zrb 1.0.0b9__py3-none-any.whl → 1.1.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/builtin/project/add/fastapp/fastapp_template/my_app_name/.coveragerc +11 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/.gitignore +4 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/column/add_column_task.py +99 -55
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/column/add_column_util.py +301 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/config.py +5 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/add_entity_task.py +131 -2
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/add_entity_util.py +128 -5
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/template/app_template/module/gateway/view/content/my-module/my-entity.html +297 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/template/app_template/test/my_module/my_entity/test_create_my_entity.py +53 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/template/app_template/test/my_module/my_entity/test_delete_my_entity.py +62 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/template/app_template/test/my_module/my_entity/test_read_my_entity.py +65 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/template/app_template/test/my_module/my_entity/test_update_my_entity.py +61 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/template/gateway_subroute.py +81 -13
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/template/navigation_config_file.py +8 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/add_module_task.py +8 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/add_module_util.py +42 -3
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/gateway/subroute/my_module.py +8 -1
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/module_task_definition.py +10 -6
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/navigation_config_file.py +6 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/task.py +56 -12
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/task_util.py +10 -4
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/common/base_service.py +136 -52
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/common/util/parser.py +3 -3
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/common/util/view.py +1 -1
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/config.py +19 -8
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/migration/versions/3093c7336477_add_auth_tables.py +46 -43
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/migration/versions/8ed025bcc845_create_permissions.py +69 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/user/repository/user_db_repository.py +5 -2
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/user/user_service.py +16 -21
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/config/navigation.py +39 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/route.py +52 -11
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/schema/navigation.py +95 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/subroute/auth.py +277 -44
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/util/auth.py +66 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/util/view.py +33 -8
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/content/auth/permission.html +311 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/content/auth/role.html +0 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/content/auth/user.html +0 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/content/error.html +4 -1
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/content/login.html +67 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/content/logout.html +49 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/common/util.js +160 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/crud/style.css +14 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/crud/util.js +94 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/default/pico-style.css +23 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/default/script.js +44 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/default/style.css +102 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/template/default.html +73 -18
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/requirements.txt +6 -1
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/schema/permission.py +1 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/schema/user.py +9 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/test/_util/access_token.py +19 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/test/auth/permission/test_create_permission.py +59 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/test/auth/permission/test_delete_permission.py +68 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/test/auth/permission/test_read_permission.py +71 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/test/auth/permission/test_update_permission.py +66 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/test/auth/test_user_session.py +195 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/test/test_health_and_readiness.py +28 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/test/test_homepage.py +15 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/test/test_not_found_error.py +16 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/test.sh +7 -0
- zrb/runner/web_route/refresh_token_api_route.py +1 -1
- zrb/runner/web_route/static/refresh-token.template.js +9 -0
- zrb/runner/web_route/static/static_route.py +1 -1
- zrb/task/base_task.py +10 -10
- zrb/util/codemod/modification_mode.py +3 -0
- zrb/util/codemod/modify_class.py +58 -0
- zrb/util/codemod/modify_class_parent.py +68 -0
- zrb/util/codemod/modify_class_property.py +128 -0
- zrb/util/codemod/modify_dict.py +75 -0
- zrb/util/codemod/modify_function.py +65 -0
- zrb/util/codemod/modify_function_call.py +68 -0
- zrb/util/codemod/modify_method.py +88 -0
- zrb/util/codemod/{prepend_code_to_module.py → modify_module.py} +2 -3
- zrb/util/file.py +3 -2
- zrb/util/load.py +13 -7
- {zrb-1.0.0b9.dist-info → zrb-1.1.0.dist-info}/METADATA +2 -2
- {zrb-1.0.0b9.dist-info → zrb-1.1.0.dist-info}/RECORD +80 -46
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/migrate.py +0 -3
- zrb/util/codemod/append_code_to_class.py +0 -35
- zrb/util/codemod/append_code_to_function.py +0 -38
- zrb/util/codemod/append_code_to_method.py +0 -55
- zrb/util/codemod/append_key_to_dict.py +0 -51
- zrb/util/codemod/append_param_to_function_call.py +0 -39
- zrb/util/codemod/prepend_parent_to_class.py +0 -38
- zrb/util/codemod/prepend_property_to_class.py +0 -55
- {zrb-1.0.0b9.dist-info → zrb-1.1.0.dist-info}/WHEEL +0 -0
- {zrb-1.0.0b9.dist-info → zrb-1.1.0.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,75 @@
|
|
1
|
+
import libcst as cst
|
2
|
+
|
3
|
+
from zrb.util.codemod.modification_mode import APPEND, PREPEND
|
4
|
+
|
5
|
+
|
6
|
+
def prepend_key_to_dict(
|
7
|
+
original_code: str, dictionary_name: str, new_key: str, new_value: str
|
8
|
+
) -> str:
|
9
|
+
return _modify_dict(original_code, dictionary_name, new_key, new_value, PREPEND)
|
10
|
+
|
11
|
+
|
12
|
+
def append_key_to_dict(
|
13
|
+
original_code: str, dictionary_name: str, new_key: str, new_value: str
|
14
|
+
) -> str:
|
15
|
+
return _modify_dict(original_code, dictionary_name, new_key, new_value, APPEND)
|
16
|
+
|
17
|
+
|
18
|
+
def _modify_dict(
|
19
|
+
original_code: str, dictionary_name: str, new_key: str, new_value: str, mode: int
|
20
|
+
) -> str:
|
21
|
+
# Parse the original code into a module
|
22
|
+
module = cst.parse_module(original_code)
|
23
|
+
# Initialize the transformer with the necessary information
|
24
|
+
transformer = _DictionaryModifier(dictionary_name, new_key, new_value, mode)
|
25
|
+
# Apply the transformation
|
26
|
+
modified_module = module.visit(transformer)
|
27
|
+
# Error handling: raise an error if the dictionary is not found
|
28
|
+
if not transformer.found:
|
29
|
+
raise ValueError(
|
30
|
+
f"Dictionary {dictionary_name} not found in the provided code."
|
31
|
+
)
|
32
|
+
# Return the modified code
|
33
|
+
return modified_module.code
|
34
|
+
|
35
|
+
|
36
|
+
class _DictionaryModifier(cst.CSTTransformer):
|
37
|
+
def __init__(self, dictionary_name: str, new_key: str, new_value: str, mode: int):
|
38
|
+
self.dictionary_name = dictionary_name
|
39
|
+
self.new_key = new_key
|
40
|
+
self.new_value = new_value
|
41
|
+
self.found = False
|
42
|
+
self.mode = mode
|
43
|
+
|
44
|
+
def leave_Assign(
|
45
|
+
self, original_node: cst.Assign, updated_node: cst.Assign
|
46
|
+
) -> cst.Assign:
|
47
|
+
# Extract the first target from updated_node, which will be an AssignTarget
|
48
|
+
target = updated_node.targets[0]
|
49
|
+
# Check if the target is a Name (which should represent the dictionary)
|
50
|
+
if (
|
51
|
+
isinstance(target.target, cst.Name)
|
52
|
+
and target.target.value == self.dictionary_name
|
53
|
+
):
|
54
|
+
# Check if it's a dictionary initialization (e.g., my_dict = {...})
|
55
|
+
if isinstance(updated_node.value, cst.Dict):
|
56
|
+
self.found = True
|
57
|
+
if self.mode == PREPEND:
|
58
|
+
new_entries = (
|
59
|
+
cst.DictElement(
|
60
|
+
key=cst.SimpleString(f'"{self.new_key}"'),
|
61
|
+
value=cst.SimpleString(f'"{self.new_value}"'),
|
62
|
+
),
|
63
|
+
) + updated_node.value.elements
|
64
|
+
new_dict = updated_node.value.with_changes(elements=new_entries)
|
65
|
+
return updated_node.with_changes(value=new_dict)
|
66
|
+
if self.mode == APPEND:
|
67
|
+
new_entries = updated_node.value.elements + (
|
68
|
+
cst.DictElement(
|
69
|
+
key=cst.SimpleString(f'"{self.new_key}"'),
|
70
|
+
value=cst.SimpleString(f'"{self.new_value}"'),
|
71
|
+
),
|
72
|
+
)
|
73
|
+
new_dict = updated_node.value.with_changes(elements=new_entries)
|
74
|
+
return updated_node.with_changes(value=new_dict)
|
75
|
+
return updated_node
|
@@ -0,0 +1,65 @@
|
|
1
|
+
import libcst as cst
|
2
|
+
|
3
|
+
from zrb.util.codemod.modification_mode import APPEND, PREPEND, REPLACE
|
4
|
+
|
5
|
+
|
6
|
+
def replace_function_code(original_code: str, function_name: str, new_code: str) -> str:
|
7
|
+
return _modify_function(original_code, function_name, new_code, REPLACE)
|
8
|
+
|
9
|
+
|
10
|
+
def prepend_code_to_function(
|
11
|
+
original_code: str, function_name: str, new_code: str
|
12
|
+
) -> str:
|
13
|
+
return _modify_function(original_code, function_name, new_code, PREPEND)
|
14
|
+
|
15
|
+
|
16
|
+
def append_code_to_function(
|
17
|
+
original_code: str, function_name: str, new_code: str
|
18
|
+
) -> str:
|
19
|
+
return _modify_function(original_code, function_name, new_code, APPEND)
|
20
|
+
|
21
|
+
|
22
|
+
def _modify_function(
|
23
|
+
original_code: str, function_name: str, new_code: str, mode: int
|
24
|
+
) -> str:
|
25
|
+
# Parse the original code into a module
|
26
|
+
module = cst.parse_module(original_code)
|
27
|
+
# Initialize the transformer with the necessary information
|
28
|
+
transformer = _FunctionCodeModifier(function_name, new_code, mode)
|
29
|
+
# Apply the transformation
|
30
|
+
modified_module = module.visit(transformer)
|
31
|
+
# Error handling: raise an error if the class or function is not found
|
32
|
+
if not transformer.function_found:
|
33
|
+
raise ValueError(f"Function {function_name} not found.")
|
34
|
+
# Return the modified code
|
35
|
+
return modified_module.code
|
36
|
+
|
37
|
+
|
38
|
+
class _FunctionCodeModifier(cst.CSTTransformer):
|
39
|
+
def __init__(self, function_name: str, new_code: str, mode: int):
|
40
|
+
self.function_name = function_name
|
41
|
+
# Use parse_module to handle multiple statements
|
42
|
+
self.new_code = cst.parse_module(new_code).body
|
43
|
+
self.function_found = False
|
44
|
+
self.mode = mode
|
45
|
+
|
46
|
+
def leave_FunctionDef(
|
47
|
+
self, original_node: cst.ClassDef, updated_node: cst.ClassDef
|
48
|
+
) -> cst.ClassDef:
|
49
|
+
# Check if the class matches the target class
|
50
|
+
if original_node.name.value == self.function_name:
|
51
|
+
self.function_found = True
|
52
|
+
if self.mode == REPLACE:
|
53
|
+
new_body = updated_node.body.with_changes(body=tuple(self.new_code))
|
54
|
+
return updated_node.with_changes(body=new_body)
|
55
|
+
if self.mode == PREPEND:
|
56
|
+
new_body = updated_node.body.with_changes(
|
57
|
+
body=tuple(self.new_code) + updated_node.body.body
|
58
|
+
)
|
59
|
+
return updated_node.with_changes(body=new_body)
|
60
|
+
if self.mode == APPEND:
|
61
|
+
new_body = updated_node.body.with_changes(
|
62
|
+
body=updated_node.body.body + tuple(self.new_code)
|
63
|
+
)
|
64
|
+
return updated_node.with_changes(body=new_body)
|
65
|
+
return updated_node
|
@@ -0,0 +1,68 @@
|
|
1
|
+
import libcst as cst
|
2
|
+
|
3
|
+
from zrb.util.codemod.modification_mode import APPEND, PREPEND, REPLACE
|
4
|
+
|
5
|
+
|
6
|
+
def replace_function_call_param(
|
7
|
+
original_code: str, function_name: str, new_param: str
|
8
|
+
) -> str:
|
9
|
+
return _modify_function_call(original_code, function_name, new_param, REPLACE)
|
10
|
+
|
11
|
+
|
12
|
+
def prepend_param_to_function_call(
|
13
|
+
original_code: str, function_name: str, new_param: str
|
14
|
+
) -> str:
|
15
|
+
return _modify_function_call(original_code, function_name, new_param, PREPEND)
|
16
|
+
|
17
|
+
|
18
|
+
def append_param_to_function_call(
|
19
|
+
original_code: str, function_name: str, new_param: str
|
20
|
+
) -> str:
|
21
|
+
return _modify_function_call(original_code, function_name, new_param, APPEND)
|
22
|
+
|
23
|
+
|
24
|
+
def _modify_function_call(
|
25
|
+
original_code: str, function_name: str, new_param: str, mode: int
|
26
|
+
) -> str:
|
27
|
+
# Parse the original code into a module
|
28
|
+
module = cst.parse_module(original_code)
|
29
|
+
# Initialize the transformer with the necessary information
|
30
|
+
transformer = _FunctionCallParamModifier(function_name, new_param, mode)
|
31
|
+
# Apply the transformation
|
32
|
+
modified_module = module.visit(transformer)
|
33
|
+
# Error handling: raise an error if the function call is not found
|
34
|
+
if not transformer.param_added:
|
35
|
+
raise ValueError(
|
36
|
+
f"Function call to {function_name} not found in the provided code."
|
37
|
+
)
|
38
|
+
# Return the modified code
|
39
|
+
return modified_module.code
|
40
|
+
|
41
|
+
|
42
|
+
class _FunctionCallParamModifier(cst.CSTTransformer):
|
43
|
+
def __init__(self, func_name: str, new_param: str, mode: int):
|
44
|
+
self.func_name = func_name
|
45
|
+
# Parse the new parameter to ensure it’s a valid CST node
|
46
|
+
self.new_param = cst.parse_expression(new_param)
|
47
|
+
self.param_added = False
|
48
|
+
self.mode = mode
|
49
|
+
|
50
|
+
def leave_Call(self, original_node: cst.Call, updated_node: cst.Call) -> cst.Call:
|
51
|
+
# Check if the function call name matches the target function
|
52
|
+
if (
|
53
|
+
isinstance(original_node.func, cst.Name)
|
54
|
+
and original_node.func.value == self.func_name
|
55
|
+
):
|
56
|
+
if self.mode == REPLACE:
|
57
|
+
new_args = (cst.Arg(value=self.new_param),)
|
58
|
+
self.param_added = True
|
59
|
+
return updated_node.with_changes(args=new_args)
|
60
|
+
if self.mode == PREPEND:
|
61
|
+
new_args = (cst.Arg(value=self.new_param),) + updated_node.args
|
62
|
+
self.param_added = True
|
63
|
+
return updated_node.with_changes(args=new_args)
|
64
|
+
if self.mode == APPEND:
|
65
|
+
new_args = updated_node.args + (cst.Arg(value=self.new_param),)
|
66
|
+
self.param_added = True
|
67
|
+
return updated_node.with_changes(args=new_args)
|
68
|
+
return updated_node
|
@@ -0,0 +1,88 @@
|
|
1
|
+
import libcst as cst
|
2
|
+
|
3
|
+
from zrb.util.codemod.modification_mode import APPEND, PREPEND, REPLACE
|
4
|
+
|
5
|
+
|
6
|
+
def replace_method_code(
|
7
|
+
original_code: str, class_name: str, method_name: str, new_code: str
|
8
|
+
) -> str:
|
9
|
+
return _modify_method(original_code, class_name, method_name, new_code, REPLACE)
|
10
|
+
|
11
|
+
|
12
|
+
def prepend_code_to_method(
|
13
|
+
original_code: str, class_name: str, method_name: str, new_code: str
|
14
|
+
) -> str:
|
15
|
+
return _modify_method(original_code, class_name, method_name, new_code, PREPEND)
|
16
|
+
|
17
|
+
|
18
|
+
def append_code_to_method(
|
19
|
+
original_code: str, class_name: str, method_name: str, new_code: str
|
20
|
+
) -> str:
|
21
|
+
return _modify_method(original_code, class_name, method_name, new_code, APPEND)
|
22
|
+
|
23
|
+
|
24
|
+
def _modify_method(
|
25
|
+
original_code: str, class_name: str, method_name: str, new_code: str, mode: int
|
26
|
+
) -> str:
|
27
|
+
# Parse the original code into a module
|
28
|
+
module = cst.parse_module(original_code)
|
29
|
+
# Initialize the transformer with the necessary information
|
30
|
+
transformer = _MethodModifier(class_name, method_name, new_code, mode)
|
31
|
+
# Apply the transformation
|
32
|
+
modified_module = module.visit(transformer)
|
33
|
+
# Error handling: raise an error if the class or function is not found
|
34
|
+
if not transformer.class_found:
|
35
|
+
raise ValueError(f"Class {class_name} not found in the provided code.")
|
36
|
+
if not transformer.method_found:
|
37
|
+
raise ValueError(f"Method {method_name} not found in class {class_name}.")
|
38
|
+
# Return the modified code
|
39
|
+
return modified_module.code
|
40
|
+
|
41
|
+
|
42
|
+
class _MethodModifier(cst.CSTTransformer):
|
43
|
+
def __init__(self, class_name: str, method_name: str, new_code: str, mode: int):
|
44
|
+
self.class_name = class_name
|
45
|
+
self.method_name = method_name
|
46
|
+
# Use parse_module to handle multiple statements
|
47
|
+
self.new_code = cst.parse_module(new_code).body
|
48
|
+
self.class_found = False
|
49
|
+
self.method_found = False
|
50
|
+
self.mode = mode
|
51
|
+
|
52
|
+
def leave_ClassDef(
|
53
|
+
self, original_node: cst.ClassDef, updated_node: cst.ClassDef
|
54
|
+
) -> cst.ClassDef:
|
55
|
+
# Check if the class matches the target class
|
56
|
+
if original_node.name.value == self.class_name:
|
57
|
+
self.class_found = True
|
58
|
+
# Now, modify function definitions inside this class
|
59
|
+
new_body = []
|
60
|
+
for (
|
61
|
+
item
|
62
|
+
) in updated_node.body.body: # Access body.body, not just updated_node.body
|
63
|
+
if (
|
64
|
+
isinstance(item, cst.FunctionDef)
|
65
|
+
and item.name.value == self.method_name
|
66
|
+
):
|
67
|
+
# Modify the target function by adding the new code
|
68
|
+
if self.mode == REPLACE:
|
69
|
+
body_with_new_code = item.body.with_changes(
|
70
|
+
body=tuple(self.new_code)
|
71
|
+
)
|
72
|
+
new_body.append(item.with_changes(body=body_with_new_code))
|
73
|
+
if self.mode == PREPEND:
|
74
|
+
body_with_new_code = item.body.with_changes(
|
75
|
+
body=tuple(self.new_code) + item.body.body
|
76
|
+
)
|
77
|
+
new_body.append(item.with_changes(body=body_with_new_code))
|
78
|
+
|
79
|
+
if self.mode == APPEND:
|
80
|
+
body_with_new_code = item.body.with_changes(
|
81
|
+
body=item.body.body + tuple(self.new_code)
|
82
|
+
)
|
83
|
+
new_body.append(item.with_changes(body=body_with_new_code))
|
84
|
+
self.method_found = True
|
85
|
+
else:
|
86
|
+
new_body.append(item)
|
87
|
+
return updated_node.with_changes(body=cst.IndentedBlock(new_body))
|
88
|
+
return updated_node
|
@@ -5,8 +5,7 @@ def prepend_code_to_module(original_code: str, new_code: str) -> str:
|
|
5
5
|
stripped_line = line.strip()
|
6
6
|
if stripped_line.startswith("import") or stripped_line.startswith("from"):
|
7
7
|
last_import_index = i
|
8
|
-
|
8
|
+
else:
|
9
9
|
break
|
10
|
-
|
11
|
-
lines.insert(last_import_index + 1, new_code)
|
10
|
+
lines.insert(last_import_index + 1, new_code)
|
12
11
|
return "\n".join(lines)
|
zrb/util/file.py
CHANGED
@@ -15,10 +15,11 @@ def write_file(file_path: str, content: str | list[str]):
|
|
15
15
|
content = "\n".join([line for line in content if line is not None])
|
16
16
|
dir_path = os.path.dirname(file_path)
|
17
17
|
os.makedirs(dir_path, exist_ok=True)
|
18
|
+
should_add_eol = content.endswith("\n")
|
19
|
+
# Remove trailing newlines, but keep one if the file originally ended up with newline
|
18
20
|
content = re.sub(r"\n{3,}$", "\n\n", content)
|
19
|
-
# Remove trailing newlines, but keep one if it exists
|
20
21
|
content = content.rstrip("\n")
|
21
|
-
if
|
22
|
+
if should_add_eol:
|
22
23
|
content += "\n"
|
23
24
|
with open(file_path, "w") as f:
|
24
25
|
f.write(content)
|
zrb/util/load.py
CHANGED
@@ -12,13 +12,17 @@ pattern = re.compile("[^a-zA-Z0-9]")
|
|
12
12
|
def load_zrb_init(dir_path: str | None = None) -> Any | None:
|
13
13
|
if dir_path is None:
|
14
14
|
dir_path = os.getcwd()
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
15
|
+
# get path list from current path to the absolute root
|
16
|
+
current_path = os.path.abspath(dir_path)
|
17
|
+
path_list = [current_path]
|
18
|
+
while current_path != os.path.dirname(current_path): # Stop at root
|
19
|
+
current_path = os.path.dirname(current_path)
|
20
|
+
path_list.append(current_path)
|
21
|
+
# loop from root to current path to load zrb_init
|
22
|
+
for current_path in path_list[::-1]:
|
23
|
+
script_path = os.path.join(current_path, "zrb_init.py")
|
24
|
+
if os.path.isfile(script_path):
|
25
|
+
load_file(script_path)
|
22
26
|
|
23
27
|
|
24
28
|
@lru_cache
|
@@ -29,6 +33,8 @@ def load_file(script_path: str, sys_path_index: int = 0) -> Any | None:
|
|
29
33
|
# Append script dir path
|
30
34
|
script_dir_path = os.path.dirname(script_path)
|
31
35
|
if script_dir_path not in sys.path:
|
36
|
+
if sys_path_index == -1:
|
37
|
+
sys_path_index = len(sys.path)
|
32
38
|
sys.path.insert(sys_path_index, script_dir_path)
|
33
39
|
# Add script dir path to Python path
|
34
40
|
os.environ["PYTHONPATH"] = _get_new_python_path(script_dir_path)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: zrb
|
3
|
-
Version: 1.0
|
3
|
+
Version: 1.1.0
|
4
4
|
Summary: Your Automation Powerhouse
|
5
5
|
Home-page: https://github.com/state-alchemists/zrb
|
6
6
|
License: AGPL-3.0-or-later
|
@@ -26,7 +26,7 @@ Requires-Dist: pdfplumber (>=0.11.4,<0.12.0) ; extra == "rag"
|
|
26
26
|
Requires-Dist: psutil (>=6.1.1,<7.0.0)
|
27
27
|
Requires-Dist: pydantic-ai (>=0.0.19,<0.0.20)
|
28
28
|
Requires-Dist: python-dotenv (>=1.0.1,<2.0.0)
|
29
|
-
Requires-Dist: python-jose[cryptography] (>=3.
|
29
|
+
Requires-Dist: python-jose[cryptography] (>=3.4.0,<4.0.0)
|
30
30
|
Requires-Dist: requests (>=2.32.3,<3.0.0)
|
31
31
|
Requires-Dist: ulid-py (>=1.1.0,<2.0.0)
|
32
32
|
Project-URL: Documentation, https://github.com/state-alchemists/zrb
|