ripple-down-rules 0.5.83__py3-none-any.whl → 0.5.85__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.
@@ -1,4 +1,4 @@
1
- __version__ = "0.5.83"
1
+ __version__ = "0.5.85"
2
2
 
3
3
  import logging
4
4
  logger = logging.Logger("rdr")
@@ -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(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(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)
@@ -881,6 +886,20 @@ def get_relative_import(target_file_path, imported_module_path: Optional[str] =
881
886
  return joined_parts
882
887
 
883
888
 
889
+ def get_path_starting_from(path: str, package_name: str) -> Optional[str]:
890
+ """
891
+ Get the path starting from the package name.
892
+
893
+ :param path: The full path to the file.
894
+ :param package_name: The name of the package to start from.
895
+ :return: The path starting from the package name or None if not found.
896
+ """
897
+ if package_name in path:
898
+ idx = path.index(package_name)
899
+ return path[idx:]
900
+ return None
901
+
902
+
884
903
  def get_imports_from_types(type_objs: Iterable[Type],
885
904
  target_file_path: Optional[str] = None,
886
905
  package_name: Optional[str] = None) -> List[str]:
@@ -923,7 +942,7 @@ def get_imports_from_types(type_objs: Iterable[Type],
923
942
  joined = ", ".join(sorted(set(names)))
924
943
  import_path = module
925
944
  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)
945
+ import_path = get_relative_import(target_file_path, module=module, package_name=package_name)
927
946
  lines.append(f"from {import_path} import {joined}")
928
947
  if other_imports:
929
948
  lines.extend(other_imports)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ripple_down_rules
3
- Version: 0.5.83
3
+ Version: 0.5.85
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=xixYpXbV9gGErJuj1TxFPGGMaaFTOvzOpHpkn65VVoU,100
1
+ ripple_down_rules/__init__.py,sha256=49RvNTpGUXv7fYtLSLpbwGCoAhuRvpyyEmnErrZRwHs,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=ikzlXjgBWM95dgL-idzeWcYyZs2IAwgA5BXMNRoKE2w,60144
8
+ ripple_down_rules/utils.py,sha256=VMOjMU2YyhUMDfBSZSjQlqi6ka-0cu014hl3OGTu3pQ,60962
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.83.dist-info/licenses/LICENSE,sha256=ixuiBLtpoK3iv89l7ylKkg9rs2GzF9ukPH7ynZYzK5s,35148
21
- ripple_down_rules-0.5.83.dist-info/METADATA,sha256=PGZ_KSayeTFDv3fTPBln3u3AzWwilfHgRdkHz5i-dv8,48214
22
- ripple_down_rules-0.5.83.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
23
- ripple_down_rules-0.5.83.dist-info/top_level.txt,sha256=VeoLhEhyK46M1OHwoPbCQLI1EifLjChqGzhQ6WEUqeM,18
24
- ripple_down_rules-0.5.83.dist-info/RECORD,,
20
+ ripple_down_rules-0.5.85.dist-info/licenses/LICENSE,sha256=ixuiBLtpoK3iv89l7ylKkg9rs2GzF9ukPH7ynZYzK5s,35148
21
+ ripple_down_rules-0.5.85.dist-info/METADATA,sha256=1tFTBGloFOMxSnYhJT6h5obVH_-UNfKQumICBkDmmwU,48214
22
+ ripple_down_rules-0.5.85.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
23
+ ripple_down_rules-0.5.85.dist-info/top_level.txt,sha256=VeoLhEhyK46M1OHwoPbCQLI1EifLjChqGzhQ6WEUqeM,18
24
+ ripple_down_rules-0.5.85.dist-info/RECORD,,