From 554db9230d035117dd36d39b3c6953006bf69577 Mon Sep 17 00:00:00 2001 From: Chris Hunt Date: Tue, 24 Dec 2019 16:56:24 -0500 Subject: [PATCH 1/3] Move directory requirement download logging out of unpack_file_url One less use of `download_dir` in `unpack_file_url`, which will make it easier to factor out. --- src/pip/_internal/operations/prepare.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/pip/_internal/operations/prepare.py b/src/pip/_internal/operations/prepare.py index 23f2e2f1982..78144476866 100644 --- a/src/pip/_internal/operations/prepare.py +++ b/src/pip/_internal/operations/prepare.py @@ -233,8 +233,6 @@ def unpack_file_url( if os.path.isdir(location): rmtree(location) _copy_source_tree(link_path, location) - if download_dir: - logger.info('Link is a directory, ignoring download_dir') return None # If a download dir is specified, is the file already there and valid? @@ -544,6 +542,10 @@ def prepare_linked_requirement( req, self.req_tracker, self.finder, self.build_isolation, ) + if link.is_existing_dir(): + if download_dir: + logger.info('Link is a directory, ignoring download_dir') + if self._download_should_save: # Make a .zip of the source_dir we already created. if link.is_vcs: From 5c901454621ba2958a85bd9eb76731a27bd88035 Mon Sep 17 00:00:00 2001 From: Chris Hunt Date: Tue, 24 Dec 2019 16:59:24 -0500 Subject: [PATCH 2/3] Switch conditions --- src/pip/_internal/operations/prepare.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pip/_internal/operations/prepare.py b/src/pip/_internal/operations/prepare.py index 78144476866..11afbd93db8 100644 --- a/src/pip/_internal/operations/prepare.py +++ b/src/pip/_internal/operations/prepare.py @@ -542,8 +542,8 @@ def prepare_linked_requirement( req, self.req_tracker, self.finder, self.build_isolation, ) - if link.is_existing_dir(): - if download_dir: + if download_dir: + if link.is_existing_dir(): logger.info('Link is a directory, ignoring download_dir') if self._download_should_save: From ce9ddbb60015de29f7bf4c0d2b24387f5ff9e540 Mon Sep 17 00:00:00 2001 From: Chris Hunt Date: Tue, 24 Dec 2019 17:03:14 -0500 Subject: [PATCH 3/3] Move download file copying out of unpacking functions Now our "unpacking" functions aren't also for sometimes populating the download directory. --- src/pip/_internal/operations/prepare.py | 28 +++++-------------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/src/pip/_internal/operations/prepare.py b/src/pip/_internal/operations/prepare.py index 11afbd93db8..3b6e225a31c 100644 --- a/src/pip/_internal/operations/prepare.py +++ b/src/pip/_internal/operations/prepare.py @@ -165,12 +165,6 @@ def unpack_http_url( # downloading archives, they have to be unpacked to parse dependencies unpack_file(from_path, location, content_type) - # a download dir is specified; let's copy the archive there - if download_dir and not os.path.exists( - os.path.join(download_dir, link.filename) - ): - _copy_file(from_path, download_dir, link) - return from_path @@ -223,9 +217,6 @@ def unpack_file_url( ): # type: (...) -> Optional[str] """Unpack link into location. - - If download_dir is provided and link points to a file, make a copy - of the link file inside download_dir. """ link_path = link.file_path # If it's a url to a local directory @@ -261,12 +252,6 @@ def unpack_file_url( # archives, they have to be unpacked to parse dependencies unpack_file(from_path, location, content_type) - # a download dir is specified and not already downloaded - if download_dir and not os.path.exists( - os.path.join(download_dir, link.filename) - ): - _copy_file(from_path, download_dir, link) - return from_path @@ -278,14 +263,7 @@ def unpack_url( hashes=None, # type: Optional[Hashes] ): # type: (...) -> Optional[str] - """Unpack link. - If link is a VCS link: - if only_download, export into download_dir and ignore location - else unpack into location - for other types of link: - - unpack into location - - if download_dir, copy the file into download_dir - - if only_download, mark location for deletion + """Unpack link into location, downloading if required. :param hashes: A Hashes object, one of whose embedded hashes must match, or HashMismatch will be raised. If the Hashes is empty, no matches are @@ -545,6 +523,10 @@ def prepare_linked_requirement( if download_dir: if link.is_existing_dir(): logger.info('Link is a directory, ignoring download_dir') + elif local_path and not os.path.exists( + os.path.join(download_dir, link.filename) + ): + _copy_file(local_path, download_dir, link) if self._download_should_save: # Make a .zip of the source_dir we already created.