samgis_core 3.0.8__py3-none-any.whl → 3.0.9__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.
- samgis_core/utilities/update_requirements_txt.py +43 -0
- {samgis_core-3.0.8.dist-info → samgis_core-3.0.9.dist-info}/METADATA +1 -1
- {samgis_core-3.0.8.dist-info → samgis_core-3.0.9.dist-info}/RECORD +5 -4
- {samgis_core-3.0.8.dist-info → samgis_core-3.0.9.dist-info}/LICENSE +0 -0
- {samgis_core-3.0.8.dist-info → samgis_core-3.0.9.dist-info}/WHEEL +0 -0
@@ -0,0 +1,43 @@
|
|
1
|
+
from pathlib import Path
|
2
|
+
import structlog
|
3
|
+
|
4
|
+
from samgis_core.utilities import session_logger
|
5
|
+
|
6
|
+
|
7
|
+
session_logger.setup_logging(json_logs=False, log_level="INFO")
|
8
|
+
logger = structlog.stdlib.get_logger(__name__)
|
9
|
+
|
10
|
+
|
11
|
+
def get_dependencies_freeze() -> dict:
|
12
|
+
"""get a 'freeze.txt'-like dict of 'name':'version' metadata about installed packages."""
|
13
|
+
from importlib import metadata
|
14
|
+
return {dist.metadata["name"]: dist.version for dist in metadata.distributions()}
|
15
|
+
|
16
|
+
|
17
|
+
def get_requirements_txt(requirements_no_versions_filename: str | Path, requirements_output_filename: str | Path):
|
18
|
+
"""
|
19
|
+
Write on disk a requirements.txt file with an updated list of dependencies from installed python packages.
|
20
|
+
|
21
|
+
Args:
|
22
|
+
requirements_no_versions_filename: full path of input requirements filename with no specified versions
|
23
|
+
requirements_output_filename: full path of output requirements.txt filename
|
24
|
+
|
25
|
+
Returns:
|
26
|
+
|
27
|
+
"""
|
28
|
+
logger.info("start requirements.txt update...")
|
29
|
+
freeze_dict = get_dependencies_freeze()
|
30
|
+
logger.debug(f"freeze_dict:{freeze_dict}.")
|
31
|
+
with open(requirements_no_versions_filename) as req_src:
|
32
|
+
packages_no_requirements = req_src.read().split("\n")
|
33
|
+
requirements_output = {
|
34
|
+
name: version for name, version in sorted(freeze_dict.items()) if name in packages_no_requirements
|
35
|
+
}
|
36
|
+
logger.info(f"requirements to write:{requirements_output}.")
|
37
|
+
with open(requirements_output_filename, "w") as dst:
|
38
|
+
out = ""
|
39
|
+
for name, version in requirements_output.items():
|
40
|
+
out += f"{name}=={version}\n"
|
41
|
+
logger.debug(f"output requirements content:\n{out}!")
|
42
|
+
dst.write(out)
|
43
|
+
logger.info(f"written requirements to file:{requirements_output_filename}!")
|
@@ -11,8 +11,9 @@ samgis_core/utilities/plot_images.py,sha256=1pwTJC2_ju-QhJXDonvEw6FMK_9i1kQhLnC4
|
|
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=1tPnSSLVBxU3TB4Wpa2oJE8VYsqb0qspe6c2XdFHRBY,1751
|
14
15
|
samgis_core/utilities/utilities.py,sha256=Yi-nBdgz75BOfPbBPs3pFE6ag6KyZ-wK_FAgHkGtNQs,4298
|
15
|
-
samgis_core-3.0.
|
16
|
-
samgis_core-3.0.
|
17
|
-
samgis_core-3.0.
|
18
|
-
samgis_core-3.0.
|
16
|
+
samgis_core-3.0.9.dist-info/LICENSE,sha256=cmg7mi2IynvK5xYN_TJBikA008n6IJNjQIig1c3ge9Q,1083
|
17
|
+
samgis_core-3.0.9.dist-info/METADATA,sha256=YKV0W3lCTtE2Z3VYIcyHE7tBCMii348OLxzSTzm-v_A,1109
|
18
|
+
samgis_core-3.0.9.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
19
|
+
samgis_core-3.0.9.dist-info/RECORD,,
|
File without changes
|
File without changes
|