Skip to content

Read only the first juliapkg.json for each package on sys.path - #101

Merged
cjdoris merged 1 commit into
JuliaPy:mainfrom
MilesCranmerBot:fix/skip-shadowed-deps-files
Sep 28, 2026
Merged

cjdoris merged 1 commit into
JuliaPy:mainfrom
MilesCranmerBot:fix/skip-shadowed-deps-files

Conversation

@MilesCranmerBot

Copy link
Copy Markdown
Contributor

Summary

deps_files() collects <entry>/<package>/juliapkg.json for every entry on sys.path. When a package appears in more than one entry, all copies are merged, although Python imports only the first. This happens when running Python inside a source checkout that is also installed non-editably: the current directory comes first on sys.path, so Python imports the checkout while site-packages holds a second copy.

Identical copies merge harmlessly. Copies that set a relative path resolve it against their own directories, so they differ and find_requirements() fails with 'path' entries are not unique. Copies at different versions merge their compat bounds even though only one is imported.

This change keeps only the first juliapkg.json for each package name found along sys.path, matching import order. Top-level juliapkg.json files and editable-install discovery are unchanged.

Testing

  • uv run pytest: 127 passed, 5 skipped (126 passed on main; the difference is the new test).
  • The new test_deps_files_skips_shadowed_package puts two copies of a package on sys.path. It fails on main and passes with this change.
  • Reproduced with a package whose juliapkg.json uses a relative path, installed non-editably and imported from its checkout. find_requirements() fails on main and succeeds with this branch, selecting the checkout's path, which is the copy Python imports.

Python imports the first copy of a package on sys.path. Merging every copy made find_requirements() fail with non-unique 'path' entries when a source checkout shadowed an installed copy.

Co-authored-by: Miles Cranmer <miles.cranmer@gmail.com>
@MilesCranmer

Copy link
Copy Markdown
Contributor

@cjdoris this fixes an issue I had when trying to ship a julia package saved inside the python source, and reference it via the "path" key in juliapkg.json.

@cjdoris
cjdoris merged commit c371ba1 into JuliaPy:main Sep 28, 2026
6 checks passed
@cjdoris

cjdoris commented Sep 28, 2026

Copy link
Copy Markdown
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants