Move all of --target stuff into a separate function
@@ -332,7 +332,14 @@ class InstallCommand(RequirementCommand):
requirement_set.cleanup_files()
if options.target_dir:
- ensure_dir(options.target_dir)
+ self._handle_target_dir(
+ options.target_dir, temp_target_dir, options.upgrade
+ )
+
+ return requirement_set
+
+ def _handle_target_dir(self, target_dir, temp_target_dir, upgrade):
+ ensure_dir(target_dir)
# Checking both purelib and platlib directories for installed
# packages to be moved to target directory
@@ -355,9 +362,9 @@ class InstallCommand(RequirementCommand):
ddir = os.path.join(data_dir, item)
if any(s.startswith(ddir) for s in lib_dir_list[:-1]):
continue
- target_item_dir = os.path.join(options.target_dir, item)
+ target_item_dir = os.path.join(target_dir, item)
if os.path.exists(target_item_dir):
- if not options.upgrade:
+ if not upgrade:
logger.warning(
'Target directory %s already exists. Specify '
'--upgrade to force replacement.',
@@ -383,7 +390,6 @@ class InstallCommand(RequirementCommand):
target_item_dir
)
shutil.rmtree(temp_target_dir)
- return requirement_set
def get_lib_location_guesses(*args, **kwargs):
