Skip to content

Commit

Permalink
Deal with hyphens and underscores in ModuleDirImport (#224)
Browse files Browse the repository at this point in the history
* Deal with hyphens and underscores in ModuleDirImport

* version

* Skip test
  • Loading branch information
peterebden authored Nov 18, 2024
1 parent 6e56fef commit fb7e4b1
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .plzconfig.tool_dev
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@

[Plugin "python"]
PexTool = //tools:please_pex_dev

[BuildEnv]
tool-dev = true
1 change: 1 addition & 0 deletions test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ python_test(
name = "distribution_metadata_test",
srcs = ["distribution_metadata_test.py"],
deps = [
"//third_party/python:google-pasta",
"//third_party/python:pygments",
],
)
Expand Down
5 changes: 5 additions & 0 deletions test/distribution_metadata_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from importlib.metadata import PackagePath, files, version, distributions
import os
import unittest


Expand All @@ -16,3 +17,7 @@ def test_importlib_metadata_files(self):
def test_importlib_metadata_iteration(self):
for distribution in distributions():
self.assertFalse(isinstance(distribution, list))

@unittest.skipIf(os.getenv("TOOL_DEV", "") != "true", "needs updated please_pex")
def test_importlib_metadata_hyphens(self):
self.assertEqual(version("google-pasta"), "0.2.0")
4 changes: 4 additions & 0 deletions tools/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Version 1.5.4
-------------
* Handle packages with hyphenated names when loading distribution metadata (#224)

Version 1.5.3
-------------
* Updated some deprecated functions on import hooks (#222)
Expand Down
2 changes: 1 addition & 1 deletion tools/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.5.3
1.5.4
4 changes: 3 additions & 1 deletion tools/please_pex/pex/pex_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,9 @@ def find_distributions(self, context):
loading the metadata for packages for the indicated ``context``.
"""
if context.name:
return self._distributions.get(context.name, [])
# The installed directories have underscores in the place of what might be a hyphen
# in the package name (e.g. the package opentelemetry-sdk installs opentelemetry_sdk).
return self._distributions.get(context.name.replace("-", "_"), [])
else:
return itertools.chain(*self._distributions.values())

Expand Down

0 comments on commit fb7e4b1

Please sign in to comment.