@@ -19,12 +19,12 @@ exclude_paths = [
19
19
"aspect_rules_py~/py/tools/" ,
20
20
# these will match in bzlmod setup with --incompatible_use_plus_in_repo_names flag flipped.
21
21
"rules_python++python+" ,
22
- "aspect_rules_py+/py/tools/"
22
+ "aspect_rules_py+/py/tools/" ,
23
23
]
24
24
25
25
# determines if the given file is a `distinfo`, `dep` or a `source`
26
26
# this required to allow PEX to put files into different places.
27
- #
27
+ #
28
28
# --dep: into `<PEX_UNPACK_ROOT>/.deps/<name_of_the_package>`
29
29
# --distinfo: is only used for determining package metadata
30
30
# --source: into `<PEX_UNPACK_ROOT>/<relative_path_to_workspace_root>/<file_name>`
@@ -37,23 +37,24 @@ def _map_srcs(f, workspace):
37
37
return []
38
38
39
39
site_packages_i = f .path .find ("site-packages" )
40
-
40
+
41
41
# if path contains `site-packages` and there is only two path segments
42
42
# after it, it will be treated as third party dep.
43
43
# Here are some examples of path we expect and use and ones we ignore.
44
- #
44
+ #
45
45
# Match: `external/rules_python~~pip~pypi_39_rtoml/site-packages/rtoml-0.11.0.dist-info/INSTALLER`
46
46
# Reason: It has two `/` after first `site-packages` substring.
47
- #
47
+ #
48
48
# No Match: `external/rules_python~~pip~pypi_39_rtoml/site-packages/rtoml-0.11.0/src/mod/parse.py`
49
49
# Reason: It has three `/` after first `site-packages` substring.
50
50
if site_packages_i != - 1 and f .path .count ("/" , site_packages_i ) == 2 :
51
51
if f .path .find ("dist-info" , site_packages_i ) != - 1 :
52
52
return ["--distinfo={}" .format (f .dirname )]
53
53
return ["--dep={}" .format (f .dirname )]
54
54
55
- # If the path does not have a `site-packages` in it, then put it into
56
- # the standard runfiles tree.
55
+ # If the path does not have a `site-packages` in it, then put it into
56
+ # the standard runfiles tree.
57
+
57
58
elif site_packages_i == - 1 :
58
59
return ["--source={}={}" .format (f .path , dest_path )]
59
60
@@ -74,22 +75,22 @@ def _py_python_pex_impl(ctx):
74
75
workspace_name = str (ctx .workspace_name )
75
76
76
77
args .add_all (
77
- ctx .attr .inject_env .items (),
78
+ ctx .attr .inject_env .items (),
78
79
map_each = lambda e : "--inject-env={}={}" .format (e [0 ], e [1 ]),
79
- # this is needed to allow passing a lambda to map_each
80
+ # this is needed to allow passing a lambda to map_each
80
81
allow_closure = True ,
81
82
)
82
83
83
84
args .add_all (
84
- binary [PyInfo ].imports ,
85
- format_each = "--sys-path=%s"
85
+ binary [PyInfo ].imports ,
86
+ format_each = "--sys-path=%s" ,
86
87
)
87
88
88
89
args .add_all (
89
90
runfiles .files ,
90
91
map_each = lambda f : _map_srcs (f , workspace_name ),
91
92
uniquify = True ,
92
- # this is needed to allow passing a lambda (with workspace_name) to map_each
93
+ # this is needed to allow passing a lambda (with workspace_name) to map_each
93
94
allow_closure = True ,
94
95
)
95
96
args .add (binary [DefaultInfo ].files_to_run .executable , format = "--executable=%s" )
@@ -99,10 +100,10 @@ def _py_python_pex_impl(ctx):
99
100
py_version = py_toolchain .interpreter_version_info
100
101
args .add_all (
101
102
[
102
- constraint .format (major = py_version .major , minor = py_version .minor , patch = py_version .micro )
103
+ constraint .format (major = py_version .major , minor = py_version .minor , patch = py_version .micro )
103
104
for constraint in ctx .attr .python_interpreter_constraints
104
- ],
105
- format_each = "--python-version-constraint=%s"
105
+ ],
106
+ format_each = "--python-version-constraint=%s" ,
106
107
)
107
108
args .add (output , format = "--output-file=%s" )
108
109
@@ -116,10 +117,9 @@ def _py_python_pex_impl(ctx):
116
117
)
117
118
118
119
return [
119
- DefaultInfo (files = depset ([output ]), executable = output )
120
+ DefaultInfo (files = depset ([output ]), executable = output ),
120
121
]
121
122
122
-
123
123
_attrs = dict ({
124
124
"binary" : attr .label (executable = True , cfg = "target" , mandatory = True , doc = "A py_binary target" ),
125
125
"inject_env" : attr .string_dict (
@@ -128,7 +128,7 @@ _attrs = dict({
128
128
),
129
129
"python_shebang" : attr .string (default = "#!/usr/bin/env python3" ),
130
130
"python_interpreter_constraints" : attr .string_list (
131
- default = ["CPython=={major}.{minor}.*" ],
131
+ default = ["CPython=={major}.{minor}.*" ],
132
132
doc = """\
133
133
Python interpreter versions this PEX binary is compatible with. A list of semver strings.
134
134
The placeholder strings `{major}`, `{minor}`, `{patch}` can be used for gathering version
@@ -143,17 +143,21 @@ py_pex_binary
143
143
]
144
144
)
145
145
```
146
- """ ),
147
- "_pex" : attr .label (executable = True , cfg = "exec" , default = "//py/tools/pex" )
146
+ """ ,
147
+ ),
148
+ # NB: this is read by _resolve_toolchain in py_semantics.
149
+ "_interpreter_version_flag" : attr .label (
150
+ default = "//py:interpreter_version" ,
151
+ ),
152
+ "_pex" : attr .label (executable = True , cfg = "exec" , default = "//py/tools/pex" ),
148
153
})
149
154
150
-
151
155
py_pex_binary = rule (
152
156
doc = "Build a pex executable from a py_binary" ,
153
157
implementation = _py_python_pex_impl ,
154
158
attrs = _attrs ,
155
159
toolchains = [
156
- PY_TOOLCHAIN
160
+ PY_TOOLCHAIN ,
157
161
],
158
162
executable = True ,
159
- )
163
+ )
0 commit comments