Skip to content

Commit

Permalink
fix: remove 'site-packages' from install dir prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
mattem committed Feb 27, 2024
1 parent 627830e commit 643ea7a
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 43 deletions.
2 changes: 1 addition & 1 deletion examples/bzlmod/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pip.whl_mods(
"@@//whl_mods:data/copy_file.txt": "copied_content/file.txt",
},
data = [":generated_file"],
data_exclude_glob = ["site-packages/*.dist-info/WHEEL"],
data_exclude_glob = ["*.dist-info/WHEEL"],
hub_name = "whl_mods_hub",
whl_name = "wheel",
)
Expand Down
4 changes: 2 additions & 2 deletions examples/bzlmod/whl_mods/pip_whl_mods_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def test_data_exclude_glob(self):
current_wheel_version = "0.40.0"

r = runfiles.Create()
dist_info_dir = "{}/site-packages/wheel-{}.dist-info".format(
dist_info_dir = "{}/wheel-{}.dist-info".format(
self._wheel_pkg_dir,
current_wheel_version,
)
Expand Down Expand Up @@ -135,7 +135,7 @@ def test_patches(self):

# This test verifies that the patches are applied to the wheel.
r = runfiles.Create()
metadata_path = "{}/site-packages/requests-{}.dist-info/METADATA".format(
metadata_path = "{}/requests-{}.dist-info/METADATA".format(
self._requests_pkg_dir,
current_wheel_version,
)
Expand Down
12 changes: 6 additions & 6 deletions examples/pip_parse/pip_parse_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ def test_dist_info(self):
self.assertListEqual(
actual,
[
"site-packages/requests-2.25.1.dist-info/INSTALLER",
"site-packages/requests-2.25.1.dist-info/LICENSE",
"site-packages/requests-2.25.1.dist-info/METADATA",
"site-packages/requests-2.25.1.dist-info/RECORD",
"site-packages/requests-2.25.1.dist-info/WHEEL",
"site-packages/requests-2.25.1.dist-info/top_level.txt",
"requests-2.25.1.dist-info/INSTALLER",
"requests-2.25.1.dist-info/LICENSE",
"requests-2.25.1.dist-info/METADATA",
"requests-2.25.1.dist-info/RECORD",
"requests-2.25.1.dist-info/WHEEL",
"requests-2.25.1.dist-info/top_level.txt",
],
)

Expand Down
14 changes: 10 additions & 4 deletions python/pip_install/private/generate_whl_library_build_bazel.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ package(default_visibility = ["//visibility:public"])
filegroup(
name = "{dist_info_label}",
srcs = glob(["site-packages/*.dist-info/**"], allow_empty = True),
srcs = glob(["*.dist-info/**"], allow_empty = True),
)
filegroup(
Expand All @@ -72,19 +72,19 @@ filegroup(
py_library(
name = "{py_library_impl_label}",
srcs = glob(
["site-packages/**/*.py"],
["**/*.py"],
exclude={srcs_exclude},
# Empty sources are allowed to support wheels that don't have any
# pure-Python code, e.g. pymssql, which is written in Cython.
allow_empty = True,
),
data = {data} + glob(
["site-packages/**/*"],
["**/*"],
exclude={data_exclude},
),
# This makes this directory a top-level in the python import
# search path for anything that depends on this.
imports = ["site-packages"],
imports = ["."],
deps = {dependencies},
tags = {tags},
visibility = {impl_vis},
Expand Down Expand Up @@ -299,6 +299,12 @@ def generate_whl_library_build_bazel(
# of generated files produced when wheels are installed. The file is ignored to avoid
# Bazel caching issues.
"**/*.dist-info/RECORD",
"*.whl",
"**/__pycache__/**",
"bin/**/*",
"BUILD.bazel",
"WORKSPACE",
"{}*.py".format(WHEEL_ENTRY_POINT_PREFIX),
]
for item in data_exclude:
if item not in _data_exclude:
Expand Down
4 changes: 2 additions & 2 deletions python/pip_install/tools/wheel_installer/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,8 +600,8 @@ def dependencies(

def unzip(self, directory: str) -> None:
installation_schemes = {
"purelib": "/site-packages",
"platlib": "/site-packages",
"purelib": "/",
"platlib": "/",
"headers": "/include",
"scripts": "/bin",
"data": "/data",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_parses_requirement_for_extra(self) -> None:
class TestWhlFilegroup(unittest.TestCase):
def setUp(self) -> None:
self.wheel_name = "example_minimal_package-0.0.1-py3-none-any.whl"
self.wheel_dir = tempfile.mkdtemp()
self.wheel_dir = tempfile.mkdtemp(prefix=os.environ.get("TEST_TMPDIR"))
self.wheel_path = os.path.join(self.wheel_dir, self.wheel_name)
shutil.copy(os.path.join("examples", "wheel", self.wheel_name), self.wheel_dir)

Expand All @@ -75,9 +75,10 @@ def test_wheel_exists(self) -> None:
)

want_files = [
"metadata.json",
"site-packages",
self.wheel_name,
'example_minimal_package-0.0.1.dist-info',
"examples",
"metadata.json",
]
self.assertEqual(
sorted(want_files),
Expand Down
50 changes: 25 additions & 25 deletions tests/pip_install/whl_library/generate_build_bazel_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ package(default_visibility = ["//visibility:public"])
filegroup(
name = "dist_info",
srcs = glob(["site-packages/*.dist-info/**"], allow_empty = True),
srcs = glob(["*.dist-info/**"], allow_empty = True),
)
filegroup(
Expand All @@ -49,19 +49,19 @@ filegroup(
py_library(
name = "_pkg",
srcs = glob(
["site-packages/**/*.py"],
["**/*.py"],
exclude=[],
# Empty sources are allowed to support wheels that don't have any
# pure-Python code, e.g. pymssql, which is written in Cython.
allow_empty = True,
),
data = [] + glob(
["site-packages/**/*"],
exclude=["**/* *", "**/*.py", "**/*.pyc", "**/*.pyc.*", "**/*.dist-info/RECORD"],
["**/*"],
exclude=["**/* *", "**/*.py", "**/*.pyc", "**/*.pyc.*", "**/*.dist-info/RECORD", "*.whl", "**/__pycache__/**", "bin/**/*", "BUILD.bazel", "WORKSPACE", "rules_python_wheel_entry_point*.py"],
),
# This makes this directory a top-level in the python import
# search path for anything that depends on this.
imports = ["site-packages"],
imports = ["."],
deps = [
"@pypi_bar_baz//:pkg",
"@pypi_foo//:pkg",
Expand Down Expand Up @@ -104,7 +104,7 @@ package(default_visibility = ["//visibility:public"])
filegroup(
name = "dist_info",
srcs = glob(["site-packages/*.dist-info/**"], allow_empty = True),
srcs = glob(["*.dist-info/**"], allow_empty = True),
)
filegroup(
Expand Down Expand Up @@ -136,19 +136,19 @@ filegroup(
py_library(
name = "_pkg",
srcs = glob(
["site-packages/**/*.py"],
["**/*.py"],
exclude=[],
# Empty sources are allowed to support wheels that don't have any
# pure-Python code, e.g. pymssql, which is written in Cython.
allow_empty = True,
),
data = [] + glob(
["site-packages/**/*"],
exclude=["**/* *", "**/*.py", "**/*.pyc", "**/*.pyc.*", "**/*.dist-info/RECORD"],
["**/*"],
exclude=["**/* *", "**/*.py", "**/*.pyc", "**/*.pyc.*", "**/*.dist-info/RECORD", "*.whl", "**/__pycache__/**", "bin/**/*", "BUILD.bazel", "WORKSPACE", "rules_python_wheel_entry_point*.py"],
),
# This makes this directory a top-level in the python import
# search path for anything that depends on this.
imports = ["site-packages"],
imports = ["."],
deps = [
"@pypi_bar_baz//:pkg",
"@pypi_foo//:pkg",
Expand Down Expand Up @@ -266,7 +266,7 @@ package(default_visibility = ["//visibility:public"])
filegroup(
name = "dist_info",
srcs = glob(["site-packages/*.dist-info/**"], allow_empty = True),
srcs = glob(["*.dist-info/**"], allow_empty = True),
)
filegroup(
Expand All @@ -287,19 +287,19 @@ filegroup(
py_library(
name = "_pkg",
srcs = glob(
["site-packages/**/*.py"],
["**/*.py"],
exclude=["srcs_exclude_all"],
# Empty sources are allowed to support wheels that don't have any
# pure-Python code, e.g. pymssql, which is written in Cython.
allow_empty = True,
),
data = ["file_dest", "exec_dest"] + glob(
["site-packages/**/*"],
exclude=["**/* *", "**/*.py", "**/*.pyc", "**/*.pyc.*", "**/*.dist-info/RECORD", "data_exclude_all"],
["**/*"],
exclude=["**/* *", "**/*.py", "**/*.pyc", "**/*.pyc.*", "**/*.dist-info/RECORD", "*.whl", "**/__pycache__/**", "bin/**/*", "BUILD.bazel", "WORKSPACE", "rules_python_wheel_entry_point*.py", "data_exclude_all"],
),
# This makes this directory a top-level in the python import
# search path for anything that depends on this.
imports = ["site-packages"],
imports = ["."],
deps = [
"@pypi_bar_baz//:pkg",
"@pypi_foo//:pkg",
Expand Down Expand Up @@ -364,7 +364,7 @@ package(default_visibility = ["//visibility:public"])
filegroup(
name = "dist_info",
srcs = glob(["site-packages/*.dist-info/**"], allow_empty = True),
srcs = glob(["*.dist-info/**"], allow_empty = True),
)
filegroup(
Expand All @@ -385,19 +385,19 @@ filegroup(
py_library(
name = "_pkg",
srcs = glob(
["site-packages/**/*.py"],
["**/*.py"],
exclude=[],
# Empty sources are allowed to support wheels that don't have any
# pure-Python code, e.g. pymssql, which is written in Cython.
allow_empty = True,
),
data = [] + glob(
["site-packages/**/*"],
exclude=["**/* *", "**/*.py", "**/*.pyc", "**/*.pyc.*", "**/*.dist-info/RECORD"],
["**/*"],
exclude=["**/* *", "**/*.py", "**/*.pyc", "**/*.pyc.*", "**/*.dist-info/RECORD", "*.whl", "**/__pycache__/**", "bin/**/*", "BUILD.bazel", "WORKSPACE", "rules_python_wheel_entry_point*.py"],
),
# This makes this directory a top-level in the python import
# search path for anything that depends on this.
imports = ["site-packages"],
imports = ["."],
deps = [
"@pypi_bar_baz//:pkg",
"@pypi_foo//:pkg",
Expand Down Expand Up @@ -448,7 +448,7 @@ package(default_visibility = ["//visibility:public"])
filegroup(
name = "dist_info",
srcs = glob(["site-packages/*.dist-info/**"], allow_empty = True),
srcs = glob(["*.dist-info/**"], allow_empty = True),
)
filegroup(
Expand All @@ -475,19 +475,19 @@ filegroup(
py_library(
name = "_pkg",
srcs = glob(
["site-packages/**/*.py"],
["**/*.py"],
exclude=[],
# Empty sources are allowed to support wheels that don't have any
# pure-Python code, e.g. pymssql, which is written in Cython.
allow_empty = True,
),
data = [] + glob(
["site-packages/**/*"],
exclude=["**/* *", "**/*.py", "**/*.pyc", "**/*.pyc.*", "**/*.dist-info/RECORD"],
["**/*"],
exclude=["**/* *", "**/*.py", "**/*.pyc", "**/*.pyc.*", "**/*.dist-info/RECORD", "*.whl", "**/__pycache__/**", "bin/**/*", "BUILD.bazel", "WORKSPACE", "rules_python_wheel_entry_point*.py"],
),
# This makes this directory a top-level in the python import
# search path for anything that depends on this.
imports = ["site-packages"],
imports = ["."],
deps = ["@pypi_bar_baz//:pkg"] + select(
{
"@platforms//os:linux": ["@pypi_box//:pkg"],
Expand Down

0 comments on commit 643ea7a

Please sign in to comment.