@@ -3,15 +3,15 @@ load("@bazel_skylib//lib:versions.bzl", "versions")
3
3
load ("//python:markers.bzl" , "evaluate" , "parse" )
4
4
5
5
# Environment Markers https://peps.python.org/pep-0508/#environment-markers
6
- _PLATFORM_MAPPING = {
7
- "aarch64-apple-darwin" : {"platform_system" : "Darwin" , "platform_tag" : "macosx_11_0_arm64" , "sys_platform" : "darwin" , "os_name" : "posix" },
8
- "aarch64-unknown-linux-gnu" : {"platform_system" : "Linux" , "platform_tag" : "manylinux_2_17_arm64" , "sys_platform" : "linux" , "os_name" : "posix" },
9
- "x86_64-apple-darwin" : {"platform_system" : "Darwin" , "platform_tag" : "macosx_10_15_x86_64" , "sys_platform" : "darwin" , "os_name" : "posix" },
10
- "x86_64-pc-windows-msvc" : {"platform_system" : "Windows" , "platform_tag" : "win_amd64" , "sys_platform" : "win32" , "os_name" : "nt" },
11
- "x86_64-unknown-linux-gnu" : {"platform_system" : "Linux" , "platform_tag" : "manylinux_2_17_x86_64" , "sys_platform" : "linux" , "os_name" : "posix" },
6
+ _INTERPRETER_MARKERS = {
7
+ "aarch64-apple-darwin" : """ {"platform_system": "Darwin", "platform_tag": [ "macosx_11_0_arm64", "macosx_12_0_arm64"], " sys_platform": "darwin", "os_name": "posix"}""" ,
8
+ "aarch64-unknown-linux-gnu" : """ {"platform_system": "Linux", "platform_tag": "manylinux_2_17_arm64", "sys_platform": "linux", "os_name": "posix"}""" ,
9
+ "x86_64-apple-darwin" : """ {"platform_system": "Darwin", "platform_tag": "macosx_10_15_x86_64", "sys_platform": "darwin", "os_name": "posix"}""" ,
10
+ "x86_64-pc-windows-msvc" : """ {"platform_system": "Windows", "platform_tag": "win_amd64", "sys_platform": "win32", "os_name": "nt"}""" ,
11
+ "x86_64-unknown-linux-gnu" : """ {"platform_system": "Linux", "platform_tag": "manylinux_2_17_x86_64", "sys_platform": "linux", "os_name": "posix"}""" ,
12
12
}
13
13
14
- def _derive_tags (interpreter , constraints ):
14
+ def _derive_environment_markers (interpreter , interpreter_markers ):
15
15
tags = {
16
16
"extra" : "*" ,
17
17
"implementation_name" : "cpython" ,
@@ -23,12 +23,12 @@ def _derive_tags(interpreter, constraints):
23
23
tags ["python_version" ] = "3.{}" .format (parts [index + 1 ])
24
24
break
25
25
26
- for fr , to in _PLATFORM_MAPPING .items ():
26
+ for fr , to in interpreter_markers .items ():
27
27
if fr in interpreter :
28
- tags .update (** to )
29
- break
28
+ tags .update (** json . decode ( to ) )
29
+ return fr , tags
30
30
31
- return tags
31
+ return None , tags
32
32
33
33
def _include_dep (dep , markers , environment ):
34
34
if not markers :
@@ -67,30 +67,30 @@ def _package_impl(ctx):
67
67
68
68
toolchain = ctx .toolchains ["@bazel_tools//tools/python:toolchain_type" ]
69
69
runtime_info = toolchain .py3_runtime
70
- target_platforms_constraints = {}
71
- for constraint in ctx .attr .constraints :
72
- constraint_info = constraint [platform_common .ConstraintValueInfo ]
73
- if ctx .target_platform_has_constraint (constraint_info ) and constraint .label .workspace_name == "platforms" :
74
- target_platforms_constraints [constraint .label .package ] = constraint .label .name
75
-
76
- tags = _derive_tags (runtime_info .interpreter .path , target_platforms_constraints )
70
+ runtime_tag , tags = _derive_environment_markers (runtime_info .interpreter .path , ctx .attr .interpreter_markers )
77
71
python_version = tags ["python_version" ]
78
72
platform_tag = tags ["platform_tag" ]
79
73
80
- output = ctx .actions .declare_directory ("{}/{}/{}" .format (python_version , platform_tag , ctx .label .name ))
74
+ output = ctx .actions .declare_directory ("{}/{}/{}" .format (python_version , runtime_tag , ctx .label .name ))
81
75
arguments = [
82
76
ctx .attr .name ,
83
77
ctx .attr .version ,
84
78
"--python-version" ,
85
79
python_version ,
86
- "--platform" ,
87
- platform_tag ,
88
80
"--output" ,
89
81
output .path ,
90
82
"--files" ,
91
83
json .encode (ctx .attr .files ),
92
84
]
93
85
86
+ if type (platform_tag ) == "string" :
87
+ arguments += ["--platform" , platform_tag ]
88
+ elif type (platform_tag ) == "list" :
89
+ for platform in tags ["platform_tag" ]:
90
+ arguments += ["--platform" , platform ]
91
+ else :
92
+ fail ("platform_tag must be either a string o a list of strings" )
93
+
94
94
if ctx .attr .source_url :
95
95
arguments += [
96
96
"--source-url" ,
@@ -100,7 +100,7 @@ def _package_impl(ctx):
100
100
ctx .actions .run (
101
101
outputs = [output ],
102
102
mnemonic = "InstallWheel" ,
103
- progress_message = "Installing Python package {} for Python {} {}" .format (ctx .label .name , python_version , platform_tag ),
103
+ progress_message = "Installing Python package {} for Python {} {}" .format (ctx .label .name , python_version , runtime_tag ),
104
104
arguments = arguments ,
105
105
use_default_shell_env = True ,
106
106
executable = ctx .executable ._poetry_deps ,
@@ -126,14 +126,11 @@ package = rule(
126
126
"files" : attr .string_dict (doc = "The package resolved files" ),
127
127
"markers" : attr .string (doc = "The JSON string with a dictionary of dependency markers accordingly to PEP 508" ),
128
128
"source_url" : attr .string (doc = "The source file URL" ),
129
- "constraints" : attr .label_list (
130
- default = [
131
- "@platforms//os:macos" ,
132
- "@platforms//os:linux" ,
133
- "@platforms//os:windows" ,
134
- "@platforms//cpu:x86_64" ,
135
- "@platforms//cpu:aarch64" ,
136
- ],
129
+ "interpreter_markers" : attr .string_dict (
130
+ default = _INTERPRETER_MARKERS ,
131
+ doc = "The mapping of an interpter substring mapping to environment markers as a JSON string. " +
132
+ "Default value corresponds to platforms defined at " +
133
+ "https://github.com/bazelbuild/rules_python/blob/23cf6b66/python/versions.bzl#L231-L277" ,
137
134
),
138
135
"_poetry_deps" : attr .label (default = ":poetry_deps" , cfg = "exec" , executable = True ),
139
136
},
0 commit comments