python-pip/allow-stripping-given-prefi...

118 lines
4.5 KiB
Diff

From 7b3991c99cd8bb9358e109901d4aa8f51269a87a Mon Sep 17 00:00:00 2001
From: Tomas Orsava <tomas.n@orsava.cz>
Date: Tue, 17 May 2016 16:40:37 +0200
Subject: [PATCH] Allow stripping given prefix from wheel RECORD files
Update of a previous patch [0] by Slavek Kabrda <bkabrda@redhat.com>.
Changes in the pip/wheel.py file in upstream prevented #2 hunk from being
applied cleanly.
[0] pip-1.5rc1-allow-stripping-prefix-from-wheel-RECORD-files.patch
---
pip/commands/install.py | 9 +++++++++
pip/req/req_install.py | 13 +++++++++----
pip/wheel.py | 8 ++++++--
3 files changed, 24 insertions(+), 6 deletions(-)
diff --git a/pip/commands/install.py b/pip/commands/install.py
index 7ddde93..e31bd3e 100644
--- a/pip/commands/install.py
+++ b/pip/commands/install.py
@@ -137,6 +137,14 @@ class InstallCommand(RequirementCommand):
"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(
'--prefix',
dest='prefix_path',
metavar='dir',
@@ -315,6 +323,7 @@ class InstallCommand(RequirementCommand):
global_options,
root=options.root_path,
prefix=options.prefix_path,
+ strip_file_prefix=options.strip_file_prefix,
)
reqs = sorted(
requirement_set.successfully_installed,
diff --git a/pip/req/req_install.py b/pip/req/req_install.py
index 9e9fbbb..47f263f 100644
--- a/pip/req/req_install.py
+++ b/pip/req/req_install.py
@@ -818,8 +818,7 @@ class InstallRequirement(object):
else:
return True
- def install(self, install_options, global_options=[], root=None,
- prefix=None):
+ def install(self, install_options, global_options=[], root=None, prefix=None, strip_file_prefix=None):
if self.editable:
self.install_editable(
install_options, global_options, prefix=prefix)
@@ -828,7 +827,12 @@ class InstallRequirement(object):
version = pip.wheel.wheel_version(self.source_dir)
pip.wheel.check_compatibility(version, self.name)
- self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
+ self.move_wheel_files(
+ self.source_dir,
+ root=root,
+ prefix=prefix,
+ strip_file_prefix=strip_file_prefix
+ )
self.install_succeeded = True
return
@@ -1021,7 +1025,7 @@ class InstallRequirement(object):
def is_wheel(self):
return self.link and self.link.is_wheel
- def move_wheel_files(self, wheeldir, root=None, prefix=None):
+ def move_wheel_files(self, wheeldir, root=None, prefix=None, strip_file_prefix=None):
move_wheel_files(
self.name, self.req, wheeldir,
user=self.use_user_site,
@@ -1030,6 +1034,7 @@ class InstallRequirement(object):
prefix=prefix,
pycompile=self.pycompile,
isolated=self.isolated,
+ strip_file_prefix=strip_file_prefix,
)
def get_dist(self):
diff --git a/pip/wheel.py b/pip/wheel.py
index b257d76..6d78ce6 100644
--- a/pip/wheel.py
+++ b/pip/wheel.py
@@ -238,7 +238,7 @@ def get_entrypoints(filename):
def move_wheel_files(name, req, wheeldir, user=False, home=None, root=None,
- pycompile=True, scheme=None, isolated=False, prefix=None):
+ pycompile=True, scheme=None, isolated=False, prefix=None, strip_file_prefix=None):
"""Install a wheel"""
if not scheme:
@@ -522,7 +522,11 @@ if __name__ == '__main__':
writer.writerow(row)
for f in generated:
h, l = rehash(f)
- writer.writerow((normpath(f, lib_dir), h, l))
+ 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))
+ writer.writerow((final_path, h, l))
for f in installed:
writer.writerow((installed[f], '', ''))
shutil.move(temp_record, record)
--
2.5.5