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
Only emit pip constraint deprecation warning once
  • Loading branch information
notatallshaw committed Aug 19, 2025
commit c41496e5bdd69e9a245ba906605c82fd162a0a67
15 changes: 14 additions & 1 deletion src/pip/_internal/build_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@

logger = logging.getLogger(__name__)

# Global flag to track if deprecation warning has been shown
_DEPRECATION_WARNING_SHOWN = False


class ExtraEnviron(TypedDict, total=False):
extra_environ: dict[str, str]
Expand Down Expand Up @@ -123,15 +126,25 @@ def _deprecation_constraint_check(self) -> None:
Check for deprecation warning: PIP_CONSTRAINT affecting build environments.

This warns when build-constraint feature is NOT enabled and PIP_CONSTRAINT
is not empty.
is not empty, but only shows the warning once per process.
"""
global _DEPRECATION_WARNING_SHOWN

if self._build_constraint_feature_enabled:
return

if _DEPRECATION_WARNING_SHOWN:
return

pip_constraint = os.environ.get("PIP_CONSTRAINT")
if not pip_constraint or not pip_constraint.strip():
return

# Don't warn if we're in a build environment that ignores constraints
if os.environ.get("_PIP_IN_BUILD_IGNORE_CONSTRAINTS") == "1":
return

_DEPRECATION_WARNING_SHOWN = True
deprecated(
reason=(
"Setting PIP_CONSTRAINT will not affect "
Expand Down
41 changes: 41 additions & 0 deletions tests/unit/test_build_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

import os
import warnings
from pathlib import Path
from unittest import mock

Expand All @@ -17,6 +18,12 @@
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 @@ -112,3 +119,37 @@ 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

@mock.patch.dict(
os.environ,
{"PIP_CONSTRAINT": "constraints.txt", "_PIP_IN_BUILD_IGNORE_CONSTRAINTS": "1"},
)
def test_deprecation_check_no_warning_when_ignoring_constraints(self) -> None:
"""Test no deprecation warning when _PIP_IN_BUILD_IGNORE_CONSTRAINTS is set."""
finder = make_test_finder()
installer = SubprocessBuildEnvironmentInstaller(
finder,
build_constraint_feature_enabled=False,
)

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