samgis_core 2.1.0__tar.gz → 3.0.2__tar.gz

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.
@@ -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)
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "samgis_core"
3
- version = "2.1.0"
3
+ version = "3.0.2"
4
4
  description = "SamGIS CORE"
5
5
  authors = ["alessandro trinca tornidor <alessandro@trinca.tornidor.com>"]
6
6
  license = "MIT license"
@@ -8,7 +8,7 @@ readme = "README.md"
8
8
 
9
9
  [metadata]
10
10
  name = "samgis_core"
11
- version = "2.1.0"
11
+ version = "3.0.2"
12
12
 
13
13
  [tool.poetry.urls]
14
14
  Source = "https://gitlab.com/aletrn/samgis_core"
@@ -23,14 +23,18 @@ numpy = [
23
23
  pillow = "^10.4.0"
24
24
  python = ">=3.10, <3.12"
25
25
  python-dotenv = "^1.0.1"
26
- onnxruntime = "^1.18.1"
27
26
  structlog = "^24.4.0"
27
+ [tool.poetry.group.onnxruntime]
28
+ optional = true
29
+
30
+ [tool.poetry.group.onnxruntime.dependencies]
31
+ onnxruntime = "^1.18.1"
28
32
 
29
- mpld3 = "^0.5.10"
30
33
  [tool.poetry.group.test]
31
34
  optional = true
32
35
 
33
36
  [tool.poetry.group.test.dependencies]
37
+ mpld3 = "^0.5.10"
34
38
  pytest = "^8.2.2"
35
39
  pytest-cov = "^5.0.0"
36
40
 
@@ -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,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
File without changes
File without changes