samgis_core 3.0.6__tar.gz → 3.0.8__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: 3.0.6
3
+ Version: 3.0.8
4
4
  Summary: SamGIS CORE
5
5
  License: MIT
6
6
  Author: alessandro trinca tornidor
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "samgis_core"
3
- version = "3.0.6"
3
+ version = "3.0.8"
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 = "3.0.6"
11
+ version = "3.0.8"
12
12
 
13
13
  [tool.poetry.urls]
14
14
  Source = "https://gitlab.com/aletrn/samgis_core"
@@ -37,6 +37,7 @@ optional = true
37
37
  mpld3 = "^0.5.10"
38
38
  pytest = "^8.2.2"
39
39
  pytest-cov = "^5.0.0"
40
+ rasterio = "^1.3.10"
40
41
 
41
42
  [build-system]
42
43
  requires = ["poetry-core"]
@@ -0,0 +1,150 @@
1
+ import os
2
+ import subprocess
3
+ from pathlib import Path
4
+
5
+ from dotenv import load_dotenv
6
+
7
+ from samgis_core import app_logger
8
+ from samgis_core.utilities.type_hints import ListStr
9
+
10
+
11
+ load_dotenv()
12
+ root_folder = Path(globals().get("__file__", "./_")).absolute().parent.parent.parent
13
+ env_project_root_folder = os.getenv("PROJECT_ROOT_FOLDER", str(root_folder))
14
+ env_input_css_path = os.getenv("INPUT_CSS_PATH")
15
+
16
+
17
+ def assert_envs(envs_list: ListStr) -> None:
18
+ """
19
+ Assert env variables are not empty.
20
+
21
+ Args:
22
+ envs_list: list of env variables
23
+
24
+ Returns:
25
+
26
+ """
27
+ for current_env in envs_list:
28
+ try:
29
+ assert current_env is not None and current_env != ""
30
+ except AssertionError as aex:
31
+ app_logger.error(f"error on assertion for current_env: {current_env}.")
32
+ raise aex
33
+
34
+
35
+ def read_std_out_err(std_out_err: str, output_type: str, command: ListStr) -> None:
36
+ """
37
+ Capture the standard output or standard error content for a given system command pipe.
38
+
39
+ Args:
40
+ std_out_err: str
41
+ output_type: output type (stdout or stderr)
42
+ command: command executed
43
+
44
+ Returns:
45
+
46
+ """
47
+ output = std_out_err.split("\n")
48
+ app_logger.info(f"output type:{output_type} for command:{' '.join(command)}.")
49
+ for line in iter(output):
50
+ app_logger.info(f"output_content_home stdout:{line.strip()}.")
51
+ app_logger.info("########")
52
+
53
+
54
+ def run_command(commands_list: ListStr, capture_output: bool = True, text: bool = True, check: bool = True) -> None:
55
+ """
56
+ Run a system command and capture its output.
57
+ See https://docs.python.org/3.11/library/subprocess.html#subprocess.run for more details
58
+
59
+ Args:
60
+ commands_list: list of single string commands
61
+ capture_output: if true, stdout and stderr will be captured
62
+ text: if true, capture stdout and stderr as strings
63
+ check: If check is true, and the process exits with a non-zero exit code, a CalledProcessError exception will
64
+ be raised. Attributes of that exception hold the arguments, the exit code, and stdout and stderr if they
65
+ were captured.
66
+
67
+ Returns:
68
+
69
+ """
70
+ try:
71
+ output_content_home = subprocess.run(
72
+ commands_list,
73
+ capture_output=capture_output,
74
+ text=text,
75
+ check=check
76
+ )
77
+ read_std_out_err(output_content_home.stdout, "stdout", commands_list)
78
+ read_std_out_err(output_content_home.stderr, "stderr", commands_list)
79
+ except Exception as ex:
80
+ app_logger.error(f"ex:{ex}.")
81
+ raise ex
82
+
83
+
84
+ def build_frontend(
85
+ project_root_folder: str | Path,
86
+ input_css_path: str | Path,
87
+ output_dist_folder: Path = root_folder / "static" / "dist",
88
+ index_page_filename: str = "index.html",
89
+ output_css_filename: str = "output.css",
90
+ force_build: bool = False,
91
+ ) -> bool:
92
+ """
93
+ Build a static [Vue js](https://vuejs.org/), [tailwindcss](https://tailwindcss.com/) frontend.
94
+ If force_build is False, the function also check if index_page_filename and output_css_filename already exists:
95
+ in this case skip the build.
96
+
97
+ Args:
98
+ project_root_folder: Project folder that contains the static frontend
99
+ input_css_path: file path pointing to the input css file
100
+ output_dist_folder: dist folder path where to write the frontend bundle
101
+ index_page_filename: index html filename
102
+ output_css_filename: output css filename
103
+ force_build: useful to skip the frontend build
104
+
105
+ Returns:
106
+ state of the build (True in case of build completed, False in case of build skipped)
107
+
108
+ """
109
+ assert_envs([
110
+ str(project_root_folder),
111
+ str(input_css_path)
112
+ ])
113
+ project_root_folder = Path(project_root_folder)
114
+ index_html_pathfile = Path(output_dist_folder) / index_page_filename
115
+ output_css_pathfile = Path(output_dist_folder) / output_css_filename
116
+ if not force_build and output_css_pathfile.is_file() and index_html_pathfile.is_file():
117
+ app_logger.info("frontend ok, build_frontend not necessary...")
118
+ return False
119
+
120
+ # install deps
121
+ os.chdir(project_root_folder / "static")
122
+ current_folder = os.getcwd()
123
+ app_logger.info(f"current_folder:{current_folder}, install pnpm...")
124
+ run_command(["which", "npm"])
125
+ run_command(["npm", "install", "-g", "npm", "pnpm"])
126
+ app_logger.info(f"install pnpm dependencies...")
127
+ run_command(["pnpm", "install"])
128
+
129
+ # build frontend dist and assert for its correct build
130
+ output_css = str(output_dist_folder / output_css_filename)
131
+ output_index_html = str(output_dist_folder / index_page_filename)
132
+ output_dist_folder = str(output_dist_folder)
133
+ app_logger.info(f"pnpm: build '{output_dist_folder}'...")
134
+ run_command(["pnpm", "build"])
135
+ app_logger.info(f"pnpm: ls -l {output_index_html}:")
136
+ run_command(["ls", "-l", output_index_html])
137
+ cmd = ["pnpm", "tailwindcss", "-i", str(input_css_path), "-o", output_css]
138
+ app_logger.info(f"pnpm: {' '.join(cmd)}...")
139
+ run_command(["pnpm", "tailwindcss", "-i", str(input_css_path), "-o", output_css])
140
+ app_logger.info(f"pnpm: ls -l {output_css}:")
141
+ run_command(["ls", "-l", output_css])
142
+ app_logger.info(f"end!")
143
+ return True
144
+
145
+
146
+ if __name__ == '__main__':
147
+ build_frontend(
148
+ project_root_folder=Path(env_project_root_folder),
149
+ input_css_path=Path(env_input_css_path)
150
+ )
@@ -140,6 +140,18 @@ def apply_coords(coords: ndarray, embedding: EmbeddingPILImage):
140
140
 
141
141
 
142
142
  def normalize_array(arr: ndarray, new_h: int | float = 255., type_normalization: str = "int") -> ndarray:
143
+ """
144
+ Normalize numpy array between 0 and 'new_h' value. Default dtype of output array is int
145
+
146
+
147
+ Args:
148
+ arr: input numpy array
149
+ new_h: max value of output array
150
+ type_normalization: default dtype of output array
151
+
152
+ Returns:
153
+ numpy array
154
+ """
143
155
  arr = arr.astype(float)
144
156
  arr_max = np.nanmax(arr)
145
157
  arr_min = np.nanmin(arr)
File without changes
File without changes