Skip to content

Commit

Permalink
Add support for pyi_srcs / direct_pyi_files
Browse files Browse the repository at this point in the history
  • Loading branch information
Synss committed Feb 13, 2025
1 parent 66b238f commit 7cd9123
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions mypy/private/mypy.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,12 @@ def _mypy_impl(target, ctx):
for import_ in _extract_imports(target):
imports_dirs[import_] = 1

pyi_files = []
pyi_dirs = {}
for dep in (ctx.rule.attr.deps + additional_types):
if RulesPythonPyInfo in dep and hasattr(dep[RulesPythonPyInfo], "direct_pyi_files"):
pyi_files.extend(dep[RulesPythonPyInfo].direct_pyi_files.to_list())
pyi_dirs |= {"%s/%s" % (ctx.bin_dir.path, imp): None for imp in _extract_imports(dep) if imp != "site-packages" and imp != "_main"}
depsets.append(dep.default_runfiles.files)

if PyTypeLibraryInfo in dep:
Expand Down Expand Up @@ -140,7 +145,7 @@ def _mypy_impl(target, ctx):

# types need to appear first in the mypy path since the module directories
# are the same and mypy resolves the first ones, first.
mypy_path = ":".join(sorted(types) + sorted(external_deps) + sorted(imports_dirs) + sorted(generated_dirs) + sorted(generated_imports_dirs))
mypy_path = ":".join(sorted(types) + sorted(pyi_dirs) + sorted(external_deps) + sorted(imports_dirs) + sorted(generated_dirs) + sorted(generated_imports_dirs))

output_file = ctx.actions.declare_file(ctx.rule.attr.name + ".mypy_stdout")

Expand Down Expand Up @@ -182,7 +187,7 @@ def _mypy_impl(target, ctx):
mnemonic = "mypy",
progress_message = "mypy %{label}",
inputs = depset(
direct = ctx.rule.files.srcs + py_type_files + upstream_caches + config_files,
direct = ctx.rule.files.srcs + py_type_files + pyi_files + upstream_caches + config_files,
transitive = depsets,
),
outputs = outputs,
Expand Down

0 comments on commit 7cd9123

Please sign in to comment.