@@ -5,7 +5,7 @@ Initial source taken from here: https://github.com/bazel-contrib/bazel-mypy-inte
5
5
6
6
load ("@bazel_skylib//lib:sets.bzl" , "sets" )
7
7
load ("@bazel_skylib//lib:shell.bzl" , "shell" )
8
- load ("//rules/mypy:stubs .bzl" , "PyStubsInfo " )
8
+ load ("//rules/venv:venv .bzl" , "PyVenvInfo " )
9
9
10
10
MyPyAspectInfo = provider (
11
11
"TODO: documentation" ,
@@ -23,23 +23,18 @@ MYPY_DEBUG = False
23
23
VALID_EXTENSIONS = ["py" , "pyi" ]
24
24
25
25
DEFAULT_ATTRS = {
26
- "_mypy_cli" : attr .label (
27
- default = Label ("//rules/mypy:__main__" ),
28
- executable = True ,
29
- cfg = "exec" ,
30
- ),
31
26
"_mypy_config" : attr .label (
32
27
default = Label ("//config:mypy_config" ),
33
28
allow_single_file = True ,
34
29
),
35
- "_stubs" : attr .label (
36
- default = Label ("//rules/mypy:stubs" ),
37
- executable = False ,
38
- ),
39
30
"_template" : attr .label (
40
31
default = Label ("//rules/mypy:mypy.bash.tpl" ),
41
32
allow_single_file = True ,
42
33
),
34
+ "_venv" : attr .label (
35
+ default = Label ("//rules/mypy:venv" ),
36
+ executable = False ,
37
+ ),
43
38
}
44
39
45
40
def _sources_to_cache_map_triples (srcs , is_aspect ):
@@ -133,8 +128,8 @@ def _mypy_rule_impl(ctx, is_aspect = False):
133
128
base_rule = ctx .rule
134
129
135
130
mypy_config_file = ctx .file ._mypy_config
136
- mypypath_parts = [ctx .attr ._stubs [PyStubsInfo ].stubs_directory ]
137
131
132
+ mypypath_parts = []
138
133
direct_src_files = []
139
134
140
135
transitive_srcs_depsets = []
@@ -178,10 +173,8 @@ def _mypy_rule_impl(ctx, is_aspect = False):
178
173
# the project version of mypy however, other rules should fall back on their
179
174
# relative runfiles.
180
175
runfiles = ctx .runfiles (
181
- files = src_files + ctx .attr ._stubs [ PyInfo ]. transitive_sources . to_list () + [mypy_config_file ],
176
+ files = src_files + [ ctx .attr ._venv [ PyVenvInfo ]. venv_dir ] + [mypy_config_file ],
182
177
)
183
- if not is_aspect :
184
- runfiles = runfiles .merge (ctx .attr ._mypy_cli .default_runfiles )
185
178
186
179
src_root_paths = sets .to_list (
187
180
sets .make ([f .root .path for f in src_files ]),
@@ -193,14 +186,13 @@ def _mypy_rule_impl(ctx, is_aspect = False):
193
186
substitutions = {
194
187
"{CACHE_MAP_TRIPLES}" : " " .join (_sources_to_cache_map_triples (src_files , is_aspect )),
195
188
"{MYPYPATH_PATH}" : mypypath if mypypath else "" ,
196
- "{MYPY_EXE}" : ctx .executable ._mypy_cli .path ,
197
189
"{MYPY_INI_PATH}" : mypy_config_file .path ,
198
- "{MYPY_ROOT}" : ctx .executable ._mypy_cli .root .path ,
199
190
"{OUTPUT}" : out .path if out else "" ,
200
191
"{PACKAGE_ROOTS}" : " " .join ([
201
192
"--package-root " + shell .quote (path or "." )
202
193
for path in src_root_paths
203
194
]),
195
+ "{PY_INTERPRETER}" : "%s/bin/python3" % ctx .attr ._venv [PyVenvInfo ].venv_dir .path ,
204
196
"{SRCS}" : " " .join ([
205
197
shell .quote (f .path ) if is_aspect else shell .quote (f .short_path )
206
198
for f in src_files
@@ -236,7 +228,7 @@ def _mypy_aspect_impl(_, ctx):
236
228
ctx .actions .run (
237
229
outputs = [aspect_info .out ],
238
230
inputs = info .default_runfiles .files ,
239
- tools = [ctx . executable . _mypy_cli ],
231
+ tools = [],
240
232
executable = aspect_info .exe ,
241
233
mnemonic = "MyPy" ,
242
234
progress_message = "Type-checking %s" % ctx .label ,
0 commit comments