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

Fixing issues with install's --target option. #2007

Merged
merged 3 commits into from Sep 11, 2014
Jump to file or symbol
Failed to load files and symbols.
+28 −2
Diff settings

Always

Just for now

Next

Fixing issues with install's --target option.

 1. Check for the existence of a directory before copying from temporary directory to final target. If it exists, warn the user.
 2. If the user specifies the --upgrade option and the directory exists, delete it and continue with installation.
 3. Adding tests for above cases.

This resolves #1489, #1710 completely and parts of #1833.
  • Loading branch information...
theacodes committed Aug 31, 2014
commit acf8634e8fc80055347c2d565f9fd1a877ae900e
View
@@ -51,7 +51,10 @@ def __init__(self, *args, **kw):
dest='target_dir',
metavar='dir',
default=None,
help='Install packages into <dir>.')
help='Install packages into <dir>. '
'By default this will not replace existing files/folders in <dir>.'
'Use --upgrade to replace existing packages in <dir> with new versions.'
)
cmd_opts.add_option(
'-d', '--download', '--download-dir', '--download-directory',
@@ -344,9 +347,19 @@ def run(self, options, args):
os.makedirs(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.warn('Target directory %s already exists. Specify --upgrade to force replacement.' % target_item_dir)
continue
if not os.path.isdir(target_item_dir):
logger.warn('Target directory %s already exists and is not a directory. Please remove in order for replacement.' % target_item_dir)
continue
shutil.rmtree(target_item_dir)
shutil.move(
os.path.join(lib_dir, item),
os.path.join(options.target_dir, item),
target_item_dir
)
shutil.rmtree(temp_target_dir)
return requirement_set
@@ -527,6 +527,19 @@ def test_install_package_with_target(script):
str(result)
)
# Test repeated call without --upgrade, no files should have changed
result = script.pip('install', '-t', target_dir, "initools==0.1")
assert not Path('scratch') / 'target' / 'initools' in result.files_updated
# Test upgrade call, check that new version is installed
result = script.pip('install', '--upgrade', '-t', target_dir, "initools==0.2")
assert Path('scratch') / 'target' / 'initools' in result.files_updated, (
str(result)
)
assert Path('scratch') / 'target' / 'INITools-0.2-py%s.egg-info' % pyversion in result.files_created, (
str(result)
)
def test_install_package_with_root(script, data):
"""
ProTip! Use n and p to navigate between commits in a pull request.