Skip to content

Commit 4653cde

Browse files
authored
Merge pull request #7834 from chrahunt/refactor/simplify-download-copy
Remove pip._internal.operations.prepare._copy_file
2 parents 115a836 + fad99dc commit 4653cde

File tree

1 file changed

+9
-38
lines changed

1 file changed

+9
-38
lines changed

src/pip/_internal/operations/prepare.py

Lines changed: 9 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import mimetypes
99
import os
1010
import shutil
11-
import sys
1211

1312
from pip._vendor import requests
1413
from pip._vendor.six import PY2
@@ -29,8 +28,6 @@
2928
from pip._internal.utils.hashes import MissingHashes
3029
from pip._internal.utils.logging import indent_log
3130
from pip._internal.utils.misc import (
32-
ask_path_exists,
33-
backup_dir,
3431
display_path,
3532
hide_url,
3633
path_to_display,
@@ -102,37 +99,6 @@ def unpack_vcs_link(link, location):
10299
vcs_backend.unpack(location, url=hide_url(link.url))
103100

104101

105-
def _copy_file(filename, location, link):
106-
# type: (str, str, Link) -> None
107-
copy = True
108-
download_location = os.path.join(location, link.filename)
109-
if os.path.exists(download_location):
110-
response = ask_path_exists(
111-
'The file {} exists. (i)gnore, (w)ipe, (b)ackup, (a)abort'.format(
112-
display_path(download_location)
113-
),
114-
('i', 'w', 'b', 'a'),
115-
)
116-
if response == 'i':
117-
copy = False
118-
elif response == 'w':
119-
logger.warning('Deleting %s', display_path(download_location))
120-
os.remove(download_location)
121-
elif response == 'b':
122-
dest_file = backup_dir(download_location)
123-
logger.warning(
124-
'Backing up %s to %s',
125-
display_path(download_location),
126-
display_path(dest_file),
127-
)
128-
shutil.move(download_location, dest_file)
129-
elif response == 'a':
130-
sys.exit(-1)
131-
if copy:
132-
shutil.copy(filename, download_location)
133-
logger.info('Saved %s', display_path(download_location))
134-
135-
136102
class File(object):
137103
def __init__(self, path, content_type):
138104
# type: (str, str) -> None
@@ -513,10 +479,15 @@ def prepare_linked_requirement(
513479
if download_dir:
514480
if link.is_existing_dir():
515481
logger.info('Link is a directory, ignoring download_dir')
516-
elif local_file and not os.path.exists(
517-
os.path.join(download_dir, link.filename)
518-
):
519-
_copy_file(local_file.path, download_dir, link)
482+
elif local_file:
483+
download_location = os.path.join(
484+
download_dir, link.filename
485+
)
486+
if not os.path.exists(download_location):
487+
shutil.copy(local_file.path, download_location)
488+
logger.info(
489+
'Saved %s', display_path(download_location)
490+
)
520491

521492
if self._download_should_save:
522493
# Make a .zip of the source_dir we already created.

0 commit comments

Comments
 (0)