[FIX] commit msg : chercher lib_identifiant sans masquer GitPython
Le répertoire ajouté est `script/`, qui porte un `git/` : en tête de `sys.path`, il fait résoudre `import git` vers ce paquet plutôt que vers GitPython, pour tout module importé ENSUITE dans le même processus — une bibliothèque tierce disparaît parce qu'une des nôtres porte le même nom. En queue, `lib_identifiant` se trouve toujours et les paquets installés gardent la priorité ; la racine du dépôt suit la même règle, elle porte un `test/` homonyme d'un paquet standard. Mesuré : `unittest discover -p 'test_git*.py'` passe de 49 tests et une erreur d'import à 84 verts ; le hook commit-msg reste vérifié. --- EN --- The directory being added is `script/`, which holds a `git/`: at the head of `sys.path` it makes `import git` resolve to that package rather than to GitPython, for every module imported AFTERWARDS in the same process — a third-party library vanishes because one of ours bears the same name. At the tail, `lib_identifiant` is still found and installed packages keep their precedence; the repository root follows the same rule, it holds a `test/` sharing its name with a standard library package. Measured: `unittest discover -p 'test_git*.py'` goes from 49 tests and one import error to 84 green; the commit-msg hook stays verified. Assisted-by: Claude Opus 5
This commit is contained in:
parent
eb5d6a72a0
commit
a60baf743e
1 changed files with 10 additions and 2 deletions
|
|
@ -21,7 +21,13 @@ import re
|
|||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
||||
# APPEND et non insert(0) : ce répertoire est `script/`, qui contient
|
||||
# `git/`. En tête de `sys.path`, il fait résoudre `import git` vers
|
||||
# `script/git/` au lieu de GitPython, pour tout module importé ensuite —
|
||||
# une bibliothèque tierce disparaît alors parce qu'une des nôtres porte le
|
||||
# même nom. En queue, `lib_identifiant` se trouve toujours, et les paquets
|
||||
# installés gardent la priorité qui leur revient.
|
||||
sys.path.append(str(Path(__file__).resolve().parents[1]))
|
||||
|
||||
from lib_identifiant import ( # noqa: E402
|
||||
NOMS_INTERDITS,
|
||||
|
|
@ -29,7 +35,9 @@ from lib_identifiant import ( # noqa: E402
|
|||
termes_interdits,
|
||||
)
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[2]))
|
||||
# Même raison : la racine du dépôt porte un `test/`, qui masquerait le
|
||||
# paquet `test` de la bibliothèque standard.
|
||||
sys.path.append(str(Path(__file__).resolve().parents[2]))
|
||||
|
||||
try:
|
||||
from script.todo.todo_i18n import t
|
||||
|
|
|
|||
Loading…
Reference in a new issue