Skip to content

Commit

Permalink
Fixup real issue here.
Browse files Browse the repository at this point in the history
  • Loading branch information
jsirois committed Mar 28, 2024
1 parent 824a4b0 commit ac17ade
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 37 deletions.
25 changes: 3 additions & 22 deletions pex/bin/pex.py
Expand Up @@ -892,28 +892,9 @@ def build_pex(
"Adding distributions from pexes: {}".format(" ".join(options.requirements_pexes))
):
for requirements_pex in options.requirements_pexes:
if (
pex_info.deps_are_wheel_files
!= PexInfo.from_pex(requirements_pex).deps_are_wheel_files
):
die(
"The {option} option was selected but the --requirements-pex "
"{requirements_pex} is built with {opposite_option}. Any --requirements-pex "
"you want to merge into the main PEX must be built with {option}.".format(
option=(
"--no-pre-install-wheels"
if pex_info.deps_are_wheel_files
else "--pre-install-wheels"
),
requirements_pex=requirements_pex,
opposite_option=(
"--pre-install-wheels"
if pex_info.deps_are_wheel_files
else "--no-pre-install-wheels"
),
)
)
requirements_pex_info = dependency_manager.add_from_pex(requirements_pex)
requirements_pex_info = dependency_manager.add_from_pex(
requirements_pex, result_type_wheel_file=pex_info.deps_are_wheel_files
)
excluded.extend(requirements_pex_info.excluded)

with TRACER.timed(
Expand Down
12 changes: 9 additions & 3 deletions pex/dependency_manager.py
Expand Up @@ -31,14 +31,20 @@ class DependencyManager(object):
_requirements = attr.ib(factory=OrderedSet) # type: OrderedSet[Requirement]
_distributions = attr.ib(factory=OrderedSet) # type: OrderedSet[FingerprintedDistribution]

def add_from_pex(self, pex):
# type: (str) -> PexInfo
def add_from_pex(
self,
pex, # type: str
result_type_wheel_file=False, # type: bool
):
# type: (...) -> PexInfo

pex_info = PexInfo.from_pex(pex)
self._requirements.update(Requirement.parse(req) for req in pex_info.requirements)

pex_environment = PEXEnvironment.mount(pex, pex_info=pex_info)
self._distributions.update(pex_environment.iter_distributions())
self._distributions.update(
pex_environment.iter_distributions(result_type_wheel_file=result_type_wheel_file)
)

return pex_info

Expand Down
18 changes: 6 additions & 12 deletions tests/integration/test_issue_2391.py
Expand Up @@ -85,22 +85,16 @@ def assert_pex():
).assert_success()
assert_pex()

# N.B.: We cannot currently re-materialize wheel files from pre-installed wheel chroots.
# See: https://github.com/pex-tool/pex/issues/2299
run_pex_command(
args=["--no-pre-install-wheels", "--requirements-pex", pre_installed_reqs_pex], quiet=True
).assert_failure(
expected_error_re=re.escape(
"The --no-pre-install-wheels option was selected but the --requirements-pex {reqs_pex} "
"is built with --pre-install-wheels. Any --requirements-pex you want to merge into the "
"main PEX must be built with --no-pre-install-wheels.".format(
reqs_pex=pre_installed_reqs_pex
)
"Cannot resolve .whl files from PEX at {reqs_pex}; its dependencies are in the form of "
"pre-installed wheel chroots.".format(reqs_pex=pre_installed_reqs_pex)
)
)

run_pex_command(args=["--requirements-pex", wheel_file_reqs_pex], quiet=True).assert_failure(
expected_error_re=re.escape(
"The --pre-install-wheels option was selected but the --requirements-pex {reqs_pex} is "
"built with --no-pre-install-wheels. Any --requirements-pex you want to merge into the "
"main PEX must be built with --pre-install-wheels.".format(reqs_pex=wheel_file_reqs_pex)
)
)
# But we can go the other way around and turn wheel files into pre-installed wheel chroots.
run_pex_command(args=["--requirements-pex", wheel_file_reqs_pex], quiet=True).assert_success()

0 comments on commit ac17ade

Please sign in to comment.