Skip to content

Commit 4a83c06

Browse files
committed
ENH: prepend the editable project directory to sys.path
Signed-off-by: Filipe Laíns <[email protected]>
1 parent c32fa12 commit 4a83c06

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

mesonpy/_editable.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ def find_spec(
4949
# if it's one of our modules, trigger a rebuild
5050
if fullname.split('.', maxsplit=1)[0] in self._top_level_modules:
5151
self.rebuild()
52+
# prepend the project path to sys.path, so that the normal finder
53+
# can find our modules
54+
# we prepend so that our path comes before the current path (if
55+
# the interpreter is run with -m), see gh-239
56+
if sys.path[0] != self._project_path:
57+
if self._project_path in sys.path:
58+
sys.path.remove(self._project_path)
59+
sys.path.insert(0, self._project_path)
5260
# return none (meaning we "didn't find" the module) and let the normal
5361
# finders find/import it
5462
return None
@@ -65,6 +73,6 @@ def install(
6573
# prepend our finder to sys.meta_path, so that it is queried before
6674
# the normal finders, and can trigger a project rebuild
6775
sys.meta_path.insert(0, finder)
68-
# add the project path to sys.path, so that the normal finder can
69-
# find our modules
70-
sys.path.append(project_path)
76+
# we add the project path to sys.path later, so that we can prepend
77+
# after the current directory is prepended (when -m is used)
78+
# see gh-239

0 commit comments

Comments
 (0)