Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bare imports in AssetFinder subdirectories #924

Merged
merged 2 commits into from
Aug 19, 2023

Conversation

dbnicholson
Copy link
Contributor

When creating a non-root AssetFinder, copy the parent's extract_packages so that importing bare modules works correctly. This is typically needed when packages are vendored and sys.path is dynamically updated to prefer the vendored version.

Fixes: #820

When creating a non-root AssetFinder, copy the parent's `extract_packages` so
that importing bare modules works correctly. This is typically needed when
packages are vendored and `sys.path` is dynamically updated to prefer the
vendored version.

Fixes: chaquo#820
@dbnicholson
Copy link
Contributor Author

This seems to be all that's needed. If the added test is run without copying the parent's extract_packages, it fails in the same way as described in #820. I also tested this in my application and it worked correctly. I don't know if there are any side effects from the change, though.

@mhsmith
Copy link
Member

mhsmith commented Aug 2, 2023

Thanks, I'll have a look at this and your other PR in a few days.

Copy link
Member

@mhsmith mhsmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks very much for this, and sorry for taking so long to review it. The implementation change looks fine, but there was a problem with the test – it didn't reproduce the original problem, because murmurhash.about is a module, not a package. So I've changed it to use murmurhash.tests.

# This is typically done when vendoring packages and dynamically adjusting sys.path. See #820.
def test_imp_subdir(self):
sys.modules.pop("about", None)
def test_path_subdir(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"imp" in the other tests refers to the imp module, which this isn't related to.

@mhsmith mhsmith merged commit bac5548 into chaquo:master Aug 19, 2023
@dbnicholson dbnicholson deleted the import-subdir branch September 10, 2023 20:11
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.

Adding AssetFinder subdirectories to sys.path causes extract_packages error
2 participants