diff --git a/examples/bzlmod/MODULE.bazel b/examples/bzlmod/MODULE.bazel index ceb0010bd..3392103aa 100644 --- a/examples/bzlmod/MODULE.bazel +++ b/examples/bzlmod/MODULE.bazel @@ -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", ) diff --git a/examples/bzlmod/whl_mods/pip_whl_mods_test.py b/examples/bzlmod/whl_mods/pip_whl_mods_test.py index 3d7d161f1..d63ffed4d 100644 --- a/examples/bzlmod/whl_mods/pip_whl_mods_test.py +++ b/examples/bzlmod/whl_mods/pip_whl_mods_test.py @@ -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, ) @@ -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, ) diff --git a/examples/pip_parse/pip_parse_test.py b/examples/pip_parse/pip_parse_test.py index 79e1a754a..2c4f1e481 100644 --- a/examples/pip_parse/pip_parse_test.py +++ b/examples/pip_parse/pip_parse_test.py @@ -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", ], ) diff --git a/examples/pip_repository_annotations/WORKSPACE b/examples/pip_repository_annotations/WORKSPACE index 854055508..1852a6c66 100644 --- a/examples/pip_repository_annotations/WORKSPACE +++ b/examples/pip_repository_annotations/WORKSPACE @@ -45,7 +45,7 @@ write_file( copy_executables = {"@pip_repository_annotations_example//:data/copy_executable.py": "copied_content/executable.py"}, copy_files = {"@pip_repository_annotations_example//: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"], ), } diff --git a/examples/pip_repository_annotations/pip_repository_annotations_test.py b/examples/pip_repository_annotations/pip_repository_annotations_test.py index e41dd4f0f..1950bde27 100644 --- a/examples/pip_repository_annotations/pip_repository_annotations_test.py +++ b/examples/pip_repository_annotations/pip_repository_annotations_test.py @@ -82,7 +82,7 @@ def test_data_exclude_glob(self): current_wheel_version = "0.38.4" r = runfiles.Create() - dist_info_dir = "pip_repository_annotations_example/external/{}/site-packages/wheel-{}.dist-info".format( + dist_info_dir = "pip_repository_annotations_example/external/{}/wheel-{}.dist-info".format( self.wheel_pkg_dir(), current_wheel_version, ) diff --git a/python/pip_install/private/generate_whl_library_build_bazel.bzl b/python/pip_install/private/generate_whl_library_build_bazel.bzl index 19650d16d..87e514d1d 100644 --- a/python/pip_install/private/generate_whl_library_build_bazel.bzl +++ b/python/pip_install/private/generate_whl_library_build_bazel.bzl @@ -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( @@ -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}, @@ -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: diff --git a/python/pip_install/tools/wheel_installer/wheel.py b/python/pip_install/tools/wheel_installer/wheel.py index 750ebfcf7..b5c991562 100644 --- a/python/pip_install/tools/wheel_installer/wheel.py +++ b/python/pip_install/tools/wheel_installer/wheel.py @@ -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", diff --git a/python/pip_install/tools/wheel_installer/wheel_installer_test.py b/python/pip_install/tools/wheel_installer/wheel_installer_test.py index 74b9c305f..09532a80c 100644 --- a/python/pip_install/tools/wheel_installer/wheel_installer_test.py +++ b/python/pip_install/tools/wheel_installer/wheel_installer_test.py @@ -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) @@ -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), diff --git a/tests/pip_install/whl_library/generate_build_bazel_tests.bzl b/tests/pip_install/whl_library/generate_build_bazel_tests.bzl index 72423aaec..18ce8a85b 100644 --- a/tests/pip_install/whl_library/generate_build_bazel_tests.bzl +++ b/tests/pip_install/whl_library/generate_build_bazel_tests.bzl @@ -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( @@ -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", @@ -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( @@ -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", @@ -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( @@ -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", @@ -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( @@ -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", @@ -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( @@ -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"],