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 third_party.exposed(). #2330

Merged
merged 1 commit into from
Jan 16, 2024
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
17 changes: 3 additions & 14 deletions pex/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

from pex import third_party
from pex.common import is_exe, safe_mkdtemp, safe_rmtree
from pex.compatibility import commonpath
from pex.executor import Executor
from pex.jobs import Job, Retain, SpawnedJob, execute_parallel
from pex.orderedset import OrderedSet
Expand Down Expand Up @@ -188,19 +187,9 @@ def get(cls, binary=None):
internal_entries = frozenset(
(pythonpath.split(os.pathsep) if pythonpath else []) + list(third_party.exposed())
)

def is_internal_entry(entry):
# type: (str) -> bool
if entry in internal_entries:
return True
if not os.path.isabs(entry):
return False
for internal_entry in internal_entries:
if internal_entry == commonpath((internal_entry, entry)):
return True
return False

sys_path = OrderedSet(entry for entry in sys.path if entry and not is_internal_entry(entry))
sys_path = OrderedSet(
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the simpler check that existed pre-#2328. It was always the right check; it's just that third_party.exposed() was broken at PEX runtime.

Copy link
Member Author

Choose a reason for hiding this comment

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

And all is well here. Performing this change 1st led to a failing test_boot_identification_leak test, and then fixing below got that passing again.

entry for entry in sys.path if entry and entry not in internal_entries
)

site_packages = OrderedSet(
path
Expand Down
4 changes: 1 addition & 3 deletions pex/third_party/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,11 @@ def iter_installed_vendor_importers(
):
# type: (...) -> Iterator[VendorImporter]
root = cls._abs_root(root)
vendored_paths = set(cls._vendored_path_items())
for importer in cls._iter_all_installed_vendor_importers():
# All Importables for a given VendorImporter will have the same prefix.
if importer._importables and importer._importables[0].prefix == prefix:
if importer._root == root:
if {importable.path for importable in importer._importables} == vendored_paths:
yield importer
yield importer
Copy link
Member Author

Choose a reason for hiding this comment

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

This comparison of the vendored paths at runtime (from the PEX .bootstrap/) would always fail since Pex only vendors a subset of all available vendored distributions in the runtime bootstrap of a PEX. The vendored Pip, for one, is never vendored in the runtime; it is only used at build time.

I'm not sure why I added this check in the 1st place back in #624 when I introduced vendoring / the pex.third_party import hook. Checking the root and prefix is enough to ensure the discovered VendorImporter is the one in question.


@classmethod
def install_vendored(
Expand Down