Skip to content

Commit 8151b8b

Browse files
committed
Add extras to {whl,pypi}_repo_name
1 parent a4a91b9 commit 8151b8b

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

python/private/pypi/whl_repo_name.bzl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
1818
load("//python/private:normalize_name.bzl", "normalize_name")
1919
load(":parse_whl_name.bzl", "parse_whl_name")
2020

21-
def whl_repo_name(filename, sha256):
21+
def whl_repo_name(filename, sha256, extras=[]):
2222
"""Return a valid whl_library repo name given a distribution filename.
2323
2424
Args:
2525
filename: {type}`str` the filename of the distribution.
2626
sha256: {type}`str` the sha256 of the distribution.
27+
extras: {type}`list[str]` the extras for the requirement.
28+
TODO(hartikainen): Note sure if this is the right place for extras.
2729
2830
Returns:
2931
a string that can be used in {obj}`whl_library`.
@@ -34,6 +36,7 @@ def whl_repo_name(filename, sha256):
3436
# Then the filename is basically foo-3.2.1.<ext>
3537
name, _, tail = filename.rpartition("-")
3638
parts.append(normalize_name(name))
39+
parts.extend(sorted([e for e in extras if e]))
3740
if sha256:
3841
parts.append("sdist")
3942
version = ""
@@ -53,6 +56,7 @@ def whl_repo_name(filename, sha256):
5356
parts.append(python_tag)
5457
parts.append(abi_tag)
5558
parts.append(platform_tag)
59+
parts.extend(sorted(extras))
5660

5761
if sha256:
5862
parts.append(sha256[:8])
@@ -61,17 +65,21 @@ def whl_repo_name(filename, sha256):
6165

6266
return "_".join(parts)
6367

64-
def pypi_repo_name(whl_name, target_platforms=[]):
68+
def pypi_repo_name(whl_name, target_platforms=[], extras=[]):
6569
"""Return a valid whl_library given a requirement line.
6670
6771
Args:
6872
whl_name: {type}`str` the whl_name to use.
6973
target_platforms: {type}`list[str]` the target platforms to use in the name.
74+
extras: {type}`list[str]` the extras for the requirement.
75+
TODO(hartikainen): Note sure if this is the right place for extras.
76+
7077
7178
Returns:
7279
{type}`str` that can be used in {obj}`whl_library`.
7380
"""
7481
parts = [normalize_name(whl_name)]
82+
parts.extend(sorted([e for e in extras if e]))
7583
parts.extend([p.partition("_")[-1] for p in target_platforms])
7684

7785
return "_".join(parts)

0 commit comments

Comments
 (0)