Skip to content

Commit c4076ea

Browse files
committed
Improve move_to_correct_build_directory
Why: Changes made are IMO much clearer, with a step by step flow to this method that is easier to reason about.
1 parent 5d74967 commit c4076ea

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

src/pip/_internal/req/req_install.py

+18-9
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ def __init__(
121121
markers = req.marker
122122
self.markers = markers
123123

124-
self._egg_info_path = None # type: Optional[str]
125124
# This holds the pkg_resources.Distribution object if this requirement
126125
# is already available:
127126
self.satisfied_by = None
@@ -367,29 +366,34 @@ def move_to_correct_build_directory(self):
367366
return
368367
assert self.req is not None
369368
assert self._temp_build_dir
370-
assert (self._ideal_build_dir is not None and
371-
self._ideal_build_dir.path) # type: ignore
369+
assert (
370+
self._ideal_build_dir is not None and
371+
self._ideal_build_dir.path # type: ignore
372+
)
372373
old_location = self._temp_build_dir
373-
self._temp_build_dir = None
374+
self._temp_build_dir = None # checked inside ensure_build_location
374375

376+
# Figure out the correct place to put the files.
375377
new_location = self.ensure_build_location(self._ideal_build_dir)
376378
if os.path.exists(new_location):
377379
raise InstallationError(
378380
'A package already exists in %s; please remove it to continue'
379-
% display_path(new_location))
381+
% display_path(new_location)
382+
)
383+
384+
# Move the files to the correct location.
380385
logger.debug(
381386
'Moving package %s from %s to new location %s',
382387
self, display_path(old_location.path), display_path(new_location),
383388
)
384389
shutil.move(old_location.path, new_location)
390+
391+
# Update directory-tracking variables, to be in line with new_location
392+
self.source_dir = os.path.normpath(os.path.abspath(new_location))
385393
self._temp_build_dir = TempDirectory(
386394
path=new_location, kind="req-install",
387395
)
388396

389-
self._ideal_build_dir = None
390-
self.source_dir = os.path.normpath(os.path.abspath(new_location))
391-
self._egg_info_path = None
392-
393397
# Correct the metadata directory, if it exists
394398
if self.metadata_directory:
395399
old_meta = self.metadata_directory
@@ -398,6 +402,11 @@ def move_to_correct_build_directory(self):
398402
new_meta = os.path.normpath(os.path.abspath(new_meta))
399403
self.metadata_directory = new_meta
400404

405+
# Done with any "move built files" work, since have moved files to the
406+
# "ideal" build location. Setting to None allows to clearly flag that
407+
# no more moves are needed.
408+
self._ideal_build_dir = None
409+
401410
def remove_temporary_source(self):
402411
# type: () -> None
403412
"""Remove the source files from this requirement, if they are marked

0 commit comments

Comments
 (0)