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 bdist_pex to use --project. #2457

Merged
merged 1 commit into from
Jul 8, 2024

Conversation

jsirois
Copy link
Member

@jsirois jsirois commented Jul 7, 2024

This change produces the same results for existing invocations of
python setup.py bdist_pex but allows new uses passing locked project
requirements (either hashed requirement files or Pex lock files) via
--pex-args.

Fixes #2412

This change produces the same results for existing invocations of
`python setup.py bdist_pex` but allows new uses passing locked project
requirements (either hashed requirement files or Pex lock files) via
`--pex-args`.

Fixes pex-tool#2412
Comment on lines +115 to +169
@skip_if_incompatible_with_repro_project
def test_bdist_pex_locked_issue_2412_repro_exact(
issue_2412_repro_project_dir, # type: str
pex_project_dir, # type: str
):
# type: (...) -> None

venv = Virtualenv.create(
venv_dir=os.path.join(issue_2412_repro_project_dir, ".env"),
install_pip=InstallationChoice.UPGRADED,
install_setuptools=InstallationChoice.UPGRADED,
)
subprocess.check_call(
args=[venv.bin_path("pip"), "install", "-U", "pip-tools", pex_project_dir]
)

subprocess.check_call(
args=[
venv.bin_path("pip-compile"),
"--output-file",
"requirements.txt",
"--generate-hashes",
"requirements.in",
],
cwd=issue_2412_repro_project_dir,
)
locked_requirements = list(
parse_requirement_file(os.path.join(issue_2412_repro_project_dir, "requirements.txt"))
)
assert 1 == len(locked_requirements)

locked_requirement = locked_requirements[0]
assert isinstance(locked_requirement, PyPIRequirement)
assert (
"--hash=sha256:" in locked_requirement.line.raw_text
), "Expected the compiled requirements file to include hashes."

locked_numpy_specifiers = list(locked_requirement.requirement.specifier)
assert 1 == len(locked_numpy_specifiers)
locked_numpy_specifier = locked_numpy_specifiers[0]
assert "==" == locked_numpy_specifier.operator
locked_numpy_version = locked_numpy_specifier.version

subprocess.check_call(
args=[
venv.interpreter.binary,
"setup.py",
"bdist_pex",
"--pex-args",
"--disable-cache -vvvv -r requirements.txt --pip-version 24.0",
"--bdist-all",
],
cwd=issue_2412_repro_project_dir,
)
assert_bdist_pex(issue_2412_repro_project_dir, expected_numpy_version=locked_numpy_version)
Copy link
Member Author

@jsirois jsirois Jul 7, 2024

Choose a reason for hiding this comment

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

Alright @anisse, now your exact use case works. I added alternatives below that use Pex locking instead of pip-compile. I will note that pex3 lock create --style universal --interpreter-constraint <matching your project> ... does not have the limitations described here for pip-compile: https://pip-tools.readthedocs.io/en/stable/#cross-environment-usage-of-requirements-in-requirements-txt-and-pip-compile. The Pex --style universal lock is truly universal, including all possibly needed depepdency subgraphs and resolving the right one when the lock is consumed later on a target machine to create a PEX for that machine. Or even when identifying the (foreign) target machine ahead of time with --platform or --complete-platform to build, for example, a Linux PEX on a Mac or vice-versa or even a Linux / Mac multi-platform PEX.

@jsirois jsirois merged commit 0674b79 into pex-tool:main Jul 8, 2024
26 checks passed
@jsirois jsirois deleted the issues/2412-really-fix branch July 8, 2024 12: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.

Support for pip-compile generated requirements with hashes
2 participants