1
+ load ("@bazel_skylib//rules:common_settings.bzl" , "BuildSettingInfo" )
1
2
load ("//python/private:toolchain_types.bzl" , "TARGET_TOOLCHAIN_TYPE" )
2
3
load (":pep508_evaluate.bzl" , "evaluate" )
3
4
5
+ def depspec_flag (** kwargs ):
6
+ pypa_dependency_specification (
7
+ # todo: copied from pep508_env.bzl
8
+ os_name = select ({
9
+ # The "java" value is documented, but with Jython defunct,
10
+ # shouldn't occur in practice.
11
+ # The osname value is technically a property of the runtime, not the
12
+ # targetted OS at runtime, but the distinction shouldn't matter in
13
+ # practice.
14
+ "@platforms//os:windows" : "nt" ,
15
+ "//conditions:default" : "posix" ,
16
+ }),
17
+ # todo: copied from pep508_env.bzl
18
+ sys_platform = select ({
19
+ "@platforms//os:windows" : "win32" ,
20
+ "@platforms//os:linux" : "linux" ,
21
+ "@platforms//os:osx" : "darwin" ,
22
+ # todo: what does spec say unknown value is?
23
+ "//conditions:default" : "" ,
24
+ }),
25
+ # todo: copied from pep508_env.bzl
26
+ # todo: pep508_env and evaluate have an "aliases" thing that needs
27
+ # to be incorporated
28
+ # todo: there are many more cpus. Unfortunately, it doesn't look like
29
+ # the value is directly accessible to starlark. It might be possible to
30
+ # get it via CcToolchain.cpu though.
31
+ platform_machine = select ({
32
+ "@platforms//cpu:x86_64" : "x86_64" ,
33
+ "@platforms//cpu:aarch64" : "aarch64" ,
34
+ # todo: what does spec say unknown value is?
35
+ "//conditions:default" : "" ,
36
+ }),
37
+ # todo: copied from pep508_env.bzl
38
+ platform_system = select ({
39
+ "@platforms//os:windows" : "Windows" ,
40
+ "@platforms//os:linux" : "Linux" ,
41
+ "@platforms//os:osx" : "Darwin" ,
42
+ # todo: what does spec say unknown value is?
43
+ "//conditions:default" : "" ,
44
+ }),
45
+ ** kwargs
46
+ )
47
+
4
48
# todo: maybe put all the env into a single target and have a
5
49
# PyPiEnvMarkersInfo provider? Have --pypi_env=//some:target?
6
50
def _impl (ctx ):
@@ -15,8 +59,8 @@ def _impl(ctx):
15
59
env ["python_full_version" ] = full_version
16
60
env ["implementation_version" ] = full_version
17
61
else :
18
- env ["python_version" ] = get_flag (ctx .attr ._python_version )
19
- full_version = get_flag (ctx .attr ._python_full_version )
62
+ env ["python_version" ] = _get_flag (ctx .attr ._python_version )
63
+ full_version = _get_flag (ctx .attr ._python_full_version )
20
64
env ["python_full_version" ] = full_version
21
65
env ["implementation_version" ] = full_version
22
66
@@ -40,76 +84,16 @@ def _impl(ctx):
40
84
env ["platform_system" ] = ctx .attr .platform_system
41
85
env ["platform_version" ] = ctx .attr ._platform_version_config_flag [BuildSettingInfo ].value
42
86
43
- if evalute (ctx .attr .expression , env ):
87
+ if evaluate (ctx .attr .expression , env ):
44
88
value = "yes"
45
89
else :
46
90
value = "no"
47
91
return [config_common .FeatureFlagInfo (value = value )]
48
92
49
- # Adapted from spec code at:
50
- # https://packaging.python.org/en/latest/specifications/dependency-specifiers/#environment-markers
51
- def format_full_info (info ):
52
- kind = info .releaselevel
53
- if kind == "final" :
54
- kind = ""
55
- serial = ""
56
- else :
57
- kind = kind [0 ] if kind else ""
58
- serial = str (info .serial ) if info .serial else ""
59
-
60
- return "{v.major}.{v.minor}.{v.micro}{kind}{serial}" .format (
61
- v = version_info ,
62
- kind = kind ,
63
- serial = serial ,
64
- )
65
- return version
66
-
67
- def pypa_dep_spec (** kwargs ):
68
- pypa_dependency_specification (
69
- # todo: copied from pep508_env.bzl
70
- os_name = select ({
71
- # The "java" value is documented, but with Jython defunct,
72
- # shouldn't occur in practice.
73
- # The osname value is technically a property of the runtime, not the
74
- # targetted OS at runtime, but the distinction shouldn't matter in
75
- # practice.
76
- "@//platforms/os:windows" : "nt" ,
77
- "//conditions:default" : "posix" ,
78
- }),
79
- # todo: copied from pep508_env.bzl
80
- sys_platform = select ({
81
- "@//platforms/os:windows" : "win32" ,
82
- "@//platforms/os:linux" : "linux" ,
83
- "@//platforms/os:osx" : "darwin" ,
84
- # todo: what does spec say unknown value is?
85
- "//conditions:default" : "" ,
86
- }),
87
- # todo: copied from pep508_env.bzl
88
- # todo: pep508_env and evaluate have an "aliases" thing that needs
89
- # to be incorporated
90
- # todo: there are many more cpus. Unfortunately, it doesn't look like
91
- # the value is directly accessible to starlark. It might be possible to
92
- # get it via CcToolchain.cpu though.
93
- platform_machine = select ({
94
- "@platforms//cpu:x86_64" : "x86_64" ,
95
- "@platforms//cpu:aarch64" : "aarch64" ,
96
- # todo: what does spec say unknown value is?
97
- "//conditions:default" : "" ,
98
- }),
99
- # todo: copied from pep508_env.bzl
100
- platform_system = select ({
101
- "@//platforms/os:windows" : "Windows" ,
102
- "@//platforms/os:linux" : "Linux" ,
103
- "@//platforms/os:osx" : "Darwin" ,
104
- # todo: what does spec say unknown value is?
105
- "//conditions:default" : "" ,
106
- }),
107
- )
108
-
109
93
pypa_dependency_specification = rule (
110
94
implementation = _impl ,
111
95
attrs = {
112
- "expression" : attt .string (),
96
+ "expression" : attr .string (),
113
97
"os_name" : attr .string (),
114
98
"sys_platform" : attr .string (),
115
99
"platform_machine" : attr .string (),
@@ -121,7 +105,7 @@ pypa_dependency_specification = rule(
121
105
default = "//python/config_settings:pip_platform_version_config" ,
122
106
),
123
107
"_python_version_flag" : attr .label (
124
- default = "//python/config_settings:_python_version_major_minor " ,
108
+ default = "//python/config_settings:python_version_major_minor " ,
125
109
),
126
110
"_python_full_version_flag" : attr .label (
127
111
default = "//python/config_settings:python_version" ,
@@ -133,6 +117,23 @@ pypa_dependency_specification = rule(
133
117
],
134
118
)
135
119
120
+ # Adapted from spec code at:
121
+ # https://packaging.python.org/en/latest/specifications/dependency-specifiers/#environment-markers
122
+ def format_full_version (info ):
123
+ kind = info .releaselevel
124
+ if kind == "final" :
125
+ kind = ""
126
+ serial = ""
127
+ else :
128
+ kind = kind [0 ] if kind else ""
129
+ serial = str (info .serial ) if info .serial else ""
130
+
131
+ return "{v.major}.{v.minor}.{v.micro}{kind}{serial}" .format (
132
+ v = info ,
133
+ kind = kind ,
134
+ serial = serial ,
135
+ )
136
+
136
137
def _get_flag (t ):
137
138
if config_common .FeatureFlagInfo in t :
138
139
return t [config_common .FeatureFlagInfo ].value
0 commit comments