commit aefacbb76661520415a1c35028f2984e70cfe0bf Author: Slavek Kabrda Date: Fri Nov 29 13:24:58 2013 +0100 Allow stripping given prefix from wheel RECORD files diff --git a/pip/commands/install.py b/pip/commands/install.py index 1693d01..0287c06 100644 --- a/pip/commands/install.py +++ b/pip/commands/install.py @@ -137,6 +137,14 @@ class InstallCommand(Command): help="Install everything relative to this alternate root directory.") 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( "--compile", action="store_true", dest="compile", @@ -273,7 +281,11 @@ class InstallCommand(Command): requirement_set.locate_files() if not options.no_install and not self.bundle: - requirement_set.install(install_options, global_options, root=options.root_path) + requirement_set.install( + install_options, + global_options, + root=options.root_path, + strip_file_prefix=options.strip_file_prefix) installed = ' '.join([req.name for req in requirement_set.successfully_installed]) if installed: diff --git a/pip/req.py b/pip/req.py index 3ae306d..c171130 100644 --- a/pip/req.py +++ b/pip/req.py @@ -615,15 +615,19 @@ exec(compile(open(__file__).read().replace('\\r\\n', '\\n'), __file__, 'exec')) name = name.replace(os.path.sep, '/') return name - def install(self, install_options, global_options=(), root=None): + def install(self, install_options, global_options=(), root=None, strip_file_prefix=None): if self.editable: self.install_editable(install_options, global_options) return if self.is_wheel: version = pip.wheel.wheel_version(self.source_dir) pip.wheel.check_compatibility(version, self.name) - self.move_wheel_files(self.source_dir, root=root) + self.move_wheel_files( + self.source_dir, + root=root, + strip_file_prefix=strip_file_prefix + ) self.install_succeeded = True return @@ -844,13 +848,14 @@ exec(compile(open(__file__).read().replace('\\r\\n', '\\n'), __file__, 'exec')) self._bundle_build_dirs = bundle_build_dirs self._bundle_editable_dirs = bundle_editable_dirs - def move_wheel_files(self, wheeldir, root=None): + def move_wheel_files(self, wheeldir, root=None, strip_file_prefix=None): move_wheel_files( self.name, self.req, wheeldir, user=self.use_user_site, home=self.target_dir, root=root, pycompile=self.pycompile, + strip_file_prefix=strip_file_prefix, ) @property diff --git a/pip/wheel.py b/pip/wheel.py index fa3e270..3a366d0 100644 --- a/pip/wheel.py +++ b/pip/wheel.py @@ -136,7 +136,7 @@ def get_entrypoints(filename): def move_wheel_files(name, req, wheeldir, user=False, home=None, root=None, - pycompile=True, scheme=None): + pycompile=True, scheme=None, strip_file_prefix=None): """Install a wheel""" if not scheme: @@ -357,6 +357,8 @@ if __name__ == '__main__': writer.writerow(row) for f in generated: h, l = rehash(f) + if strip_file_prefix and f.startswith(strip_file_prefix): + f = os.path.join(os.sep, os.path.relpath(f, strip_file_prefix)) writer.writerow((f, h, l)) for f in installed: writer.writerow((installed[f], '', ''))