Repository: pypa/pip
Pull request #10989 (2022-03-26 10:45:14)

Rename `RequirementTracker` to `BuildTracker`
Toward #6607




Patch:
diff --git a/src/pip/_internal/cli/req_command.py b/src/pip/_internal/cli/req_command.py
index 5d4d1f0f4..970deec2c 100644
--- a/src/pip/_internal/cli/req_command.py
+++ b/src/pip/_internal/cli/req_command.py
@@ -22,6 +22,7 @@ from pip._internal.index.package_finder import PackageFinder
 from pip._internal.models.selection_prefs import SelectionPreferences
 from pip._internal.models.target_python import TargetPython
 from pip._internal.network.session import PipSession
+from pip._internal.operations.build.build_tracker import BuildTracker
 from pip._internal.operations.prepare import RequirementPreparer
 from pip._internal.req.constructors import (
     install_req_from_editable,
@@ -31,7 +32,6 @@ from pip._internal.req.constructors import (
 )
 from pip._internal.req.req_file import parse_requirements
 from pip._internal.req.req_install import InstallRequirement
-from pip._internal.req.req_tracker import RequirementTracker
 from pip._internal.resolution.base import BaseResolver
 from pip._internal.self_outdated_check import pip_self_version_check
 from pip._internal.utils.deprecation import deprecated
@@ -257,7 +257,7 @@ class RequirementCommand(IndexGroupCommand):
         cls,
         temp_build_dir: TempDirectory,
         options: Values,
-        req_tracker: RequirementTracker,
+        build_tracker: BuildTracker,
         session: PipSession,
         finder: PackageFinder,
         use_user_site: bool,
@@ -314,7 +314,7 @@ class RequirementCommand(IndexGroupCommand):
             src_dir=options.src_dir,
             download_dir=download_dir,
             build_isolation=options.build_isolation,
-            req_tracker=req_tracker,
+            build_tracker=build_tracker,
             session=session,
             progress_bar=options.progress_bar,
             finder=finder,
diff --git a/src/pip/_internal/commands/download.py b/src/pip/_internal/commands/download.py
index 233b7e983..a6d7e628f 100644
--- a/src/pip/_internal/commands/download.py
+++ b/src/pip/_internal/commands/download.py
@@ -7,7 +7,7 @@ from pip._internal.cli import cmdoptions
 from pip._internal.cli.cmdoptions import make_target_python
 from pip._internal.cli.req_command import RequirementCommand, with_cleanup
 from pip._internal.cli.status_codes import SUCCESS
-from pip._internal.req.req_tracker import get_requirement_tracker
+from pip._internal.operations.build.build_tracker import get_build_tracker
 from pip._internal.utils.misc import ensure_dir, normalize_path, write_output
 from pip._internal.utils.temp_dir import TempDirectory
 
@@ -95,7 +95,7 @@ class DownloadCommand(RequirementCommand):
             ignore_requires_python=options.ignore_requires_python,
         )
 
-        req_tracker = self.enter_context(get_requirement_tracker())
+        build_tracker = self.enter_context(get_build_tracker())
 
         directory = TempDirectory(
             delete=not options.no_clean,
@@ -108,7 +108,7 @@ class DownloadCommand(RequirementCommand):
         preparer = self.make_requirement_preparer(
             temp_build_dir=directory,
             options=options,
-            req_tracker=req_tracker,
+            build_tracker=build_tracker,
             session=session,
             finder=finder,
             download_dir=options.download_dir,
diff --git a/src/pip/_internal/commands/install.py b/src/pip/_internal/commands/install.py
index 34e4c2f84..db41b9a1b 100644
--- a/src/pip/_internal/commands/install.py
+++ b/src/pip/_internal/commands/install.py
@@ -21,10 +21,10 @@ from pip._internal.exceptions import CommandError, InstallationError
 from pip._internal.locations import get_scheme
 from pip._internal.metadata import get_environment
 from pip._internal.models.format_control import FormatControl
+from pip._internal.operations.build.build_tracker import get_build_tracker
 from pip._internal.operations.check import ConflictDetails, check_install_conflicts
 from pip._internal.req import install_given_reqs
 from pip._internal.req.req_install import InstallRequirement
-from pip._internal.req.req_tracker import get_requirement_tracker
 from pip._internal.utils.compat import WINDOWS
 from pip._internal.utils.distutils_args import parse_distutils_args
 from pip._internal.utils.filesystem import test_writable_dir
@@ -293,7 +293,7 @@ class InstallCommand(RequirementCommand):
         )
         wheel_cache = WheelCache(options.cache_dir, options.format_control)
 
-        req_tracker = self.enter_context(get_requirement_tracker())
+        build_tracker = self.enter_context(get_build_tracker())
 
         directory = TempDirectory(
             delete=not options.no_clean,
@@ -315,7 +315,7 @@ class InstallCommand(RequirementCommand):
             preparer = self.make_requirement_preparer(
                 temp_build_dir=directory,
                 options=options,
-                req_tracker=req_tracker,
+                build_tracker=build_tracker,
                 session=session,
                 finder=finder,
                 use_user_site=options.use_user_site,
diff --git a/src/pip/_internal/commands/wheel.py b/src/pip/_internal/commands/wheel.py
index fd4fab4fd..4fefe8111 100644
--- a/src/pip/_internal/commands/wheel.py
+++ b/src/pip/_internal/commands/wheel.py
@@ -9,8 +9,8 @@ from pip._internal.cli import cmdoptions
 from pip._internal.cli.req_command import RequirementCommand, with_cleanup
 from pip._internal.cli.status_codes import SUCCESS
 from pip._internal.exceptions import CommandError
+from pip._internal.operations.build.build_tracker import get_build_tracker
 from pip._internal.req.req_install import InstallRequirement
-from pip._internal.req.req_tracker import get_requirement_tracker
 from pip._internal.utils.misc import ensure_dir, normalize_path
 from pip._internal.utils.temp_dir import TempDirectory
 from pip._internal.wheel_builder import build, should_build_for_wheel_command
@@ -108,7 +108,7 @@ class WheelCommand(RequirementCommand):
         options.wheel_dir = normalize_path(options.wheel_dir)
         ensure_dir(options.wheel_dir)
 
-        req_tracker = self.enter_context(get_requirement_tracker())
+        build_tracker = self.enter_context(get_build_tracker())
 
         directory = TempDirectory(
             delete=not options.no_clean,
@@ -121,7 +121,7 @@ class WheelCommand(RequirementCommand):
         preparer = self.make_requirement_preparer(
             temp_build_dir=directory,
             options=options,
-            req_tracker=req_tracker,
+            build_tracker=build_tracker,
             session=session,
             finder=finder,
             download_dir=options.wheel_dir,
diff --git a/src/pip/_internal/req/req_tracker.py b/src/pip/_internal/operations/build/build_tracker.py
similarity index 90%
rename from src/pip/_internal/req/req_tracker.py
rename to src/pip/_internal/operations/build/build_tracker.py
index 24d3c5303..d6574f2ca 100644
--- a/src/pip/_internal/req/req_tracker.py
+++ b/src/pip/_internal/operations/build/build_tracker.py
@@ -39,25 +39,25 @@ def update_env_context_manager(**changes: str) -> Iterator[None]:
 
 
 @contextlib.contextmanager
-def get_requirement_tracker() -> Iterator["RequirementTracker"]:
-    root = os.environ.get("PIP_REQ_TRACKER")
+def get_build_tracker() -> Iterator["BuildTracker"]:
+    root = os.environ.get("PIP_BUILD_TRACKER")
     with contextlib.ExitStack() as ctx:
         if root is None:
-            root = ctx.enter_context(TempDirectory(kind="req-tracker")).path
-            ctx.enter_context(update_env_context_manager(PIP_REQ_TRACKER=root))
+            root = ctx.enter_context(TempDirectory(kind="build-tracker")).path
+            ctx.enter_context(update_env_context_manager(PIP_BUILD_TRACKER=root))
             logger.debug("Initialized build tracking at %s", root)
 
-        with RequirementTracker(root) as tracker:
+        with BuildTracker(root) as tracker:
             yield tracker
 
 
-class RequirementTracker:
+class BuildTracker:
     def __init__(self, root: str) -> None:
         self._root = root
         self._entries: Set[InstallRequirement] = set()
         logger.debug("Created build tracker: %s", self._root)
 
-    def __enter__(self) -> "RequirementTracker":
+    def __enter__(self) -> "BuildTracker":
         logger.debug("Entered build tracker: %s", self._root)
         return self
 
diff --git a/src/pip/_internal/operations/prepare.py b/src/pip/_internal/operations/prepare.py
index a726f031a..46252816d 100644
--- a/src/pip/_internal/operations/prepare.py
+++ b/src/pip/_internal/operations/prepare.py
@@ -33,8 +33,8 @@ from pip._internal.network.lazy_wheel import (
     dist_from_wheel_url,
 )
 from pip._internal.network.session import PipSession
+from pip._internal.operations.build.build_tracker import BuildTracker
 from pip._internal.req.req_install import InstallRequirement
-from pip._internal.req.req_tracker import RequirementTracker
 from pip._internal.utils.filesystem import copy2_fixed
 from pip._internal.utils.hashes import Hashes, MissingHashes
 from pip._internal.utils.logging import indent_log
@@ -48,13 +48,13 @@ logger = logging.getLogger(__name__)
 
 def _get_prepared_distribution(
     req: InstallRequirement,
-    req_tracker: RequirementTracker,
+    build_tracker: BuildTracker,
     finder: PackageFinder,
     build_isolation: bool,
 ) -> BaseDistribution:
     """Prepare a distribution for installation."""
     abstract_dist = make_distribution_for_install_requirement(req)
-    with req_tracker.track(req):
+    with build_tracker.track(req):
         abstract_dist.prepare_distribution_metadata(finder, build_isolation)
     return abstract_dist.get_metadata_distribution()
 
@@ -261,7 +261,7 @@ class RequirementPreparer:
         download_dir: Optional[str],
         src_dir: str,
         build_isolation: bool,
-        req_tracker: RequirementTracker,
+        build_tracker: BuildTracker,
         session: PipSession,
         progress_bar: str,
         finder: PackageFinder,
@@ -275,7 +275,7 @@ class RequirementPreparer:
 
         self.src_dir = src_dir
         self.build_dir = build_dir
-        self.req_tracker = req_tracker
+        self.build_tracker = build_tracker
         self._session = session
         self._download = Downloader(session, progress_bar)
         self._batch_download = BatchDownloader(session, progress_bar)
@@ -555,7 +555,7 @@ class RequirementPreparer:
 
         dist = _get_prepared_distribution(
             req,
-            self.req_tracker,
+            self.build_tracker,
             self.finder,
             self.build_isolation,
         )
@@ -608,7 +608,7 @@ class RequirementPreparer:
 
             dist = _get_prepared_distribution(
                 req,
-                self.req_tracker,
+                self.build_tracker,
                 self.finder,
                 self.build_isolation,
             )


Test patch:
diff --git a/tests/conftest.py b/tests/conftest.py
index 04b1b6e70..c137f8441 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -271,7 +271,7 @@ def isolate(tmpdir: Path, monkeypatch: pytest.MonkeyPatch) -> None:
     monkeypatch.setenv("PIP_DISABLE_PIP_VERSION_CHECK", "true")
 
     # Make sure tests don't share a requirements tracker.
-    monkeypatch.delenv("PIP_REQ_TRACKER", False)
+    monkeypatch.delenv("PIP_BUILD_TRACKER", False)
 
     # FIXME: Windows...
     os.makedirs(os.path.join(home_dir, ".config", "git"))
diff --git a/tests/unit/resolution_resolvelib/conftest.py b/tests/unit/resolution_resolvelib/conftest.py
index 545ed7c35..6cef3c17c 100644
--- a/tests/unit/resolution_resolvelib/conftest.py
+++ b/tests/unit/resolution_resolvelib/conftest.py
@@ -11,9 +11,9 @@ from pip._internal.index.package_finder import PackageFinder
 from pip._internal.models.search_scope import SearchScope
 from pip._internal.models.selection_prefs import SelectionPreferences
 from pip._internal.network.session import PipSession
+from pip._internal.operations.build.build_tracker import get_build_tracker
 from pip._internal.operations.prepare import RequirementPreparer
 from pip._internal.req.constructors import install_req_from_line
-from pip._internal.req.req_tracker import get_requirement_tracker
 from pip._internal.resolution.resolvelib.factory import Factory
 from pip._internal.resolution.resolvelib.provider import PipProvider
 from pip._internal.utils.temp_dir import TempDirectory, global_tempdir_manager
@@ -38,11 +38,11 @@ def preparer(finder: PackageFinder) -> Iterator[RequirementPreparer]:
 
     with global_tempdir_manager():
         with TempDirectory() as tmp:
-            with get_requirement_tracker() as tracker:
+            with get_build_tracker() as tracker:
                 preparer = RequirementCommand.make_requirement_preparer(
                     tmp,
                     options=o[0],
-                    req_tracker=tracker,
+                    build_tracker=tracker,
                     session=session,
                     finder=finder,
                     use_user_site=False,
diff --git a/tests/unit/test_req.py b/tests/unit/test_req.py
index 858695c1f..4a339e4e2 100644
--- a/tests/unit/test_req.py
+++ b/tests/unit/test_req.py
@@ -23,6 +23,7 @@ from pip._internal.exceptions import (
 from pip._internal.index.package_finder import PackageFinder
 from pip._internal.metadata.pkg_resources import Distribution
 from pip._internal.network.session import PipSession
+from pip._internal.operations.build.build_tracker import get_build_tracker
 from pip._internal.operations.prepare import RequirementPreparer
 from pip._internal.req import InstallRequirement, RequirementSet
 from pip._internal.req.constructors import (
@@ -39,7 +40,6 @@ from pip._internal.req.req_file import (
     get_line_parser,
     handle_requirement_line,
 )
-from pip._internal.req.req_tracker import get_requirement_tracker
 from pip._internal.resolution.legacy.resolver import Resolver
 from pip._internal.utils.urls import path_to_url
 from tests.lib import TestData, make_test_finder, requirements_file
@@ -85,13 +85,13 @@ class TestRequirementSet:
         )
         session = PipSession()
 
-        with get_requirement_tracker() as tracker:
+        with get_build_tracker() as tracker:
             preparer = RequirementPreparer(
                 build_dir=os.path.join(self.tempdir, "build"),
                 src_dir=os.path.join(self.tempdir, "src"),
                 download_dir=None,
                 build_isolation=True,
-                req_tracker=tracker,
+                build_tracker=tracker,
                 session=session,
                 progress_bar="on",
                 finder=finder,