Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…issuecomment-657167922 and introduce regression test
  • Loading branch information
thundergolfer-two committed Jul 18, 2020
1 parent 6184ffd commit d5f56a0
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 4 deletions.
8 changes: 4 additions & 4 deletions mypy.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@ def _mypy_rule_impl(ctx, is_aspect = False, exe = None, out_path = None):
transitive_srcs_depsets = []
stub_files = []

direct_src_root_paths = sets.to_list(
sets.make([f.root.path for f in direct_src_files]),
)

if hasattr(base_rule.attr, "srcs"):
direct_src_files = _extract_srcs(base_rule.attr.srcs)

Expand Down Expand Up @@ -133,6 +129,10 @@ def _mypy_rule_impl(ctx, is_aspect = False, exe = None, out_path = None):
if not is_aspect:
runfiles = runfiles.merge(ctx.attr._mypy_cli.default_runfiles)

direct_src_root_paths = sets.to_list(
sets.make([f.root.path for f in direct_src_files]),
)

ctx.actions.expand_template(
template = ctx.file._template,
output = exe,
Expand Down
11 changes: 11 additions & 0 deletions test/foo/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
load("@rules_python//python:defs.bzl", "py_library")

py_library(
name = "foo",
srcs = ["bar.py"],
deps = [
"//test/types",
],
srcs_version = "PY3",
visibility = ["//test:__subpackages__"],
)
4 changes: 4 additions & 0 deletions test/foo/bar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from test.types import FooEnumType, SeqOfMaybeInts

blah: SeqOfMaybeInts = [1, None, 2, None, 3, 4, 5]
blurgh: FooEnumType = FooEnumType.BAR
6 changes: 6 additions & 0 deletions test/shell/test_mypy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ test_ok_on_valid_mypy_typings() {
action_should_succeed build --aspects //:mypy.bzl%mypy_aspect --output_groups=mypy //test:correct_mypy_typings
}

# Test for regression originally introduced in https://github.com/thundergolfer/bazel-mypy-integration/pull/16/files
test_ok_for_package_roots_regression() {
action_should_succeed build --aspects //:mypy.bzl%mypy_aspect --output_groups=mypy //test/foo:foo
}

test_fails_on_broken_mypy_typings() {
action_should_fail build --aspects //:mypy.bzl%mypy_aspect --output_groups=mypy //test:broken_mypy_typings
}
Expand All @@ -25,6 +30,7 @@ test_fails_on_empty_mypy_test() {
}

$runner test_ok_on_valid_mypy_typings
$runner test_ok_for_package_roots_regression
$runner test_fails_on_broken_mypy_typings
$runner test_ok_on_valid_mypy_test
$runner test_fails_on_broken_mypy_test
Expand Down
9 changes: 9 additions & 0 deletions test/types/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
load("@rules_python//python:defs.bzl", "py_library")

py_library(
name = "types",
srcs = ["__init__.py"],
deps = [],
srcs_version = "PY3",
visibility = ["//test:__subpackages__"],
)
12 changes: 12 additions & 0 deletions test/types/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import enum
from typing import List, Optional


class FooEnumType(enum.IntEnum):
BAR = 1
BAZ = 2
BEE = 3
BOO = 4


SeqOfMaybeInts = List[Optional[int]]

0 comments on commit d5f56a0

Please sign in to comment.