diff --git a/news/4602.fixed.md b/news/4602.fixed.md new file mode 100644 index 0000000000..a67d66d759 --- /dev/null +++ b/news/4602.fixed.md @@ -0,0 +1,3 @@ +(pypi) Wheel entry points are now found on case-sensitive filesystems when the +`METADATA` name's case differs from its `.dist-info` directory +([#4602](https://github.com/bazel-contrib/rules_python/issues/4602)). diff --git a/python/private/pypi/patch_and_extract_whl.bzl b/python/private/pypi/patch_and_extract_whl.bzl index 0c73568806..ca76888ab3 100644 --- a/python/private/pypi/patch_and_extract_whl.bzl +++ b/python/private/pypi/patch_and_extract_whl.bzl @@ -7,14 +7,14 @@ load(":patch_whl.bzl", "get_whl_patches", "patch_whl") load(":pep508_requirement.bzl", "requirement") load(":pypi_repo_utils.bzl", "pypi_repo_utils") load(":whl_extract.bzl", "whl_extract") -load(":whl_metadata.bzl", "parse_entry_points", "whl_metadata") - -def _get_entry_points(rctx, install_dir_path, metadata): - dist_info_dir = "{}-{}.dist-info".format( - metadata.name.replace("-", "_"), - metadata.version.replace("-", "_"), - ) - entry_points_txt = install_dir_path.get_child(dist_info_dir).get_child("entry_points.txt") +load(":whl_metadata.bzl", "find_whl_metadata", "parse_entry_points", "whl_metadata") + +def _get_entry_points(rctx, install_dir_path, logger): + # Use the .dist-info directory that holds METADATA instead of building its + # name from the METADATA Name, whose case can differ from the directory + # (e.g. `Name: Pygments` in `pygments-2.21.0.dist-info`). + metadata_file = find_whl_metadata(install_dir = install_dir_path, logger = logger) + entry_points_txt = metadata_file.dirname.get_child("entry_points.txt") if entry_points_txt.exists: return parse_entry_points(rctx.read(entry_points_txt)) return {} @@ -120,7 +120,7 @@ def patch_and_extract_whl(rctx, *, whl_path, logger, sdist_filename = None, whl_ })) namespace_package_files = pypi_repo_utils.find_namespace_package_files(rctx, install_dir_path) - entry_points = _get_entry_points(rctx, install_dir_path, metadata) + entry_points = _get_entry_points(rctx, install_dir_path, logger) _move_scripts_needing_shebang_rewrite(rctx, entry_points) build_file_contents = generate_whl_library_build_bazel( diff --git a/tests/repos/whl_with_data2/whl_with_data2-1.0.dist-info/METADATA b/tests/repos/whl_with_data2/whl_with_data2-1.0.dist-info/METADATA index c762d184fb..fe883be802 100644 --- a/tests/repos/whl_with_data2/whl_with_data2-1.0.dist-info/METADATA +++ b/tests/repos/whl_with_data2/whl_with_data2-1.0.dist-info/METADATA @@ -1,3 +1,3 @@ Metadata-Version: 2.1 -Name: whl-with-data2 +Name: Whl.With-Data2 Version: 1.0 diff --git a/tests/venv_site_packages_libs/whl_scripts_runnable_test.py b/tests/venv_site_packages_libs/whl_scripts_runnable_test.py index a0c4210f71..28a48dbb1b 100644 --- a/tests/venv_site_packages_libs/whl_scripts_runnable_test.py +++ b/tests/venv_site_packages_libs/whl_scripts_runnable_test.py @@ -47,6 +47,10 @@ def test_script_is_runnable(self): self.assertEqual(script_executable, sys.executable) def test_entry_point_is_runnable(self): + # whl_with_data2's METADATA Name (Whl.With-Data2) differs from its + # .dist-info directory name (whl_with_data2) in case and punctuation, + # so this also covers finding entry_points.txt on case-sensitive + # filesystems. script_path = self._get_script_path("whl_with_data2_bin") self.assertTrue(script_path.exists(), f"Entry point not found at {script_path}")