Files
clan-llm/sitecustomize.py
collinarnett ff1400f0e4 sitecustomize: use Path instead of os.path
Replace os.path operations with pathlib.Path to comply with ruff rules
PTH118, PTH109, PTH110. Also fix import formatting in test files.
2026-01-17 14:01:05 -05:00

38 lines
1.3 KiB
Python

"""Development environment customization for clan-llm.
This module is automatically imported by Python when PYTHONPATH includes
the directory containing it. It modifies module paths to inject local
editable versions from pkgs/clan-llm.
"""
from importlib import import_module
from pathlib import Path
def _inject_local_submodule(parent_module: str, submodule: str) -> None:
"""Add local directory from pkgs/clan-llm to a parent module's __path__.
This allows the specified submodule to be loaded from the local directory
while keeping the rest of the parent module from the Nix store.
Args:
parent_module: Parent module name (e.g. 'clan_lib', 'clan_cli')
submodule: Submodule to override (e.g. 'llm', 'ai')
"""
try:
module = import_module(parent_module)
local_path = Path.cwd() / "pkgs/clan-llm" / parent_module
submodule_path = local_path / submodule
# Only inject if the specific submodule exists locally
if submodule_path.exists() and str(local_path) not in module.__path__:
module.__path__.insert(0, str(local_path))
except ImportError:
# Module not installed, skip customization
pass
_inject_local_submodule("clan_lib", "llm")
_inject_local_submodule("clan_cli", "ai")