Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions news/4602.fixed.md
Original file line number Diff line number Diff line change
@@ -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)).
18 changes: 9 additions & 9 deletions python/private/pypi/patch_and_extract_whl.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Metadata-Version: 2.1
Name: whl-with-data2
Name: Whl.With-Data2
Version: 1.0
4 changes: 4 additions & 0 deletions tests/venv_site_packages_libs/whl_scripts_runnable_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

Expand Down
Loading