forked from pantsbuild/pants
-
Notifications
You must be signed in to change notification settings - Fork 0
/
subsystem.py
74 lines (64 loc) · 2.61 KB
/
subsystem.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# Copyright 2019 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).
from typing import Optional, Tuple, cast
from pants.backend.python.subsystems.python_tool_base import PythonToolBase
from pants.engine.addresses import UnparsedAddressInputs
from pants.option.custom_types import file_option, shell_str, target_option
class MyPy(PythonToolBase):
"""The MyPy Python type checker (http://mypy-lang.org/)."""
options_scope = "mypy"
default_version = "mypy==0.782"
default_entry_point = "mypy"
# See `mypy/rules.py`. We only use these default constraints in some situations. Technically,
# MyPy only requires 3.5+, but some popular plugins like `django-stubs` require 3.6+. Because
# 3.5 is EOL, and users can tweak this back, this seems like a more sensible default.
register_interpreter_constraints = True
default_interpreter_constraints = ["CPython>=3.6"]
@classmethod
def register_options(cls, register):
super().register_options(register)
register(
"--skip",
type=bool,
default=False,
help=f"Don't use MyPy when running `{register.bootstrap.pants_bin_name} lint`.",
)
register(
"--args",
type=list,
member_type=shell_str,
help=(
"Arguments to pass directly to mypy, e.g. "
f'`--{cls.options_scope}-args="--python-version 3.7 --disallow-any-expr"`'
),
)
register(
"--config",
type=file_option,
advanced=True,
help="Path to `mypy.ini` or alternative MyPy config file",
)
register(
"--source-plugins",
type=list,
member_type=target_option,
advanced=True,
help=(
"An optional list of `mypy_source_plugin` target addresses. This allows you to "
"load custom plugins defined in source code. Run the goal `target-types "
"--details=mypy_source_plugin` for instructions, including how to load "
"third-party plugins."
),
)
@property
def skip(self) -> bool:
return cast(bool, self.options.skip)
@property
def args(self) -> Tuple[str, ...]:
return tuple(self.options.args)
@property
def config(self) -> Optional[str]:
return cast(Optional[str], self.options.config)
@property
def source_plugins(self) -> UnparsedAddressInputs:
return UnparsedAddressInputs(self.options.source_plugins, owning_address=None)