Skip to content

Commit fb3a1f6

Browse files
committed
Better _find_editable_deps_files thanks to @cjdoris
1 parent 9a42148 commit fb3a1f6

File tree

1 file changed

+14
-27
lines changed

1 file changed

+14
-27
lines changed

src/juliapkg/deps.py

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -171,34 +171,21 @@ def can_skip_resolve():
171171
return deps
172172

173173

174-
def _find_editable_deps_files(path):
175-
# The editable .pth files appear to follow a pattern
176-
# `__editable.<pkg_name>-<pkg_version>.pth`.
177-
editable_pth_files = glob.glob(os.path.join(path, "__editable__.*.pth"))
174+
def _find_editable_deps_files():
178175
ans = []
179-
for editable_pth_file in editable_pth_files:
180-
# Extract the package name from the pth file name.
181-
bname = os.path.basename(editable_pth_file)
182-
m = re.match("__editable__\\.(.*)-", bname)
183-
if m:
184-
pkg_name = m.group(1)
185-
# Use the import finders to find the location of the editable package.
186-
for finder in sys.meta_path:
187-
try:
188-
module_spec = finder.find_spec(pkg_name)
189-
except TypeError:
176+
for finder in sys.meta_path:
177+
module_name = finder.__module__
178+
if module_name.startswith("__editable___"):
179+
m = sys.modules[module_name]
180+
paths = m.MAPPING.values()
181+
for path in paths:
182+
if not os.path.isdir(path):
190183
continue
191-
if module_spec:
192-
for search_loc in module_spec.submodule_search_locations:
193-
fn = os.path.join(search_loc, "juliapkg.json")
194-
ans.append(fn)
195-
# Thought about adding subdirectories, but that would
196-
# match possible `test` directories that might have
197-
# test-specific dependencies that wouldn't be
198-
# wanted/needed.
199-
# for subdir in os.listdir(search_loc):
200-
# fn = os.path.join(search_loc, subdir, "juliapkg.json")
201-
# ans.append(fn)
184+
fn = os.path.join(path, "juliapkg.json")
185+
ans.append(fn)
186+
for subdir in os.listdir(path):
187+
fn = os.path.join(path, subdir, "juliapkg.json")
188+
ans.append(fn)
202189

203190
return ans
204191

@@ -219,7 +206,7 @@ def deps_files():
219206
fn = os.path.join(path, subdir, "juliapkg.json")
220207
ans.append(fn)
221208

222-
ans += _find_editable_deps_files(path)
209+
ans += _find_editable_deps_files()
223210

224211
return list(
225212
set(

0 commit comments

Comments
 (0)