Skip to content

Commit

Permalink
Make suppression tags configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-thm committed Aug 9, 2024
1 parent f2ed9dc commit 2b63a55
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"python.analysis.typeCheckingMode": "basic"
}
12 changes: 8 additions & 4 deletions mypy/private/mypy.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ def _mypy_impl(target, ctx):
if ctx.rule.kind not in ["py_binary", "py_library", "py_test"]:
return []

# disable if a target is tagged "no-mypy"
if "no-mypy" in ctx.rule.attr.tags:
return []
# disable if a target is tagged with at least one suppression tag
for tag in ctx.attr.suppression_tags:
if tag in ctx.rule.attr.tags:
return []

# we need to help mypy map the location of external deps by setting
# MYPYPATH to include the site-packages directories.
Expand Down Expand Up @@ -120,7 +121,7 @@ def _mypy_impl(target, ctx):
OutputGroupInfo(mypy = depset([output_file])),
]

def mypy(mypy_cli = None, mypy_ini = None, types = None, cache = True):
def mypy(mypy_cli = None, mypy_ini = None, types = None, cache = True, suppression_tags = None):
"""
Create a mypy target inferring upstream caches from deps.
Expand All @@ -138,6 +139,8 @@ def mypy(mypy_cli = None, mypy_ini = None, types = None, cache = True):
Use the types extension to create this map for a requirements.in
or requirements.txt file.
cache: (optional, default True) propagate the mypy cache
suppression_tags: (optional, default ["no-mypy"]) tags that suppress running
mypy on a particular target.
Returns:
a mypy aspect.
Expand Down Expand Up @@ -167,6 +170,7 @@ def mypy(mypy_cli = None, mypy_ini = None, types = None, cache = True):
"_types_keys": attr.label_list(default = types.keys()),
"_types_values": attr.label_list(default = types.values()),
"cache": attr.bool(default = cache),
"suppression_tags": attr.string_list(default = suppression_tags or ["no-mypy"]),
} | additional_attrs,
)

Expand Down

0 comments on commit 2b63a55

Please sign in to comment.