Skip to content

Commit 5fc8b7f

Browse files
committed
Fix: Correction de la classification des dépendances (interne vs externe)
- collect_project_dependencies utilise désormais _collect_workspace_module_roots pour identifier précisément les modules locaux et éviter de les lister comme dépendances manquantes. - _check_module_installed est plus robuste grâce à un fallback sur importlib.util.find_spec (correction pour yaml/PyYAML). - Suppression de la confusion entre les dossiers projet (Loaders, Services) et les librairies tierces.
1 parent 674528f commit 5fc8b7f

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

Core/deps_analyser/analyser.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -597,16 +597,24 @@ def _classify_module_origin(module_name: str, workspace_dir: str) -> str:
597597

598598
def _check_module_installed(module: str) -> bool:
599599
"""
600-
Check whether module is installed via importlib.metadata (more reliable than subprocess pip show).
600+
Check whether module is installed.
601+
Tries importlib.metadata (package name) and then importlib.util.find_spec (module name).
601602
"""
602603
try:
603604
distribution(module)
604605
return True
605-
except PackageNotFoundError:
606-
return False
606+
except (PackageNotFoundError, Exception):
607+
pass
608+
609+
try:
610+
import importlib.util
611+
612+
if importlib.util.find_spec(module) is not None:
613+
return True
607614
except Exception:
608-
# Fallback: considérer comme non installé en cas d'erreur
609-
return False
615+
pass
616+
617+
return False
610618

611619

612620
def _find_pip_executable(venv_path: str = None, workspace_dir: str = None) -> tuple:
@@ -786,6 +794,7 @@ def collect_project_dependencies(
786794

787795
# 2. Scan imports in all Python files (fallback/validation)
788796
modules_from_imports = set()
797+
workspace_python_files = []
789798
for root, dirs, files in os.walk(workspace_dir):
790799
# Skip common non-source directories
791800
dirs[:] = [
@@ -806,15 +815,21 @@ def collect_project_dependencies(
806815
for file in files:
807816
if file.endswith(".py"):
808817
file_path = os.path.join(root, file)
818+
workspace_python_files.append(file_path)
809819
try:
810820
modules_from_imports.update(
811821
_extract_imported_modules_from_file(file_path, workspace_dir)
812822
)
813823
except Exception:
814824
pass
815825

826+
# Identify internal module roots to avoid misclassifying them as third-party
827+
internal_roots = _collect_workspace_module_roots(workspace_python_files, workspace_dir)
828+
816829
# Filter and classify modules from imports
817830
for m in modules_from_imports:
831+
if m in internal_roots:
832+
continue
818833
origin = _classify_module_origin(m, workspace_dir)
819834
if origin in ("third_party", "unknown"):
820835
all_deps.add(m)

0 commit comments

Comments
 (0)