python-pip/allow-stripping-given-prefix-from-wheel-RECORD-files.patch

111 lines
4.6 KiB
Diff
Raw Normal View History

2018-11-22 12:26:40 +00:00
diff --git a/src/pip/_internal/commands/install.py b/src/pip/_internal/commands/install.py
2019-02-13 10:56:20 +00:00
index 1c244d2..4b07ec0 100644
2018-11-22 12:26:40 +00:00
--- a/src/pip/_internal/commands/install.py
+++ b/src/pip/_internal/commands/install.py
2019-02-13 10:56:20 +00:00
@@ -109,6 +109,14 @@ class InstallCommand(RequirementCommand):
2018-07-23 15:22:50 +00:00
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."
+ )
+
2016-11-18 21:31:08 +00:00
2018-07-23 15:22:50 +00:00
cmd_opts.add_option(cmdoptions.build_dir())
2019-02-13 10:56:20 +00:00
@@ -391,6 +399,7 @@ class InstallCommand(RequirementCommand):
2018-07-23 15:22:50 +00:00
pycompile=options.compile,
warn_script_location=warn_script_location,
use_user_site=options.use_user_site,
+ strip_file_prefix=options.strip_file_prefix,
)
2018-07-23 15:22:50 +00:00
lib_locations = get_lib_location_guesses(
2018-11-22 12:26:40 +00:00
diff --git a/src/pip/_internal/req/req_install.py b/src/pip/_internal/req/req_install.py
2019-02-13 10:56:20 +00:00
index a4834b0..d21530a 100644
2018-11-22 12:26:40 +00:00
--- a/src/pip/_internal/req/req_install.py
+++ b/src/pip/_internal/req/req_install.py
2019-02-13 10:56:20 +00:00
@@ -431,7 +431,8 @@ class InstallRequirement(object):
prefix=None, # type: Optional[str]
warn_script_location=True, # type: bool
use_user_site=False, # type: bool
- pycompile=True # type: bool
+ pycompile=True, # type: bool
+ strip_file_prefix=None # type: Optional[str]
):
# type: (...) -> None
move_wheel_files(
2019-02-13 10:56:20 +00:00
@@ -443,6 +444,7 @@ class InstallRequirement(object):
2018-07-23 15:22:50 +00:00
pycompile=pycompile,
2015-01-15 13:05:55 +00:00
isolated=self.isolated,
2018-07-23 15:22:50 +00:00
warn_script_location=warn_script_location,
+ strip_file_prefix=strip_file_prefix,
)
2018-07-23 15:22:50 +00:00
# Things valid for sdists
2019-02-13 10:56:20 +00:00
@@ -894,7 +896,8 @@ class InstallRequirement(object):
prefix=None, # type: Optional[str]
warn_script_location=True, # type: bool
use_user_site=False, # type: bool
- pycompile=True # type: bool
+ pycompile=True, # type: bool
+ strip_file_prefix=None # type: Optional[str]
):
# type: (...) -> None
2018-07-23 15:22:50 +00:00
global_options = global_options if global_options is not None else []
2019-02-13 10:56:20 +00:00
@@ -911,6 +914,7 @@ class InstallRequirement(object):
2018-07-23 15:22:50 +00:00
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
2018-11-22 12:26:40 +00:00
diff --git a/src/pip/_internal/wheel.py b/src/pip/_internal/wheel.py
2019-02-13 10:56:20 +00:00
index 700b180..3655bd4 100644
2018-11-22 12:26:40 +00:00
--- a/src/pip/_internal/wheel.py
+++ b/src/pip/_internal/wheel.py
2019-02-13 10:56:20 +00:00
@@ -265,6 +265,7 @@ def get_csv_rows_for_installed(
changed, # type: set
generated, # type: List[str]
lib_dir, # type: str
+ strip_file_prefix=None, # type: Optional[str]
):
# type: (...) -> List[InstalledCSVRow]
installed_rows = [] # type: List[InstalledCSVRow]
@@ -282,7 +283,11 @@ def get_csv_rows_for_installed(
installed_rows.append(tuple(row))
for f in generated:
digest, length = rehash(f)
- installed_rows.append((normpath(f, lib_dir), digest, str(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))
+ installed_rows.append((final_path, digest, str(length)))
for f in installed:
installed_rows.append((installed[f], '', ''))
return installed_rows
@@ -299,7 +304,8 @@ def move_wheel_files(
scheme=None, # type: Optional[Mapping[str, str]]
isolated=False, # type: bool
prefix=None, # type: Optional[str]
- warn_script_location=True # type: bool
+ warn_script_location=True, # type: bool
+ strip_file_prefix=None # type: Optional[str]
):
# type: (...) -> None
"""Install a wheel"""
2019-02-13 10:56:20 +00:00
@@ -598,6 +604,7 @@ if __name__ == '__main__':
outrows = get_csv_rows_for_installed(
reader, installed=installed, changed=changed,
generated=generated, lib_dir=lib_dir,
+ strip_file_prefix=strip_file_prefix
)
writer = csv.writer(record_out)
# Sort to simplify testing.