samgis_core 2.1.0__py3-none-any.whl → 3.0.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,59 @@
1
+ import json
2
+ import logging
3
+ import os
4
+ from pathlib import Path
5
+
6
+
7
+ def stats_pathname(pathname: Path | str):
8
+ current_pathname = Path(pathname)
9
+ return current_pathname.is_dir()
10
+
11
+
12
+ def create_folder_if_not_exists(pathname: Path | str):
13
+ current_pathname = Path(pathname)
14
+ try:
15
+ print(f"Pathname exists? {current_pathname.exists()}, That's a folder? {current_pathname.is_dir()}...")
16
+ logging.info(f"Pathname exists? {current_pathname.exists()}, That's a folder? {current_pathname.is_dir()}...")
17
+ current_pathname.unlink(missing_ok=True)
18
+ except PermissionError as pe:
19
+ print(f"permission denied on removing pathname before folder creation:{pe}.")
20
+ logging.error(f"permission denied on removing pathname before folder creation:{pe}.")
21
+ except IsADirectoryError as errdir:
22
+ print(f"that's a directory:{errdir}.")
23
+ logging.error(f"that's a directory:{errdir}.")
24
+
25
+ print(f"Creating pathname: {current_pathname} ...")
26
+ logging.info(f"Creating pathname: {current_pathname} ...")
27
+ current_pathname.mkdir(mode=0o770, parents=True, exist_ok=True)
28
+
29
+ print(f"assertion: pathname exists and is a folder: {current_pathname} ...")
30
+ logging.info(f"assertion: pathname exists and is a folder: {current_pathname} ...")
31
+ assert current_pathname.is_dir()
32
+
33
+
34
+ def folders_creation(folders_map: dict | str = None, ignore_errors: bool = True):
35
+ enforce_validation_with_getenv = folders_map is None
36
+ if enforce_validation_with_getenv:
37
+ folders_map = os.getenv("FOLDERS_MAP")
38
+ try:
39
+ folders_dict = folders_map if isinstance(folders_map, dict) else json.loads(folders_map)
40
+ for folder_env_ref, folder_env_path in folders_dict.items():
41
+ logging.info(f"folder_env_ref:{folder_env_ref}, folder_env_path:{folder_env_path}.")
42
+ create_folder_if_not_exists(folder_env_path)
43
+ print("========")
44
+ if enforce_validation_with_getenv:
45
+ assert os.getenv(folder_env_ref) == folder_env_path
46
+ except (json.JSONDecodeError, TypeError) as jde:
47
+ logging.error(f"jde:{jde}.")
48
+ msg = "double check your variables, e.g. for misspelling like 'FOLDER_MAP'"
49
+ msg += "instead than 'FOLDERS_MAP', or invalid json values."
50
+ logging.error(msg)
51
+ for k_env, v_env in dict(os.environ).items():
52
+ logging.info(f"{k_env}, v_env:{v_env}.")
53
+ if not ignore_errors:
54
+ raise TypeError(jde)
55
+
56
+
57
+ if __name__ == '__main__':
58
+ folders_creation()
59
+
@@ -6,6 +6,9 @@ from PIL.Image import Image
6
6
  from numpy import ndarray
7
7
 
8
8
 
9
+ class ListStr(list[str]): pass
10
+
11
+
9
12
  class DictStrInt(dict[str, int]): pass
10
13
 
11
14
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: samgis_core
3
- Version: 2.1.0
3
+ Version: 3.0.2
4
4
  Summary: SamGIS CORE
5
5
  License: MIT
6
6
  Author: alessandro trinca tornidor
@@ -12,10 +12,8 @@ Classifier: Programming Language :: Python :: 3.10
12
12
  Classifier: Programming Language :: Python :: 3.11
13
13
  Requires-Dist: bson (>=0.5.10,<0.6.0)
14
14
  Requires-Dist: loguru (>=0.7.2,<0.8.0)
15
- Requires-Dist: mpld3 (>=0.5.10,<0.6.0)
16
15
  Requires-Dist: numpy (==1.25.2) ; python_version >= "3.10" and python_version < "3.11"
17
16
  Requires-Dist: numpy (>=1.26,<2.0) ; python_version >= "3.11" and python_version < "3.12"
18
- Requires-Dist: onnxruntime (>=1.18.1,<2.0.0)
19
17
  Requires-Dist: pillow (>=10.4.0,<11.0.0)
20
18
  Requires-Dist: python-dotenv (>=1.0.1,<2.0.0)
21
19
  Requires-Dist: structlog (>=24.4.0,<25.0.0)
@@ -5,13 +5,13 @@ samgis_core/prediction_api/sam_onnx2.py,sha256=-nt6xfeLuUCB9GtJD74o53Ks3zPVgBWZb
5
5
  samgis_core/prediction_api/sam_onnx_inference.py,sha256=EQjJy1RLZn0-m66bdY_T1bR-t6PnNu47JJVphEkgPhE,5539
6
6
  samgis_core/utilities/__init__.py,sha256=nL9pzdB4SdEF8m5gCbtlVCtdGLg9JjPm-FNxKBsIBZA,32
7
7
  samgis_core/utilities/constants.py,sha256=0xBdfGYwCg4O0OXFtTcMVNj-kryjbajcxOZhMVkVP7U,227
8
- samgis_core/utilities/fastapi_logger.py,sha256=yt8Vj1viyE-Kry1_iy5p4saZvGEEmRfuTEMHYXgnjqk,650
8
+ samgis_core/utilities/create_folders_if_not_exists.py,sha256=yCxuCUTAB9FG_6CBhN5vHScs7MLU_Myn6-tHbI_OpuI,2510
9
9
  samgis_core/utilities/plot_images.py,sha256=nY_1KW7x_h218MA9leulEKLkoNhLlyEscLSWs0Az2uE,263
10
10
  samgis_core/utilities/serialize.py,sha256=aIjhEoibBpV_gpgOg6LiVxZCWjOkYxlzcboDZLQctJE,2689
11
11
  samgis_core/utilities/session_logger.py,sha256=P_H6LcMmNoD-cuwl9mMLl73KYz1kfLQhYiKY37NujcI,5095
12
- samgis_core/utilities/type_hints.py,sha256=hAMYXpHgMhYguOPbegCQbVCIexWNSn6S-2Q_nilfesQ,1068
12
+ samgis_core/utilities/type_hints.py,sha256=YhTSsD7ICVZtLRoq-P6O5AP9BEGg5hSHJaboS1qbpuw,1101
13
13
  samgis_core/utilities/utilities.py,sha256=tRGp-Iw0PoPf5YHDL6Hx2CEdZhqs03hh3YPe_rmoO-E,3286
14
- samgis_core-2.1.0.dist-info/LICENSE,sha256=cmg7mi2IynvK5xYN_TJBikA008n6IJNjQIig1c3ge9Q,1083
15
- samgis_core-2.1.0.dist-info/METADATA,sha256=hpR4ZgmZ0TPbB4nMYG8Jjx2M5lyfd33qNccqoZSvitk,1232
16
- samgis_core-2.1.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
17
- samgis_core-2.1.0.dist-info/RECORD,,
14
+ samgis_core-3.0.2.dist-info/LICENSE,sha256=cmg7mi2IynvK5xYN_TJBikA008n6IJNjQIig1c3ge9Q,1083
15
+ samgis_core-3.0.2.dist-info/METADATA,sha256=9JspSIKk1yLQy_YEcPxwdpYhL7fAh7PmZOLKuZxUt9Q,1148
16
+ samgis_core-3.0.2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
17
+ samgis_core-3.0.2.dist-info/RECORD,,
@@ -1,26 +0,0 @@
1
- import loguru
2
-
3
-
4
- format_string = "{time} - {level} - {file} - {function} - ({extra[request_id]}) {message} "
5
-
6
-
7
- def setup_logging(debug: bool = False, formatter: str = format_string) -> loguru.logger:
8
- """
9
- Create a logging instance with log string formatter.
10
-
11
- Args:
12
- debug: logging debug argument
13
- formatter: log string formatter
14
-
15
- Returns:
16
- Logger
17
-
18
- """
19
- import sys
20
-
21
- logger = loguru.logger
22
- logger.remove()
23
- level_logger = "DEBUG" if debug else "INFO"
24
- logger.add(sys.stdout, format=formatter, level=level_logger)
25
- logger.info(f"type_logger:{type(logger)}, logger:{logger}.")
26
- return logger