Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## Unreleased
* Read only the first `juliapkg.json` for each package found on `sys.path`, matching import.

## v0.1.27 (2026-09-19)
* Add `bindir()` function.

Expand Down
7 changes: 5 additions & 2 deletions src/juliapkg/deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,8 @@ def deps_files():
ans = []
# the default deps file
ans.append(cur_deps_file())
# look in sys.path
# look in sys.path, keeping only the first copy of each package, as import does
seen = set()
for path in sys.path:
if not path:
path = os.getcwd()
Expand All @@ -310,7 +311,9 @@ def deps_files():
ans.append(fn)
for subdir in os.listdir(path):
fn = os.path.join(path, subdir, "juliapkg.json")
ans.append(fn)
if subdir not in seen and os.path.isfile(fn):
seen.add(subdir)
ans.append(fn)

ans += editable_deps_files()

Expand Down
22 changes: 22 additions & 0 deletions test/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,25 @@ def test_editable_setuptools():
)
assert os.path.exists(fn)
assert any(os.path.samefile(fn, x) for x in juliapkg.deps.deps_files())


def test_deps_files_skips_shadowed_package(monkeypatch):
# a package found twice on sys.path contributes only the copy import uses
with (
tempfile.TemporaryDirectory() as first,
tempfile.TemporaryDirectory() as second,
):
for root in (first, second):
os.mkdir(os.path.join(root, "shadowedpkg"))
with open(os.path.join(root, "shadowedpkg", "juliapkg.json"), "w") as fp:
json.dump({"packages": {}}, fp)
monkeypatch.setattr("sys.path", [first, second])
files = juliapkg.deps.deps_files()
assert any(
os.path.samefile(os.path.join(first, "shadowedpkg", "juliapkg.json"), x)
for x in files
)
assert not any(
os.path.samefile(os.path.join(second, "shadowedpkg", "juliapkg.json"), x)
for x in files
)
Loading