Skip to content

Commit ab73c0a

Browse files
feature/load_inheritance_config_package (Pipelex#97)
1 parent d11cfb2 commit ab73c0a

1 file changed

Lines changed: 13 additions & 20 deletions

File tree

pipelex/tools/config/manager.py

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import importlib
12
import os
23
from configparser import ConfigParser
34
from typing import Any, Dict, Optional
@@ -71,32 +72,24 @@ def load_inheritance_config(self, the_pipelex_config: Dict[str, Any]):
7172
print(f"pyproject.toml not found in {self.local_root_dir}")
7273
return
7374

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+
7486
pyproject = toml.load(pyproject_path)
7587
if "tool" in pyproject and "pipelex" in pyproject["tool"] and "config_inheritance" in pyproject["tool"]["pipelex"]:
7688
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)
9590
if package_path:
9691
config_path = os.path.join(package_path, "pipelex.toml")
97-
print(f"Loading config inheritance for {config_name} from {config_path}")
9892
if os.path.exists(config_path):
99-
print(f"Found config inheritance for {config_name} from {config_path}")
10093
config = failable_load_toml_from_path(config_path)
10194
if config:
10295
deep_update(the_pipelex_config, config)

0 commit comments

Comments
 (0)