zrb 0.24.1__py3-none-any.whl → 0.25.0__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.
- zrb/config/config.py +12 -2
- zrb/helper/cli.py +17 -3
- zrb/helper/loader/load_module.py +7 -46
- zrb/helper/loader/load_script.py +57 -0
- {zrb-0.24.1.dist-info → zrb-0.25.0.dist-info}/METADATA +1 -1
- {zrb-0.24.1.dist-info → zrb-0.25.0.dist-info}/RECORD +9 -8
- {zrb-0.24.1.dist-info → zrb-0.25.0.dist-info}/LICENSE +0 -0
- {zrb-0.24.1.dist-info → zrb-0.25.0.dist-info}/WHEEL +0 -0
- {zrb-0.24.1.dist-info → zrb-0.25.0.dist-info}/entry_points.txt +0 -0
zrb/config/config.py
CHANGED
@@ -33,8 +33,18 @@ def _get_default_tmp_dir() -> str:
|
|
33
33
|
TMP_DIR = os.getenv("ZRB_TMP_DIR", _get_default_tmp_dir())
|
34
34
|
DEFAULT_SHELL = os.getenv("ZRB_SHELL", _get_current_shell())
|
35
35
|
DEFAULT_EDITOR = os.getenv("ZRB_EDITOR", "nano")
|
36
|
-
|
37
|
-
|
36
|
+
INIT_MODULES_STR = os.getenv("ZRB_INIT_MODULES", "")
|
37
|
+
INIT_MODULES = (
|
38
|
+
[module.strip() for module in INIT_MODULES_STR.split(":") if module.strip() != ""]
|
39
|
+
if INIT_MODULES_STR != ""
|
40
|
+
else []
|
41
|
+
)
|
42
|
+
INIT_SCRIPTS_STR = os.getenv("ZRB_INIT_SCRIPTS", "")
|
43
|
+
INIT_SCRIPTS = (
|
44
|
+
[script.strip() for script in INIT_SCRIPTS_STR.split(":") if script.strip() != ""]
|
45
|
+
if INIT_SCRIPTS_STR != ""
|
46
|
+
else []
|
47
|
+
)
|
38
48
|
LOGGING_LEVEL = untyped_to_logging_level(os.getenv("ZRB_LOGGING_LEVEL", "WARNING"))
|
39
49
|
SHOULD_LOAD_BUILTIN = untyped_to_boolean(os.getenv("ZRB_SHOULD_LOAD_BUILTIN", "1"))
|
40
50
|
ENV_PREFIX = os.getenv("ZRB_ENV", "")
|
zrb/helper/cli.py
CHANGED
@@ -4,9 +4,10 @@ from functools import lru_cache
|
|
4
4
|
|
5
5
|
import click
|
6
6
|
|
7
|
-
from zrb.config.config import INIT_SCRIPTS, SHOULD_LOAD_BUILTIN, VERSION
|
7
|
+
from zrb.config.config import INIT_MODULES, INIT_SCRIPTS, SHOULD_LOAD_BUILTIN, VERSION
|
8
8
|
from zrb.helper.accessories.color import colored
|
9
9
|
from zrb.helper.loader.load_module import load_module
|
10
|
+
from zrb.helper.loader.load_script import load_script
|
10
11
|
from zrb.helper.log import logger
|
11
12
|
from zrb.helper.typecheck import typechecked
|
12
13
|
from zrb.runner import runner
|
@@ -45,15 +46,28 @@ def create_cli() -> click.Group:
|
|
45
46
|
from zrb import builtin
|
46
47
|
|
47
48
|
assert builtin
|
49
|
+
# load from ZRB_INIT_MODULES
|
50
|
+
for init_module in INIT_MODULES:
|
51
|
+
try:
|
52
|
+
load_module(init_module)
|
53
|
+
except Exception:
|
54
|
+
logger.error(
|
55
|
+
colored(
|
56
|
+
f"Failed to load module {init_module}",
|
57
|
+
color="red",
|
58
|
+
attrs=["bold"],
|
59
|
+
)
|
60
|
+
)
|
61
|
+
traceback.print_exc()
|
48
62
|
# Load zrb_init.py
|
49
63
|
project_dir = os.getenv("ZRB_PROJECT_DIR", os.getcwd())
|
50
64
|
project_script = os.path.join(project_dir, "zrb_init.py")
|
51
|
-
|
65
|
+
load_script(script_path=project_script, sys_path_index=0)
|
52
66
|
# load from ZRB_INIT_SCRIPTS environment
|
53
67
|
for index, init_script in enumerate(INIT_SCRIPTS):
|
54
68
|
logger.info(colored(f"Load module from {init_script}", attrs=["dark"]))
|
55
69
|
try:
|
56
|
-
|
70
|
+
load_script(script_path=init_script, sys_path_index=index + 1)
|
57
71
|
except Exception:
|
58
72
|
logger.error(
|
59
73
|
colored(
|
zrb/helper/loader/load_module.py
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
import importlib
|
2
|
-
import os
|
3
|
-
import re
|
4
|
-
import sys
|
1
|
+
import importlib
|
5
2
|
from functools import lru_cache
|
3
|
+
from typing import Any
|
6
4
|
|
7
5
|
from zrb.helper.accessories.color import colored
|
8
6
|
from zrb.helper.log import logger
|
@@ -10,48 +8,11 @@ from zrb.helper.typecheck import typechecked
|
|
10
8
|
|
11
9
|
logger.debug(colored("Loading zrb.helper.loader.load_module", attrs=["dark"]))
|
12
10
|
|
13
|
-
pattern = re.compile("[^a-zA-Z0-9]")
|
14
|
-
|
15
11
|
|
16
12
|
@lru_cache
|
17
13
|
@typechecked
|
18
|
-
def load_module(
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
_append_dir_to_python_path(script_dir_path)
|
24
|
-
_exec_script_as_module(script_path)
|
25
|
-
|
26
|
-
|
27
|
-
def _exec_script_as_module(script_path: str):
|
28
|
-
module_name = pattern.sub("", script_path)
|
29
|
-
logger.info(colored(f"Get module spec: {script_path}", attrs=["dark"]))
|
30
|
-
spec = importlib.util.spec_from_file_location(module_name, script_path)
|
31
|
-
logger.info(colored(f"Create module: {script_path}", attrs=["dark"]))
|
32
|
-
module = importlib.util.module_from_spec(spec)
|
33
|
-
logger.info(colored(f"Exec module: {script_path}", attrs=["dark"]))
|
34
|
-
spec.loader.exec_module(module)
|
35
|
-
logger.info(colored(f"Module executed: {script_path}", attrs=["dark"]))
|
36
|
-
|
37
|
-
|
38
|
-
def _append_dir_to_sys_path(dir_path: str, index: int):
|
39
|
-
if dir_path in sys.path:
|
40
|
-
return
|
41
|
-
sys.path.insert(index, dir_path)
|
42
|
-
logger.info(colored(f"Set sys.path to {sys.path}", attrs=["dark"]))
|
43
|
-
|
44
|
-
|
45
|
-
def _append_dir_to_python_path(dir_path: str):
|
46
|
-
new_python_path = _get_new_python_path(dir_path)
|
47
|
-
logger.info(colored(f"Set PYTHONPATH to {new_python_path}", attrs=["dark"]))
|
48
|
-
os.environ["PYTHONPATH"] = new_python_path
|
49
|
-
|
50
|
-
|
51
|
-
def _get_new_python_path(dir_path: str) -> str:
|
52
|
-
current_python_path = os.getenv("PYTHONPATH")
|
53
|
-
if current_python_path is None or current_python_path == "":
|
54
|
-
return dir_path
|
55
|
-
if dir_path in current_python_path.split(":"):
|
56
|
-
return current_python_path
|
57
|
-
return ":".join([current_python_path, dir_path])
|
14
|
+
def load_module(module_name: str) -> Any:
|
15
|
+
logger.info(colored(f"Importing module: {module_name}", attrs=["dark"]))
|
16
|
+
module = importlib.import_module(module_name)
|
17
|
+
logger.info(colored(f"Module imported: {module_name}", attrs=["dark"]))
|
18
|
+
return module
|
@@ -0,0 +1,57 @@
|
|
1
|
+
import importlib.util
|
2
|
+
import os
|
3
|
+
import re
|
4
|
+
import sys
|
5
|
+
from functools import lru_cache
|
6
|
+
|
7
|
+
from zrb.helper.accessories.color import colored
|
8
|
+
from zrb.helper.log import logger
|
9
|
+
from zrb.helper.typecheck import typechecked
|
10
|
+
|
11
|
+
logger.debug(colored("Loading zrb.helper.loader.load_script", attrs=["dark"]))
|
12
|
+
|
13
|
+
pattern = re.compile("[^a-zA-Z0-9]")
|
14
|
+
|
15
|
+
|
16
|
+
@lru_cache
|
17
|
+
@typechecked
|
18
|
+
def load_script(script_path: str, sys_path_index: int = 0):
|
19
|
+
if not os.path.isfile(script_path):
|
20
|
+
return
|
21
|
+
script_dir_path = os.path.dirname(script_path)
|
22
|
+
_append_dir_to_sys_path(script_dir_path, sys_path_index)
|
23
|
+
_append_dir_to_python_path(script_dir_path)
|
24
|
+
_exec_script_as_module(script_path)
|
25
|
+
|
26
|
+
|
27
|
+
def _exec_script_as_module(script_path: str):
|
28
|
+
module_name = pattern.sub("", script_path)
|
29
|
+
logger.info(colored(f"Get module spec: {script_path}", attrs=["dark"]))
|
30
|
+
spec = importlib.util.spec_from_file_location(module_name, script_path)
|
31
|
+
logger.info(colored(f"Create module: {script_path}", attrs=["dark"]))
|
32
|
+
module = importlib.util.module_from_spec(spec)
|
33
|
+
logger.info(colored(f"Exec module: {script_path}", attrs=["dark"]))
|
34
|
+
spec.loader.exec_module(module)
|
35
|
+
logger.info(colored(f"Module executed: {script_path}", attrs=["dark"]))
|
36
|
+
|
37
|
+
|
38
|
+
def _append_dir_to_sys_path(dir_path: str, index: int):
|
39
|
+
if dir_path in sys.path:
|
40
|
+
return
|
41
|
+
sys.path.insert(index, dir_path)
|
42
|
+
logger.info(colored(f"Set sys.path to {sys.path}", attrs=["dark"]))
|
43
|
+
|
44
|
+
|
45
|
+
def _append_dir_to_python_path(dir_path: str):
|
46
|
+
new_python_path = _get_new_python_path(dir_path)
|
47
|
+
logger.info(colored(f"Set PYTHONPATH to {new_python_path}", attrs=["dark"]))
|
48
|
+
os.environ["PYTHONPATH"] = new_python_path
|
49
|
+
|
50
|
+
|
51
|
+
def _get_new_python_path(dir_path: str) -> str:
|
52
|
+
current_python_path = os.getenv("PYTHONPATH")
|
53
|
+
if current_python_path is None or current_python_path == "":
|
54
|
+
return dir_path
|
55
|
+
if dir_path in current_python_path.split(":"):
|
56
|
+
return current_python_path
|
57
|
+
return ":".join([current_python_path, dir_path])
|
@@ -1312,7 +1312,7 @@ zrb/builtin/update.py,sha256=89i_fPUlL27IXczLI7Lr7k4STMpnxyw2je8daCKUTQo,225
|
|
1312
1312
|
zrb/builtin/version.py,sha256=i0pnnLQFLdTwcVqZs6xsGkbAY-IPbmelip7HuZVjgv0,384
|
1313
1313
|
zrb/builtin/watch_changes.py,sha256=Vr__e_T31nnbefcPftvyn78dT3-UXqNRpH0KO-COeKQ,1220
|
1314
1314
|
zrb/config/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
1315
|
-
zrb/config/config.py,sha256=
|
1315
|
+
zrb/config/config.py,sha256=k_3HaOljqKWr1TKZ0Ap7_E2BRqejkVNChMMA13PqEwM,1891
|
1316
1316
|
zrb/helper/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
1317
1317
|
zrb/helper/accessories/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
1318
1318
|
zrb/helper/accessories/color.py,sha256=7bj2-K_sn1leXN_C9eeOWXZBfnsBAFOzfirSiM8vCMw,964
|
@@ -1321,7 +1321,7 @@ zrb/helper/accessories/name.py,sha256=e1uvU3MzuvDb5j6YIWBA048y4qeM-LfrxRKWlMehli
|
|
1321
1321
|
zrb/helper/accessories/untyped_color.py,sha256=4wRbHSClbCzPRWtW-Cy2agOMozANVi7u4p8lMXMSuJg,194
|
1322
1322
|
zrb/helper/advertisement.py,sha256=GOaCtWYL9Oj_tAg4jqsCuFsdinHaOSH_6d57y8BbsVU,912
|
1323
1323
|
zrb/helper/callable.py,sha256=usatPKPkK_67G9dWreaGXskOaGHd_hE8MiTWAUhfojE,563
|
1324
|
-
zrb/helper/cli.py,sha256=
|
1324
|
+
zrb/helper/cli.py,sha256=S1j8hfW_zEDeycPRbJd0E8xkOZkuEZ5PNz6JO6EC8UI,2637
|
1325
1325
|
zrb/helper/codemod/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
1326
1326
|
zrb/helper/codemod/add_argument_to_function.py,sha256=Xh5Tlb4iO3cv4dRR12ms9kf0j-atVSnCh88TuqCof8I,1435
|
1327
1327
|
zrb/helper/codemod/add_argument_to_function_call.py,sha256=dFFqQ885gG_ZCBgax6sjkWx7s7cIk1amLhTC0Ge_zZo,1186
|
@@ -1346,7 +1346,8 @@ zrb/helper/file/text.py,sha256=7JqNbk8hC7Y4UopEmhiGYkxDAauepvI1tEkbfpzcI84,963
|
|
1346
1346
|
zrb/helper/git/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
1347
1347
|
zrb/helper/git/detect_changes.py,sha256=blRGkLarFh88X-G2XHP2h0bRzropT-Hqfqjbp2uRcx4,1311
|
1348
1348
|
zrb/helper/loader/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
1349
|
-
zrb/helper/loader/load_module.py,sha256=
|
1349
|
+
zrb/helper/loader/load_module.py,sha256=OfF7rtiXjNqAjIycLveXcmrWz8bZ0R9uqKeae_xYc2c,570
|
1350
|
+
zrb/helper/loader/load_script.py,sha256=LvIRB4-f3ft-wEp1amhws-L-mCKDQ1rFUzrdc16AwGE,1998
|
1350
1351
|
zrb/helper/log.py,sha256=zwUjYERey4f9VSkYca1TT1VjTzoCTsQNTFEbXrc-DS4,544
|
1351
1352
|
zrb/helper/map/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
1352
1353
|
zrb/helper/map/conversion.py,sha256=GeD7w9nv0j8f6LIxaAwXhr_5G9woX6zhEBX_vRZyWjw,620
|
@@ -1424,8 +1425,8 @@ zrb/task_input/multiline_input.py,sha256=KNto5k5X1C6KE_A-vX0OjpQyjgCRJ6BR2PwHXNQ
|
|
1424
1425
|
zrb/task_input/password_input.py,sha256=95NlJ9xIq7z_evpAyR2XsBpeuWpBXd2Ezn3P7oDOttk,4360
|
1425
1426
|
zrb/task_input/str_input.py,sha256=0nje7vI9fs_xqQBbmKB8Yn7wevlWp9Qebv7f8-GmiXs,4350
|
1426
1427
|
zrb/task_input/task_input.py,sha256=WTj_qIQyRs-04-VotjNTcVyIuf6b2afInVoCQHoRmr0,2327
|
1427
|
-
zrb-0.
|
1428
|
-
zrb-0.
|
1429
|
-
zrb-0.
|
1430
|
-
zrb-0.
|
1431
|
-
zrb-0.
|
1428
|
+
zrb-0.25.0.dist-info/LICENSE,sha256=WfnGCl8G60EYOPAEkuc8C9m9pdXWDe08NsKj3TBbxsM,728
|
1429
|
+
zrb-0.25.0.dist-info/METADATA,sha256=k6zqt8ZNoObLoO5RitMmfjDovV-v3AJIx5oyOn36tF4,17085
|
1430
|
+
zrb-0.25.0.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
1431
|
+
zrb-0.25.0.dist-info/entry_points.txt,sha256=xTgXc1kBKYhJHEujdaSPHUcJT3-hbyP1mLgwkv-5sSk,40
|
1432
|
+
zrb-0.25.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|