From eb91e8ca39dd59e41f4be51f955f52413004533a Mon Sep 17 00:00:00 2001 From: Chris Hunt Date: Sun, 23 Feb 2020 14:37:01 -0500 Subject: [PATCH] Use Command context helper to cleanup requirement tracker The lifetime of the requirement tracker will be essentially the same, but now we have more flexibility on where in the code we create it. In a followup we can do the same thing with build_dir and remove the `with` statement (and its indentation) entirely from these commands. --- src/pip/_internal/commands/download.py | 4 +++- src/pip/_internal/commands/install.py | 4 +++- src/pip/_internal/commands/wheel.py | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/pip/_internal/commands/download.py b/src/pip/_internal/commands/download.py index 69c7c9a60..edd334346 100644 --- a/src/pip/_internal/commands/download.py +++ b/src/pip/_internal/commands/download.py @@ -98,7 +98,9 @@ class DownloadCommand(RequirementCommand): ) build_delete = (not (options.no_clean or options.build_dir)) - with get_requirement_tracker() as req_tracker, TempDirectory( + req_tracker = self.enter_context(get_requirement_tracker()) + + with TempDirectory( options.build_dir, delete=build_delete, kind="download" ) as directory: reqs = self.get_requirements( diff --git a/src/pip/_internal/commands/install.py b/src/pip/_internal/commands/install.py index 242df7d82..afa2c24d0 100644 --- a/src/pip/_internal/commands/install.py +++ b/src/pip/_internal/commands/install.py @@ -288,7 +288,9 @@ class InstallCommand(RequirementCommand): build_delete = (not (options.no_clean or options.build_dir)) wheel_cache = WheelCache(options.cache_dir, options.format_control) - with get_requirement_tracker() as req_tracker, TempDirectory( + req_tracker = self.enter_context(get_requirement_tracker()) + + with TempDirectory( options.build_dir, delete=build_delete, kind="install" ) as directory: try: diff --git a/src/pip/_internal/commands/wheel.py b/src/pip/_internal/commands/wheel.py index a5bf28c94..7fbcb70f1 100644 --- a/src/pip/_internal/commands/wheel.py +++ b/src/pip/_internal/commands/wheel.py @@ -124,7 +124,9 @@ class WheelCommand(RequirementCommand): options.wheel_dir = normalize_path(options.wheel_dir) ensure_dir(options.wheel_dir) - with get_requirement_tracker() as req_tracker, TempDirectory( + req_tracker = self.enter_context(get_requirement_tracker()) + + with TempDirectory( options.build_dir, delete=build_delete, kind="wheel" ) as directory: try: