forked from pantsbuild/pants
-
Notifications
You must be signed in to change notification settings - Fork 0
/
subsystem.py
76 lines (58 loc) · 2.7 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
75
76
# Copyright 2020 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).
from pants.backend.python.goals import lockfile
from pants.backend.python.goals.export import ExportPythonTool, ExportPythonToolSentinel
from pants.backend.python.goals.lockfile import (
GeneratePythonLockfile,
GeneratePythonToolLockfileSentinel,
)
from pants.backend.python.subsystems.python_tool_base import ExportToolOption, PythonToolBase
from pants.backend.python.subsystems.setup import PythonSetup
from pants.backend.python.target_types import ConsoleScript
from pants.core.goals.generate_lockfiles import GenerateToolLockfileSentinel
from pants.engine.rules import collect_rules, rule
from pants.engine.unions import UnionRule
from pants.option.option_types import ArgsListOption, SkipOption
from pants.util.docutil import git_url
class Docformatter(PythonToolBase):
options_scope = "docformatter"
name = "docformatter"
help = "The Python docformatter tool (https://github.com/myint/docformatter)."
default_version = "docformatter>=1.4,<1.5"
default_main = ConsoleScript("docformatter")
register_interpreter_constraints = True
default_interpreter_constraints = ["CPython>=3.7,<4"]
register_lockfile = True
default_lockfile_resource = ("pants.backend.python.lint.docformatter", "docformatter.lock")
default_lockfile_path = "src/python/pants/backend/python/lint/docformatter/docformatter.lock"
default_lockfile_url = git_url(default_lockfile_path)
skip = SkipOption("fmt", "lint")
args = ArgsListOption(example="--wrap-summaries=100 --pre-summary-newline")
export = ExportToolOption()
class DocformatterLockfileSentinel(GeneratePythonToolLockfileSentinel):
resolve_name = Docformatter.options_scope
@rule
def setup_lockfile_request(
_: DocformatterLockfileSentinel, docformatter: Docformatter, python_setup: PythonSetup
) -> GeneratePythonLockfile:
return GeneratePythonLockfile.from_tool(
docformatter, use_pex=python_setup.generate_lockfiles_with_pex
)
class DocformatterExportSentinel(ExportPythonToolSentinel):
pass
@rule
def docformatter_export(
_: DocformatterExportSentinel, docformatter: Docformatter
) -> ExportPythonTool:
if not docformatter.export:
return ExportPythonTool(resolve_name=docformatter.options_scope, pex_request=None)
return ExportPythonTool(
resolve_name=docformatter.options_scope, pex_request=docformatter.to_pex_request()
)
def rules():
return (
*collect_rules(),
*lockfile.rules(),
UnionRule(GenerateToolLockfileSentinel, DocformatterLockfileSentinel),
UnionRule(ExportPythonToolSentinel, DocformatterExportSentinel),
)