Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix installation using --target #3730

Closed
wants to merge 6 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 39 additions & 29 deletions pip/commands/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,35 +352,45 @@ def run(self, options, args):
if options.target_dir:
ensure_dir(options.target_dir)

lib_dir = distutils_scheme('', home=temp_target_dir)['purelib']

for item in os.listdir(lib_dir):
target_item_dir = os.path.join(options.target_dir, item)
if os.path.exists(target_item_dir):
if not options.upgrade:
logger.warning(
'Target directory %s already exists. Specify '
'--upgrade to force replacement.',
target_item_dir
)
continue
if os.path.islink(target_item_dir):
logger.warning(
'Target directory %s already exists and is '
'a link. Pip will not automatically replace '
'links, please remove if replacement is '
'desired.',
target_item_dir
)
continue
if os.path.isdir(target_item_dir):
shutil.rmtree(target_item_dir)
else:
os.remove(target_item_dir)
lib_dir_purelib = distutils_scheme('', home=temp_target_dir)['purelib']
lib_dir_platlib = distutils_scheme('', home=temp_target_dir)['platlib']
if os.path.exists(lib_dir_purelib):
self._install_to_target(lib_dir_purelib, options.target_dir,
options)
if os.path.exists(lib_dir_platlib):
self._install_to_target(lib_dir_platlib, options.target_dir,
options)

shutil.move(
os.path.join(lib_dir, item),
target_item_dir
)
shutil.rmtree(temp_target_dir)
return requirement_set

@staticmethod
def _install_to_target(lib_dir, target_dir, options):
for item in os.listdir(lib_dir):
target_item_dir = os.path.join(target_dir, item)
if os.path.exists(target_item_dir):
if not options.upgrade:
logger.warning(
'Target directory %s already exists. Specify '
'--upgrade to force replacement.',
target_item_dir
)
continue
if os.path.islink(target_item_dir):
logger.warning(
'Target directory %s already exists and is '
'a link. Pip will not automatically replace '
'links, please remove if replacement is '
'desired.',
target_item_dir
)
continue
if os.path.isdir(target_item_dir):
shutil.rmtree(target_item_dir)
else:
os.remove(target_item_dir)

shutil.move(
os.path.join(lib_dir, item),
target_item_dir
)