Fix external plugin module name collisions - #9953
Merged
tastelikefeet merged 1 commit intoAug 24, 2026
Merged
Conversation
tastelikefeet
approved these changes
Aug 24, 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.
PR type
PR information
External plugins are currently imported by their filename stem. When two configured plugins have the same filename in different directories, Python reuses the first entry from
sys.modules, so the second plugin is never executed.Load external plugins under a stable module key derived from their absolute path. This keeps same-path imports cached while isolating same-name files from different directories, and removes a partially initialized module if execution fails.
The regression test creates two
plugin.pyfiles in separate directories and verifies that both modules execute with their own values.Experiment results
python -m unittest tests.utils.test_file_utils.TestFileUtils.test_import_external_files_with_same_name(passed)python -m unittest tests.utils.test_file_utils(2 tests passed)pre-commit run --files swift/utils/utils.py tests/utils/test_file_utils.py(passed)git diff --check(passed)