|
| 1 | +import importlib |
1 | 2 | import os |
2 | 3 | from configparser import ConfigParser |
3 | 4 | from typing import Any, Dict, Optional |
@@ -71,32 +72,24 @@ def load_inheritance_config(self, the_pipelex_config: Dict[str, Any]): |
71 | 72 | print(f"pyproject.toml not found in {self.local_root_dir}") |
72 | 73 | return |
73 | 74 |
|
| 75 | + def _find_package_path(package_name: str) -> Optional[str]: |
| 76 | + """Find package path by importing it""" |
| 77 | + try: |
| 78 | + module = importlib.import_module(package_name) |
| 79 | + if hasattr(module, "__file__") and module.__file__: |
| 80 | + return os.path.dirname(module.__file__) |
| 81 | + except ImportError: |
| 82 | + pass |
| 83 | + |
| 84 | + return None |
| 85 | + |
74 | 86 | pyproject = toml.load(pyproject_path) |
75 | 87 | if "tool" in pyproject and "pipelex" in pyproject["tool"] and "config_inheritance" in pyproject["tool"]["pipelex"]: |
76 | 88 | for config_name in pyproject["tool"]["pipelex"]["config_inheritance"]: |
77 | | - print(f"Loading config inheritance for {config_name}") |
78 | | - # First check if it's a local dependency in poetry |
79 | | - package_path: Optional[str] = None |
80 | | - if "tool" in pyproject and "poetry" in pyproject["tool"] and "dependencies" in pyproject["tool"]["poetry"]: |
81 | | - dep_config: Dict[str, Any] = pyproject["tool"]["poetry"]["dependencies"].get(config_name, {}) |
82 | | - if "path" in dep_config: |
83 | | - # It's a local path |
84 | | - local_path: str = str(dep_config["path"]) |
85 | | - package_path = os.path.abspath(os.path.join(self.local_root_dir, local_path)) |
86 | | - |
87 | | - if not package_path: |
88 | | - # Try to find in .venv |
89 | | - venv_path = os.path.join(self.local_root_dir, ".venv") |
90 | | - if os.path.exists(venv_path): |
91 | | - site_packages = os.path.join(venv_path, "lib", "python3.11", "site-packages", config_name) |
92 | | - if os.path.exists(site_packages): |
93 | | - package_path = site_packages |
94 | | - |
| 89 | + package_path = _find_package_path(config_name) |
95 | 90 | if package_path: |
96 | 91 | config_path = os.path.join(package_path, "pipelex.toml") |
97 | | - print(f"Loading config inheritance for {config_name} from {config_path}") |
98 | 92 | if os.path.exists(config_path): |
99 | | - print(f"Found config inheritance for {config_name} from {config_path}") |
100 | 93 | config = failable_load_toml_from_path(config_path) |
101 | 94 | if config: |
102 | 95 | deep_update(the_pipelex_config, config) |
|
0 commit comments