[Bugfix] Core packager to always keep __main_ at the end#360
Open
rane-rajasi wants to merge 1 commit into
Open
[Bugfix] Core packager to always keep __main_ at the end#360rane-rajasi wants to merge 1 commit into
rane-rajasi wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes core packager module-merge ordering so __main__.py remains the (near-)final entrypoint and package manager modules are not accidentally appended after it, preventing intermittent “module not found” failures caused by os.walk() traversal order.
Changes:
- Adjusts
TdnfPackageManager.pyspecial-case logic to insert before__main__.pywhen__main__.pyis already last, instead of unconditionally appending. - Updates the in-code comment to reflect the intended ordering behavior relative to
AzL3TdnfPackageManager.pyand__main__.py.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #360 +/- ##
=======================================
Coverage 94.04% 94.04%
=======================================
Files 109 109
Lines 19967 19967
=======================================
Hits 18778 18778
Misses 1189 1189
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:
|
kjohn-msft
approved these changes
Jul 7, 2026
michellemcdaniel
approved these changes
Jul 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug:
As a part of the build process, packager classes (Package-All.py and Package-Core.py), package all modules within extension and core directories into MsftLinuxPatchExt,py and MsftLinuxPatchCore.py respectively, which are then used to perform different patching operations. Since MsftLinuxPatchExt.py and MsftLinuxPatchCore.py contain multiple extension and core modules, the order in which these modules are added is important during patch process execution in python. Especially, main() should always be added at the very end, since it will start the execution flow and will only consider modules that were loaded before it. So, if a module is added after main, it will raise a Not found error.
This issue was observed in one of the recent builds where TdnfPackageManager (and some other modules) were inserted after main(), due to the code in Package-Core.py handling the special case for TdnfPackageManager. This led those modules marked as not found during execution
Below is the packager log for Core modules (Notice main.py is in between with TdnfPackageManager.py right after it):
Expected Behavior:
main.py should be last (or near-last entrypoint), and package manager modules should appear before it.
TdnfPackageManager.py should be before AzL3TdnfPackageManager.py, and both should be before main.py.
Impact
The merged file order becomes inconsistent and can violate intended initialization/dependency sequencing.
Behavior is traversal-order sensitive (depends on os.walk() encounter order), so it may appear intermittently across environments.
Root Cause:
In src/tools/packager/Package-Core.py, branch for TdnfPackageManager.py does:
Insert before AzL3TdnfPackageManager.py if already present
Else append unconditionally
If main.py is already appended, fallback append puts TdnfPackageManager.py after main.py.
The generic fallback logic for other files already handles this correctly using:
modules_to_be_merged.insert(-1, file_path) when main.py is last.
This isn't something introduced in recent commits, but the change in packager locations could have caused os.walk() to process modules in a different order triggering this
Proposed Fix:
In Package-Core.py, for the special case handling TdnfPackageManager, add a fallback, use same guard as generic path:
If last module is main.py, insert at -1; else append.
This preserves both constraints:
TdnfPackageManager.py before AzL3TdnfPackageManager.py when possible
Neither ends up after main.py.
Acceptance Criteria:
Packager output order always satisfies:
TdnfPackageManager.py appears before AzL3TdnfPackageManager.py
main.py appears after both
Behavior remains stable regardless of os.walk() traversal order.