Skip to content

Commit 09457c7

Browse files
authored
Use installer to remove custom unzip and spread code (#715)
1 parent 5c6661e commit 09457c7

File tree

10 files changed

+55
-272
lines changed

10 files changed

+55
-272
lines changed

examples/pip_install/pip_install_test.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,11 @@ def test_data(self):
3737
self.assertListEqual(
3838
env.split(" "),
3939
[
40-
"external/pip/pypi__s3cmd/s3cmd-2.1.0.data/data/share/doc/packages/s3cmd/INSTALL.md",
41-
"external/pip/pypi__s3cmd/s3cmd-2.1.0.data/data/share/doc/packages/s3cmd/LICENSE",
42-
"external/pip/pypi__s3cmd/s3cmd-2.1.0.data/data/share/doc/packages/s3cmd/NEWS",
43-
"external/pip/pypi__s3cmd/s3cmd-2.1.0.data/data/share/doc/packages/s3cmd/README.md",
44-
"external/pip/pypi__s3cmd/s3cmd-2.1.0.data/data/share/man/man1/s3cmd.1",
45-
"external/pip/pypi__s3cmd/s3cmd-2.1.0.data/scripts/s3cmd",
40+
"external/pip/pypi__s3cmd/data/share/doc/packages/s3cmd/INSTALL.md",
41+
"external/pip/pypi__s3cmd/data/share/doc/packages/s3cmd/LICENSE",
42+
"external/pip/pypi__s3cmd/data/share/doc/packages/s3cmd/NEWS",
43+
"external/pip/pypi__s3cmd/data/share/doc/packages/s3cmd/README.md",
44+
"external/pip/pypi__s3cmd/data/share/man/man1/s3cmd.1",
4645
],
4746
)
4847

@@ -52,12 +51,13 @@ def test_dist_info(self):
5251
self.assertListEqual(
5352
env.split(" "),
5453
[
55-
"external/pip/pypi__boto3/boto3-1.14.51.dist-info/DESCRIPTION.rst",
56-
"external/pip/pypi__boto3/boto3-1.14.51.dist-info/METADATA",
57-
"external/pip/pypi__boto3/boto3-1.14.51.dist-info/RECORD",
58-
"external/pip/pypi__boto3/boto3-1.14.51.dist-info/WHEEL",
59-
"external/pip/pypi__boto3/boto3-1.14.51.dist-info/metadata.json",
60-
"external/pip/pypi__boto3/boto3-1.14.51.dist-info/top_level.txt",
54+
"external/pip/pypi__boto3/site-packages/boto3-1.14.51.dist-info/DESCRIPTION.rst",
55+
'external/pip/pypi__boto3/site-packages/boto3-1.14.51.dist-info/INSTALLER',
56+
"external/pip/pypi__boto3/site-packages/boto3-1.14.51.dist-info/METADATA",
57+
"external/pip/pypi__boto3/site-packages/boto3-1.14.51.dist-info/RECORD",
58+
"external/pip/pypi__boto3/site-packages/boto3-1.14.51.dist-info/WHEEL",
59+
"external/pip/pypi__boto3/site-packages/boto3-1.14.51.dist-info/metadata.json",
60+
"external/pip/pypi__boto3/site-packages/boto3-1.14.51.dist-info/top_level.txt",
6161
],
6262
)
6363

examples/pip_parse/pip_parse_test.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,11 @@ def test_data(self):
3535
self.assertListEqual(
3636
env.split(" "),
3737
[
38-
"external/pypi_s3cmd/s3cmd-2.1.0.data/data/share/doc/packages/s3cmd/INSTALL.md",
39-
"external/pypi_s3cmd/s3cmd-2.1.0.data/data/share/doc/packages/s3cmd/LICENSE",
40-
"external/pypi_s3cmd/s3cmd-2.1.0.data/data/share/doc/packages/s3cmd/NEWS",
41-
"external/pypi_s3cmd/s3cmd-2.1.0.data/data/share/doc/packages/s3cmd/README.md",
42-
"external/pypi_s3cmd/s3cmd-2.1.0.data/data/share/man/man1/s3cmd.1",
43-
"external/pypi_s3cmd/s3cmd-2.1.0.data/scripts/s3cmd",
38+
"external/pypi_s3cmd/data/share/doc/packages/s3cmd/INSTALL.md",
39+
"external/pypi_s3cmd/data/share/doc/packages/s3cmd/LICENSE",
40+
"external/pypi_s3cmd/data/share/doc/packages/s3cmd/NEWS",
41+
"external/pypi_s3cmd/data/share/doc/packages/s3cmd/README.md",
42+
"external/pypi_s3cmd/data/share/man/man1/s3cmd.1",
4443
],
4544
)
4645

@@ -50,11 +49,12 @@ def test_dist_info(self):
5049
self.assertListEqual(
5150
env.split(" "),
5251
[
53-
"external/pypi_requests/requests-2.25.1.dist-info/LICENSE",
54-
"external/pypi_requests/requests-2.25.1.dist-info/METADATA",
55-
"external/pypi_requests/requests-2.25.1.dist-info/RECORD",
56-
"external/pypi_requests/requests-2.25.1.dist-info/WHEEL",
57-
"external/pypi_requests/requests-2.25.1.dist-info/top_level.txt",
52+
'external/pypi_requests/site-packages/requests-2.25.1.dist-info/INSTALLER',
53+
"external/pypi_requests/site-packages/requests-2.25.1.dist-info/LICENSE",
54+
"external/pypi_requests/site-packages/requests-2.25.1.dist-info/METADATA",
55+
"external/pypi_requests/site-packages/requests-2.25.1.dist-info/RECORD",
56+
"external/pypi_requests/site-packages/requests-2.25.1.dist-info/WHEEL",
57+
"external/pypi_requests/site-packages/requests-2.25.1.dist-info/top_level.txt",
5858
],
5959
)
6060

examples/pip_repository_annotations/WORKSPACE

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ write_file(
4242
copy_executables = {"@pip_repository_annotations_example//:data/copy_executable.py": "copied_content/executable.py"},
4343
copy_files = {"@pip_repository_annotations_example//:data/copy_file.txt": "copied_content/file.txt"},
4444
data = [":generated_file"],
45-
data_exclude_glob = ["*.dist-info/WHEEL"],
45+
data_exclude_glob = ["site-packages/*.dist-info/WHEEL"],
4646
),
4747
}
4848

examples/pip_repository_annotations/pip_repository_annotations_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def test_data_exclude_glob(self):
6969

7070
r = runfiles.Create()
7171
dist_info_dir = (
72-
"pip_repository_annotations_example/external/{}/wheel-{}.dist-info".format(
72+
"pip_repository_annotations_example/external/{}/site-packages/wheel-{}.dist-info".format(
7373
self.wheel_pkg_dir(),
7474
current_wheel_version,
7575
)

python/pip_install/extract_wheels/lib/BUILD

-12
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ py_library(
99
"arguments.py",
1010
"bazel.py",
1111
"namespace_pkgs.py",
12-
"purelib.py",
1312
"requirements.py",
1413
"wheel.py",
1514
],
@@ -135,17 +134,6 @@ py_test(
135134
],
136135
)
137136

138-
py_test(
139-
name = "purelib_test",
140-
size = "small",
141-
srcs = [
142-
"purelib_test.py",
143-
],
144-
deps = [
145-
":lib",
146-
],
147-
)
148-
149137
filegroup(
150138
name = "distribution",
151139
srcs = glob(

python/pip_install/extract_wheels/lib/bazel.py

+9-22
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from python.pip_install.extract_wheels.lib import (
1010
annotation,
1111
namespace_pkgs,
12-
purelib,
1312
wheel,
1413
)
1514

@@ -137,27 +136,18 @@ def generate_build_file_contents(
137136
there may be no Python sources whatsoever (e.g. packages written in Cython: like `pymssql`).
138137
"""
139138

140-
dist_info_ignores = [
141-
# RECORD is known to contain sha256 checksums of files which might include the checksums
142-
# of generated files produced when wheels are installed. The file is ignored to avoid
143-
# Bazel caching issues.
144-
"**/*.dist-info/RECORD",
145-
]
146-
147139
data_exclude = list(
148140
set(
149141
[
150-
"*.whl",
151-
"**/__pycache__/**",
152142
"**/* *",
153143
"**/*.py",
154144
"**/*.pyc",
155-
"BUILD.bazel",
156-
"WORKSPACE",
157-
f"{WHEEL_ENTRY_POINT_PREFIX}*.py",
145+
# RECORD is known to contain sha256 checksums of files which might include the checksums
146+
# of generated files produced when wheels are installed. The file is ignored to avoid
147+
# Bazel caching issues.
148+
"**/*.dist-info/RECORD",
158149
]
159150
+ data_exclude
160-
+ dist_info_ignores
161151
)
162152
)
163153

@@ -172,12 +162,12 @@ def generate_build_file_contents(
172162
173163
filegroup(
174164
name = "{dist_info_label}",
175-
srcs = glob(["*.dist-info/**"], allow_empty = True),
165+
srcs = glob(["site-packages/*.dist-info/**"], allow_empty = True),
176166
)
177167
178168
filegroup(
179169
name = "{data_label}",
180-
srcs = glob(["*.data/**"], allow_empty = True),
170+
srcs = glob(["data/**"], allow_empty = True),
181171
)
182172
183173
filegroup(
@@ -188,11 +178,11 @@ def generate_build_file_contents(
188178
189179
py_library(
190180
name = "{name}",
191-
srcs = glob(["**/*.py"], exclude={srcs_exclude}, allow_empty = True),
192-
data = {data} + glob(["**/*"], exclude={data_exclude}),
181+
srcs = glob(["site-packages/**/*.py"], exclude={srcs_exclude}, allow_empty = True),
182+
data = {data} + glob(["site-packages/**/*"], exclude={data_exclude}),
193183
# This makes this directory a top-level in the python import
194184
# search path for anything that depends on this.
195-
imports = ["."],
185+
imports = ["site-packages"],
196186
deps = [{dependencies}],
197187
tags = [{tags}],
198188
)
@@ -377,9 +367,6 @@ def extract_wheel(
377367
shutil.copy(whl.path, directory)
378368
whl.unzip(directory)
379369

380-
# Note: Order of operations matters here
381-
purelib.spread_purelib_into_root(directory)
382-
383370
if not enable_implicit_namespace_pkgs:
384371
setup_namespace_pkg_compatibility(directory)
385372

python/pip_install/extract_wheels/lib/purelib.py

-67
This file was deleted.

python/pip_install/extract_wheels/lib/purelib_test.py

-40
This file was deleted.

0 commit comments

Comments
 (0)