diff --git a/src/pip/_internal/commands/install.py b/src/pip/_internal/commands/install.py index 6fc178f..1279d4a 100644 --- a/src/pip/_internal/commands/install.py +++ b/src/pip/_internal/commands/install.py @@ -115,6 +115,14 @@ class InstallCommand(RequirementCommand): default=None, help="Installation prefix where lib, bin and other top-level " "folders are placed") + cmd_opts.add_option( + '--strip-file-prefix', + dest='strip_file_prefix', + metavar='prefix', + default=None, + help="Strip given prefix from script paths in wheel RECORD." + ) + cmd_opts.add_option(cmdoptions.build_dir()) @@ -364,6 +372,7 @@ class InstallCommand(RequirementCommand): pycompile=options.compile, warn_script_location=warn_script_location, use_user_site=options.use_user_site, + strip_file_prefix=options.strip_file_prefix, ) lib_locations = get_lib_location_guesses( diff --git a/src/pip/_internal/req/req_install.py b/src/pip/_internal/req/req_install.py index c2624fe..922d10c 100644 --- a/src/pip/_internal/req/req_install.py +++ b/src/pip/_internal/req/req_install.py @@ -370,7 +370,7 @@ class InstallRequirement(object): def move_wheel_files(self, wheeldir, root=None, home=None, prefix=None, warn_script_location=True, use_user_site=False, - pycompile=True): + pycompile=True, strip_file_prefix=None): move_wheel_files( self.name, self.req, wheeldir, user=use_user_site, @@ -380,6 +380,7 @@ class InstallRequirement(object): pycompile=pycompile, isolated=self.isolated, warn_script_location=warn_script_location, + strip_file_prefix=strip_file_prefix, ) # Things valid for sdists @@ -743,7 +744,7 @@ class InstallRequirement(object): def install(self, install_options, global_options=None, root=None, home=None, prefix=None, warn_script_location=True, - use_user_site=False, pycompile=True): + use_user_site=False, pycompile=True, strip_file_prefix=None): global_options = global_options if global_options is not None else [] if self.editable: self.install_editable( @@ -758,6 +759,7 @@ class InstallRequirement(object): self.source_dir, root=root, prefix=prefix, home=home, warn_script_location=warn_script_location, use_user_site=use_user_site, pycompile=pycompile, + strip_file_prefix=strip_file_prefix, ) self.install_succeeded = True return diff --git a/src/pip/_internal/wheel.py b/src/pip/_internal/wheel.py index 5ce890e..c42d77a 100644 --- a/src/pip/_internal/wheel.py +++ b/src/pip/_internal/wheel.py @@ -206,7 +206,7 @@ def message_about_scripts_not_on_PATH(scripts): def move_wheel_files(name, req, wheeldir, user=False, home=None, root=None, pycompile=True, scheme=None, isolated=False, prefix=None, - warn_script_location=True): + warn_script_location=True, strip_file_prefix=None): """Install a wheel""" if not scheme: @@ -508,7 +508,11 @@ if __name__ == '__main__': outrows.append(tuple(row)) for f in generated: digest, length = rehash(f) - outrows.append((normpath(f, lib_dir), digest, length)) + final_path = normpath(f, lib_dir) + if strip_file_prefix and final_path.startswith(strip_file_prefix): + final_path = os.path.join(os.sep, + os.path.relpath(final_path, strip_file_prefix)) + outrows.append((final_path, digest, length)) for f in installed: outrows.append((installed[f], '', '')) for row in sorted(outrows):