Fix FedJob subdirectory sibling imports - #4959
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adjusts how FedJobConfig copies external scripts and their dependencies so that unqualified imports in entry-point scripts located in subdirectories can correctly resolve to sibling modules (and adds unit coverage for this behavior).
Changes:
- Pass an
is_external_scriptflag when copying registered external scripts so unqualified imports can be resolved against the script’s directory even when the derived module name contains dots (e.g.,src.client). - Add a new unit test covering unqualified sibling imports for scripts in subdirectories and refine an existing test to better reflect package-import behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
tests/unit_test/job_config/fed_job_config_test.py |
Adds/updates unit tests for external script import-resolution and copy behavior. |
nvflare/job_config/fed_job_config.py |
Extends _copy_source_file to optionally treat a file as an external entry-point when resolving unqualified imports. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Greptile SummaryThis PR fixes a regression introduced in #4885 where scripts registered from subdirectories (e.g.
Confidence Score: 5/5Safe to merge — the fix is minimal, well-targeted, and the three-test suite covers the regression case, the package-collision boundary, and end-to-end simulator export. The Files Needing Attention: No files require special attention. Important Files Changed
Reviews (10): Last reviewed commit: "Merge branch 'main' into codex/fix-fedjo..." | Re-trigger Greptile |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4959 +/- ##
=======================================
Coverage 64.26% 64.26%
=======================================
Files 1030 1030
Lines 103578 103580 +2
=======================================
+ Hits 66560 66570 +10
+ Misses 37018 37010 -8
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Fix FedJob export of sibling modules for subdirectory scripts.
Description
Fixes a regression from #4885 where a registered script such as
src/client.pycould no longer export a sibling imported asfrom net import Net.Registered external scripts now search their source directory for unqualified imports, while recursively discovered package modules retain the existing collision protection.
Testing
src/client.pyimportingsrc/net.py./runtest.sh -spassedTypes of changes
./runtest.sh.