18
18
load ("//python/private:normalize_name.bzl" , "normalize_name" )
19
19
load (":parse_whl_name.bzl" , "parse_whl_name" )
20
20
21
- def whl_repo_name (filename , sha256 ):
21
+ def whl_repo_name (filename , sha256 , extras = [] ):
22
22
"""Return a valid whl_library repo name given a distribution filename.
23
23
24
24
Args:
25
25
filename: {type}`str` the filename of the distribution.
26
26
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.
27
29
28
30
Returns:
29
31
a string that can be used in {obj}`whl_library`.
@@ -34,6 +36,7 @@ def whl_repo_name(filename, sha256):
34
36
# Then the filename is basically foo-3.2.1.<ext>
35
37
name , _ , tail = filename .rpartition ("-" )
36
38
parts .append (normalize_name (name ))
39
+ parts .extend (sorted ([e for e in extras if e ]))
37
40
if sha256 :
38
41
parts .append ("sdist" )
39
42
version = ""
@@ -53,6 +56,7 @@ def whl_repo_name(filename, sha256):
53
56
parts .append (python_tag )
54
57
parts .append (abi_tag )
55
58
parts .append (platform_tag )
59
+ parts .extend (sorted (extras ))
56
60
57
61
if sha256 :
58
62
parts .append (sha256 [:8 ])
@@ -61,17 +65,21 @@ def whl_repo_name(filename, sha256):
61
65
62
66
return "_" .join (parts )
63
67
64
- def pypi_repo_name (whl_name , target_platforms = []):
68
+ def pypi_repo_name (whl_name , target_platforms = [], extras = [] ):
65
69
"""Return a valid whl_library given a requirement line.
66
70
67
71
Args:
68
72
whl_name: {type}`str` the whl_name to use.
69
73
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
+
70
77
71
78
Returns:
72
79
{type}`str` that can be used in {obj}`whl_library`.
73
80
"""
74
81
parts = [normalize_name (whl_name )]
82
+ parts .extend (sorted ([e for e in extras if e ]))
75
83
parts .extend ([p .partition ("_" )[- 1 ] for p in target_platforms ])
76
84
77
85
return "_" .join (parts )
0 commit comments