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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions product/runtime/src/main/python/java/android/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ def __init__(self, context, build_json, path):
self.extract_root = parent.extract_root
self.prefix = relpath(path, self.extract_root)
self.zip_files = parent.zip_files
self.extract_packages = parent.extract_packages

def __repr__(self):
return f"{type(self).__name__}({self.path!r})"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,19 @@ def check_top_level(real_name, load_name, id):
# important enough to investigate just now.
self.assertFalse(hasattr(imp_rename_2, "mod_3"))

# Ensure that a package can be imported by a bare name when it's in an AssetFinder subdirectory.
# This is typically done when vendoring packages and dynamically adjusting sys.path. See #820.
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.

sys.modules.pop("tests", None)
murmur_path = asset_path(REQS_COMMON_ZIP, "murmurhash")
tests_path = join(murmur_path, "tests/__init__.py")
sys.path.insert(0, murmur_path)
try:
import tests
finally:
sys.path.remove(murmur_path)
self.assertEqual(tests_path, tests.__file__)

# Make sure the standard library importer implements the new loader API
# (https://stackoverflow.com/questions/63574951).
def test_zipimport(self):
Expand Down