samgis_core 3.0.8__py3-none-any.whl → 3.0.10__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.
@@ -123,7 +123,7 @@ def build_frontend(
123
123
  app_logger.info(f"current_folder:{current_folder}, install pnpm...")
124
124
  run_command(["which", "npm"])
125
125
  run_command(["npm", "install", "-g", "npm", "pnpm"])
126
- app_logger.info(f"install pnpm dependencies...")
126
+ app_logger.info("install pnpm dependencies...")
127
127
  run_command(["pnpm", "install"])
128
128
 
129
129
  # build frontend dist and assert for its correct build
@@ -139,7 +139,7 @@ def build_frontend(
139
139
  run_command(["pnpm", "tailwindcss", "-i", str(input_css_path), "-o", output_css])
140
140
  app_logger.info(f"pnpm: ls -l {output_css}:")
141
141
  run_command(["ls", "-l", output_css])
142
- app_logger.info(f"end!")
142
+ app_logger.info("end!")
143
143
  return True
144
144
 
145
145
 
@@ -0,0 +1,85 @@
1
+ import argparse
2
+ import sys
3
+ from pathlib import Path
4
+ import structlog
5
+
6
+ from samgis_core.utilities import session_logger
7
+
8
+ session_logger.setup_logging(json_logs=False, log_level="INFO")
9
+ logger = structlog.stdlib.get_logger(__name__)
10
+
11
+
12
+ def get_dependencies_freeze() -> dict:
13
+ """get a 'freeze.txt'-like dict of 'name':'version' metadata about installed packages."""
14
+ from importlib import metadata
15
+ return {dist.metadata["name"]: dist.version for dist in metadata.distributions()}
16
+
17
+
18
+ def sanitize_path(filename: str | Path) -> Path:
19
+ filename = Path(filename)
20
+ base_path = Path.cwd().resolve(strict=True)
21
+ logger.info(f"base_path (current working folder):{base_path} ...")
22
+ safe_path = filename.resolve(strict=True)
23
+ try:
24
+ assert base_path / filename.name == safe_path
25
+ except AssertionError:
26
+ msg = f"""
27
+ Basename of resolved path {safe_path} doesn't matches original file {filename},
28
+ or filename {filename} isn't within the current directory {base_path} ...
29
+ """
30
+ raise OSError(msg)
31
+ return Path(safe_path)
32
+
33
+
34
+ def get_requirements_txt(requirements_no_versions_filename: str | Path, requirements_output_filename: str | Path):
35
+ """
36
+ Write on disk a requirements.txt file with an updated list of dependencies from installed python packages.
37
+ Both input and output requirements files must be within the folder from which the current command is executed.
38
+
39
+ Args:
40
+ requirements_no_versions_filename: input requirements filename with no specified versions
41
+ requirements_output_filename: output requirements.txt filename
42
+
43
+ Returns:
44
+
45
+ """
46
+ logger.info("start requirements.txt update...")
47
+ freeze_dict = get_dependencies_freeze()
48
+ logger.debug(f"freeze_dict:{freeze_dict}.")
49
+ requirements_no_versions_filename = sanitize_path(requirements_no_versions_filename)
50
+ with open(requirements_no_versions_filename) as req_src:
51
+ packages_no_requirements = req_src.read().split("\n")
52
+ requirements_output = {
53
+ name: version for name, version in sorted(freeze_dict.items()) if name in packages_no_requirements
54
+ }
55
+ logger.info(f"requirements to write:{requirements_output}.")
56
+ requirements_output_filename = sanitize_path(requirements_output_filename)
57
+ with open(requirements_output_filename, "w") as dst:
58
+ out = ""
59
+ for name, version in requirements_output.items():
60
+ out += f"{name}=={version}\n"
61
+ logger.info(f"output requirements content:\n{out}!")
62
+ dst.write(out)
63
+ logger.info(f"written requirements to file:{requirements_output_filename}!")
64
+
65
+
66
+ def get_args(current_args: list) -> argparse.Namespace:
67
+ warning = "This file must be within the current folder."
68
+ parser = argparse.ArgumentParser(description="Update requirements.txt from current installed packages.")
69
+ parser.add_argument(
70
+ "--req_no_version_path", required=True,
71
+ help=f"file path for requirements list packages without versions. {warning}."
72
+ )
73
+ parser.add_argument(
74
+ "--req_output_path", required=True,
75
+ help=f"file path for output requirements. {warning}."
76
+ )
77
+ return parser.parse_args(current_args)
78
+
79
+
80
+ if __name__ == '__main__':
81
+ args = get_args(sys.argv[1:])
82
+ get_requirements_txt(
83
+ requirements_no_versions_filename=args.req_no_version_path,
84
+ requirements_output_filename=args.req_output_path
85
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: samgis_core
3
- Version: 3.0.8
3
+ Version: 3.0.10
4
4
  Summary: SamGIS CORE
5
5
  License: MIT
6
6
  Author: alessandro trinca tornidor
@@ -6,13 +6,14 @@ samgis_core/prediction_api/sam_onnx_inference.py,sha256=WFRc8TNMOix4g0IAteNbDAs0
6
6
  samgis_core/utilities/__init__.py,sha256=nL9pzdB4SdEF8m5gCbtlVCtdGLg9JjPm-FNxKBsIBZA,32
7
7
  samgis_core/utilities/constants.py,sha256=0xBdfGYwCg4O0OXFtTcMVNj-kryjbajcxOZhMVkVP7U,227
8
8
  samgis_core/utilities/create_folders_if_not_exists.py,sha256=Ee_4l83suZvY5r24D26SNKGJVH3KAHregsiWs-0W-gQ,3202
9
- samgis_core/utilities/frontend_builder.py,sha256=3aQ95XXpMNQoDKuhn1pJLJ25R1PM0gx03VMrakuopXs,5438
9
+ samgis_core/utilities/frontend_builder.py,sha256=KuQ-yrjG_Hti289tFT4k9QbiUEWYb269AAClEu5bbDU,5436
10
10
  samgis_core/utilities/plot_images.py,sha256=1pwTJC2_ju-QhJXDonvEw6FMK_9i1kQhLnC4tjn2EH0,3469
11
11
  samgis_core/utilities/serialize.py,sha256=aIjhEoibBpV_gpgOg6LiVxZCWjOkYxlzcboDZLQctJE,2689
12
12
  samgis_core/utilities/session_logger.py,sha256=mlzLaeSC2b_MF3wLywyXYQsSPIvEd3OnhlD7_4VhMzo,5704
13
13
  samgis_core/utilities/type_hints.py,sha256=anbm8pHFWr_C1upCmncYOK-q9Iq82fO9_yftTqXeizc,1649
14
+ samgis_core/utilities/update_requirements_txt.py,sha256=yIqwFhRIPsxtFvv64C8EbOo76qYnXKYNNTP4VLUc47Q,3418
14
15
  samgis_core/utilities/utilities.py,sha256=Yi-nBdgz75BOfPbBPs3pFE6ag6KyZ-wK_FAgHkGtNQs,4298
15
- samgis_core-3.0.8.dist-info/LICENSE,sha256=cmg7mi2IynvK5xYN_TJBikA008n6IJNjQIig1c3ge9Q,1083
16
- samgis_core-3.0.8.dist-info/METADATA,sha256=_8iQ8fxwVJv6aVbhcjB92ik0R8eiuxLO5NN4vID0pC4,1109
17
- samgis_core-3.0.8.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
18
- samgis_core-3.0.8.dist-info/RECORD,,
16
+ samgis_core-3.0.10.dist-info/LICENSE,sha256=cmg7mi2IynvK5xYN_TJBikA008n6IJNjQIig1c3ge9Q,1083
17
+ samgis_core-3.0.10.dist-info/METADATA,sha256=hS5NltC6HZsoV4FApVlAYRUWxWj7s97rPuGMRwGVFjM,1110
18
+ samgis_core-3.0.10.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
19
+ samgis_core-3.0.10.dist-info/RECORD,,