Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
2e4086e
Implement build constraints
notatallshaw Aug 9, 2025
1aa1d32
Add build constraints tests
notatallshaw Aug 9, 2025
db4fcf7
Add build constraints to user guide
notatallshaw Aug 9, 2025
d9d5f5d
NEWS ENTRY
notatallshaw Aug 9, 2025
8d170b5
Imply using new behavior when build constraints are provided without …
notatallshaw Aug 9, 2025
9f9032c
Update src/pip/_internal/cli/req_command.py
notatallshaw Aug 14, 2025
a9e81d7
Update src/pip/_internal/build_env.py
notatallshaw Aug 14, 2025
4fbafeb
Merge branch 'main' into add-build-constraints
notatallshaw Aug 14, 2025
8943172
Fix linting
notatallshaw Aug 19, 2025
ef06010
Fix test
notatallshaw Aug 19, 2025
d564457
Consistently use "build constraints" in variables and documentation
notatallshaw Aug 19, 2025
ebd55e7
Simplify deprecation warning
notatallshaw Aug 19, 2025
c41496e
Only emit pip constraint deprecation warning once
notatallshaw Aug 19, 2025
e015f3d
Move `ExtraEnviron` into type checking block
notatallshaw Aug 19, 2025
b333b85
Use standard `assert_installed` in functional tests for build constra…
notatallshaw Aug 20, 2025
bc48f0b
Eagerly assert build constraints files
notatallshaw Aug 20, 2025
fc1bfb5
Add deprecation news item.
notatallshaw Aug 20, 2025
74b08e1
Remove pointless check for `_PIP_IN_BUILD_IGNORE_CONSTRAINTS` in `_de…
notatallshaw Aug 20, 2025
41164aa
Exit `_deprecation_constraint_check` early when build constraints pre…
notatallshaw Aug 20, 2025
e53db93
Remove superfluous `constraints` parameter
notatallshaw Aug 21, 2025
f372c74
Merge branch 'main' into add-build-constraints
notatallshaw Aug 29, 2025
d86d520
Merge branch 'main' into add-build-constraints
notatallshaw Sep 8, 2025
05aeb84
Merge branch 'main' into add-build-constraints
notatallshaw Sep 19, 2025
4c04652
Merge branch 'main' into add-build-constraints
notatallshaw Sep 25, 2025
ab36b15
Merge branch 'main' into add-build-constraints
notatallshaw Oct 5, 2025
d8f372c
Use with to close pip session.
notatallshaw Oct 11, 2025
d0cf197
Remove deprication supression logic
notatallshaw Oct 11, 2025
b091be2
Update tests
notatallshaw Oct 11, 2025
aa5fcd9
Merge branch 'main' into add-build-constraints
notatallshaw Oct 11, 2025
d0bcf5c
fix lint
notatallshaw Oct 11, 2025
11676b0
Merge branch 'main' into add-build-constraints
notatallshaw Oct 14, 2025
035396d
Merge branch 'main' into add-build-constraints
notatallshaw Oct 17, 2025
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
Prev Previous commit
Next Next commit
Update tests
  • Loading branch information
notatallshaw committed Oct 11, 2025
commit b091be20142f3e7a0369c1b955b522905ba78c3e
37 changes: 36 additions & 1 deletion tests/functional/test_build_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

from __future__ import annotations

import os
from pathlib import Path
from unittest import mock

import pytest

from pip._internal.utils.urls import path_to_url

from tests.lib import PipTestEnvironment, TestPipResult, create_test_package_with_setup


Expand Down Expand Up @@ -43,6 +47,7 @@ def _run_pip_install_with_build_constraints(
str(build_constraints_file),
"--use-feature",
"build-constraint",
"--use-pep517",
]

if extra_args:
Expand All @@ -63,10 +68,12 @@ def _run_pip_install_with_build_constraints_no_feature_flag(
"install",
"--build-constraint",
str(constraints_file),
"--use-pep517",
str(project_dir),
)


@pytest.mark.network
def test_build_constraints_basic_functionality_simple(
script: PipTestEnvironment, tmpdir: Path
) -> None:
Expand Down Expand Up @@ -112,6 +119,7 @@ def test_build_constraints_vs_regular_constraints_simple(
regular_constraints_file,
"--use-feature",
"build-constraint",
"--use-pep517",
str(project_dir),
expect_error=False,
)
Expand All @@ -137,6 +145,7 @@ def test_build_constraints_environment_isolation_simple(
result.assert_installed("test-env-isolation", editable=False, without_files=["."])


@pytest.mark.network
def test_build_constraints_file_not_found(
script: PipTestEnvironment, tmpdir: Path
) -> None:
Expand All @@ -155,17 +164,43 @@ def test_build_constraints_file_not_found(
assert "No such file or directory" in result.stderr


@pytest.mark.network
def test_build_constraints_without_feature_flag(
script: PipTestEnvironment, tmpdir: Path
) -> None:
"""Test that --build-constraint automatically enables the feature."""
project_dir = _create_simple_test_package(script=script, name="test_no_feature")
constraints_file = _create_constraints_file(
script=script, filename="constraints.txt", content="setuptools==45.0.0\n"
script=script, filename="constraints.txt", content="setuptools>=40.0.0\n"
)
result = _run_pip_install_with_build_constraints_no_feature_flag(
script=script, project_dir=project_dir, constraints_file=constraints_file
)
# Should succeed now that --build-constraint auto-enables the feature
assert result.returncode == 0
result.assert_installed("test-no-feature", editable=False, without_files=["."])


@pytest.mark.network
def test_constraints_dont_pass_through(
script: PipTestEnvironment, tmpdir: Path
) -> None:
"""When build constraints enabled, check PIP_CONSTRAINT won't affect builds."""
project_dir = create_test_package_with_setup(
script,
name="test_isolation",
version="1.0",
py_modules=["test_isolation"],
)
constraints = _create_constraints_file(
script=script, filename="constraints.txt", content="setuptools==2000\n"
)
with mock.patch.dict(os.environ, {"PIP_CONSTRAINT": path_to_url(str(constraints))}):
result = script.pip(
"install",
"--no-cache-dir",
str(project_dir),
"--use-pep517",
"--use-feature=build-constraint",
)
result.assert_installed("test_isolation", editable=False, without_files=["."])
23 changes: 0 additions & 23 deletions tests/unit/test_build_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@
class TestSubprocessBuildEnvironmentInstaller:
"""Test SubprocessBuildEnvironmentInstaller build constraints functionality."""

def setup_method(self) -> None:
"""Reset the global deprecation warning flag before each test."""
import pip._internal.build_env

pip._internal.build_env._DEPRECATION_WARNING_SHOWN = False

@mock.patch.dict(os.environ, {}, clear=True)
def test_deprecation_check_no_pip_constraint(self) -> None:
"""Test no deprecation warning when PIP_CONSTRAINT is not set."""
Expand Down Expand Up @@ -119,20 +113,3 @@ def test_install_calls_deprecation_check(

# Verify that call_subprocess was called (install proceeded after warning)
mock_call_subprocess.assert_called_once()

@mock.patch.dict(os.environ, {"PIP_CONSTRAINT": "constraints.txt"})
def test_deprecation_check_warning_shown_only_once(self) -> None:
"""Test deprecation warning is shown only once per process."""
finder = make_test_finder()
installer = SubprocessBuildEnvironmentInstaller(
finder,
build_constraint_feature_enabled=False,
)

with pytest.warns(PipDeprecationWarning):
installer._deprecation_constraint_check()

with warnings.catch_warnings(record=True) as warning_list:
warnings.simplefilter("always")
installer._deprecation_constraint_check()
assert len(warning_list) == 0
Loading