ripple-down-rules 0.5.84__py3-none-any.whl → 0.5.86__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.
- ripple_down_rules/__init__.py +1 -1
- ripple_down_rules/utils.py +26 -4
- {ripple_down_rules-0.5.84.dist-info → ripple_down_rules-0.5.86.dist-info}/METADATA +1 -1
- {ripple_down_rules-0.5.84.dist-info → ripple_down_rules-0.5.86.dist-info}/RECORD +7 -7
- {ripple_down_rules-0.5.84.dist-info → ripple_down_rules-0.5.86.dist-info}/WHEEL +0 -0
- {ripple_down_rules-0.5.84.dist-info → ripple_down_rules-0.5.86.dist-info}/licenses/LICENSE +0 -0
- {ripple_down_rules-0.5.84.dist-info → ripple_down_rules-0.5.86.dist-info}/top_level.txt +0 -0
ripple_down_rules/__init__.py
CHANGED
ripple_down_rules/utils.py
CHANGED
@@ -850,22 +850,27 @@ def get_function_representation(func: Callable) -> str:
|
|
850
850
|
|
851
851
|
|
852
852
|
def get_relative_import(target_file_path, imported_module_path: Optional[str] = None,
|
853
|
-
module: Optional[str] = None) -> str:
|
853
|
+
module: Optional[str] = None, package_name: Optional[str] = None) -> str:
|
854
854
|
"""
|
855
855
|
Get a relative import path from the target file to the imported module.
|
856
856
|
|
857
857
|
:param target_file_path: The file path of the target file.
|
858
858
|
:param imported_module_path: The file path of the module being imported.
|
859
859
|
:param module: The module name, if available.
|
860
|
+
:param package_name: The name of the root package where the module is located.
|
860
861
|
:return: A relative import path as a string.
|
861
862
|
"""
|
862
863
|
# Convert to absolute paths
|
864
|
+
target_path = Path(target_file_path).resolve()
|
865
|
+
if package_name is not None:
|
866
|
+
target_path = Path(get_path_starting_from_latest_encounter_of(str(target_path), package_name))
|
863
867
|
if module is not None:
|
864
868
|
imported_module_path = sys.modules[module].__file__
|
865
869
|
if imported_module_path is None:
|
866
870
|
raise ValueError("Either imported_module_path or module must be provided")
|
867
|
-
target_path = Path(target_file_path).resolve()
|
868
871
|
imported_path = Path(imported_module_path).resolve()
|
872
|
+
if package_name is not None:
|
873
|
+
imported_path = Path(get_path_starting_from_latest_encounter_of(str(imported_path), package_name))
|
869
874
|
|
870
875
|
# Compute relative path from target to imported module
|
871
876
|
rel_path = os.path.relpath(imported_path.parent, target_path.parent)
|
@@ -873,14 +878,31 @@ def get_relative_import(target_file_path, imported_module_path: Optional[str] =
|
|
873
878
|
# Convert path to Python import format
|
874
879
|
rel_parts = [part.replace('..', '.') for part in Path(rel_path).parts]
|
875
880
|
rel_parts = rel_parts if rel_parts else ['']
|
881
|
+
dot_parts = [part for part in rel_parts if part == '.']
|
882
|
+
non_dot_parts = [part for part in rel_parts if part != '.']
|
883
|
+
|
876
884
|
|
877
885
|
# Join the parts and add the module name
|
878
|
-
joined_parts = "".join(
|
886
|
+
joined_parts = "".join(dot_parts) + ".".join(non_dot_parts) + f".{imported_path.stem}"
|
879
887
|
joined_parts = f".{joined_parts}" if not joined_parts.startswith(".") else joined_parts
|
880
888
|
|
881
889
|
return joined_parts
|
882
890
|
|
883
891
|
|
892
|
+
def get_path_starting_from_latest_encounter_of(path: str, package_name: str) -> Optional[str]:
|
893
|
+
"""
|
894
|
+
Get the path starting from the package name.
|
895
|
+
|
896
|
+
:param path: The full path to the file.
|
897
|
+
:param package_name: The name of the package to start from.
|
898
|
+
:return: The path starting from the package name or None if not found.
|
899
|
+
"""
|
900
|
+
if package_name in path:
|
901
|
+
idx = path.rfind(package_name)
|
902
|
+
return path[idx:]
|
903
|
+
return None
|
904
|
+
|
905
|
+
|
884
906
|
def get_imports_from_types(type_objs: Iterable[Type],
|
885
907
|
target_file_path: Optional[str] = None,
|
886
908
|
package_name: Optional[str] = None) -> List[str]:
|
@@ -923,7 +945,7 @@ def get_imports_from_types(type_objs: Iterable[Type],
|
|
923
945
|
joined = ", ".join(sorted(set(names)))
|
924
946
|
import_path = module
|
925
947
|
if (target_file_path is not None) and (package_name is not None) and (package_name in module):
|
926
|
-
import_path = get_relative_import(target_file_path, module=module)
|
948
|
+
import_path = get_relative_import(target_file_path, module=module, package_name=package_name)
|
927
949
|
lines.append(f"from {import_path} import {joined}")
|
928
950
|
if other_imports:
|
929
951
|
lines.extend(other_imports)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: ripple_down_rules
|
3
|
-
Version: 0.5.
|
3
|
+
Version: 0.5.86
|
4
4
|
Summary: Implements the various versions of Ripple Down Rules (RDR) for knowledge representation and reasoning.
|
5
5
|
Author-email: Abdelrhman Bassiouny <abassiou@uni-bremen.de>
|
6
6
|
License: GNU GENERAL PUBLIC LICENSE
|
@@ -1,11 +1,11 @@
|
|
1
|
-
ripple_down_rules/__init__.py,sha256=
|
1
|
+
ripple_down_rules/__init__.py,sha256=yHGpD2EOFIRVmTQHKqc3fRmy_stAXTnnT3m1K9MGr6o,100
|
2
2
|
ripple_down_rules/experts.py,sha256=bwozulI1rv0uyaMZQqEgapDO-s8wvW0D6Jqxmvu5fik,12610
|
3
3
|
ripple_down_rules/helpers.py,sha256=v4oE7C5PfQUVJfSUs1FfLHEwrJXEHJLn4vJhJMvyCR8,4453
|
4
4
|
ripple_down_rules/rdr.py,sha256=C6bvlq6MsKa2Mym1wW6JUMj705aCaoihTP279TM6eT0,55218
|
5
5
|
ripple_down_rules/rdr_decorators.py,sha256=amXUjgc-rfYxPKFW16Xm8Z9vfaaslNl5OvDOg9fKaTg,9447
|
6
6
|
ripple_down_rules/rules.py,sha256=iVevv6iZ-6L2IPI0ZYbBjxBymXEQMmJGRFhiKUS-NmA,20352
|
7
7
|
ripple_down_rules/start-code-server.sh,sha256=otClk7VmDgBOX2TS_cjws6K0UwvgAUJhoA0ugkPCLqQ,949
|
8
|
-
ripple_down_rules/utils.py,sha256=
|
8
|
+
ripple_down_rules/utils.py,sha256=ZDyrStxnIBcjlgrwOQt-6fPkZXy_WMZwn3na5JCFqEw,61173
|
9
9
|
ripple_down_rules/datastructures/__init__.py,sha256=V2aNgf5C96Y5-IGghra3n9uiefpoIm_QdT7cc_C8cxQ,111
|
10
10
|
ripple_down_rules/datastructures/callable_expression.py,sha256=f3wUPTrLa1INO-1qfgVz87ryrCABronfyq0_JKWoZCs,12800
|
11
11
|
ripple_down_rules/datastructures/case.py,sha256=1zSaXUljaH6z3SgMGzYPoDyjotNam791KpYgvxuMh90,15463
|
@@ -17,8 +17,8 @@ ripple_down_rules/user_interface/ipython_custom_shell.py,sha256=Jrf7NxOdlrwGXH0X
|
|
17
17
|
ripple_down_rules/user_interface/object_diagram.py,sha256=FEa2HaYR9QmTE6NsOwBvZ0jqmu3DKyg6mig2VE5ZP4Y,4956
|
18
18
|
ripple_down_rules/user_interface/prompt.py,sha256=AkkltdDIaioN43lkRKDPKSjJcmdSSGZDMYz7AL7X9lE,8082
|
19
19
|
ripple_down_rules/user_interface/template_file_creator.py,sha256=xWUt-RHRqrvoMo74o-bMLo8xNxil68wgbOZAMADZp2A,13570
|
20
|
-
ripple_down_rules-0.5.
|
21
|
-
ripple_down_rules-0.5.
|
22
|
-
ripple_down_rules-0.5.
|
23
|
-
ripple_down_rules-0.5.
|
24
|
-
ripple_down_rules-0.5.
|
20
|
+
ripple_down_rules-0.5.86.dist-info/licenses/LICENSE,sha256=ixuiBLtpoK3iv89l7ylKkg9rs2GzF9ukPH7ynZYzK5s,35148
|
21
|
+
ripple_down_rules-0.5.86.dist-info/METADATA,sha256=zQp8XNkCxkNEZu9rxpj4KpSYF2wtqua9cVR2d73gEbM,48214
|
22
|
+
ripple_down_rules-0.5.86.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
23
|
+
ripple_down_rules-0.5.86.dist-info/top_level.txt,sha256=VeoLhEhyK46M1OHwoPbCQLI1EifLjChqGzhQ6WEUqeM,18
|
24
|
+
ripple_down_rules-0.5.86.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|