duty 1.6.0__py3-none-any.whl → 1.6.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- duty/__init__.py +49 -2
- duty/__main__.py +1 -1
- duty/_internal/__init__.py +0 -0
- duty/_internal/callables/__init__.py +34 -0
- duty/{callables → _internal/callables}/_io.py +2 -0
- duty/_internal/callables/autoflake.py +132 -0
- duty/_internal/callables/black.py +176 -0
- duty/_internal/callables/blacken_docs.py +92 -0
- duty/_internal/callables/build.py +76 -0
- duty/_internal/callables/coverage.py +716 -0
- duty/_internal/callables/flake8.py +222 -0
- duty/_internal/callables/git_changelog.py +178 -0
- duty/_internal/callables/griffe.py +227 -0
- duty/_internal/callables/interrogate.py +152 -0
- duty/_internal/callables/isort.py +573 -0
- duty/_internal/callables/mkdocs.py +256 -0
- duty/_internal/callables/mypy.py +496 -0
- duty/_internal/callables/pytest.py +475 -0
- duty/_internal/callables/ruff.py +399 -0
- duty/_internal/callables/safety.py +82 -0
- duty/_internal/callables/ssort.py +38 -0
- duty/_internal/callables/twine.py +284 -0
- duty/_internal/cli.py +322 -0
- duty/_internal/collection.py +246 -0
- duty/_internal/context.py +111 -0
- duty/{debug.py → _internal/debug.py} +13 -15
- duty/_internal/decorator.py +111 -0
- duty/_internal/exceptions.py +12 -0
- duty/_internal/tools/__init__.py +41 -0
- duty/{tools → _internal/tools}/_autoflake.py +8 -4
- duty/{tools → _internal/tools}/_base.py +15 -2
- duty/{tools → _internal/tools}/_black.py +5 -5
- duty/{tools → _internal/tools}/_blacken_docs.py +10 -5
- duty/{tools → _internal/tools}/_build.py +4 -4
- duty/{tools → _internal/tools}/_coverage.py +8 -4
- duty/{tools → _internal/tools}/_flake8.py +10 -12
- duty/{tools → _internal/tools}/_git_changelog.py +8 -4
- duty/{tools → _internal/tools}/_griffe.py +8 -4
- duty/{tools → _internal/tools}/_interrogate.py +4 -4
- duty/{tools → _internal/tools}/_isort.py +8 -6
- duty/{tools → _internal/tools}/_mkdocs.py +8 -4
- duty/{tools → _internal/tools}/_mypy.py +5 -5
- duty/{tools → _internal/tools}/_pytest.py +8 -4
- duty/{tools → _internal/tools}/_ruff.py +11 -5
- duty/{tools → _internal/tools}/_safety.py +13 -8
- duty/{tools → _internal/tools}/_ssort.py +10 -6
- duty/{tools → _internal/tools}/_twine.py +11 -5
- duty/_internal/tools/_yore.py +96 -0
- duty/_internal/validation.py +266 -0
- duty/callables/__init__.py +4 -4
- duty/callables/autoflake.py +11 -126
- duty/callables/black.py +12 -171
- duty/callables/blacken_docs.py +11 -86
- duty/callables/build.py +12 -71
- duty/callables/coverage.py +12 -711
- duty/callables/flake8.py +12 -217
- duty/callables/git_changelog.py +12 -173
- duty/callables/griffe.py +12 -222
- duty/callables/interrogate.py +12 -147
- duty/callables/isort.py +12 -568
- duty/callables/mkdocs.py +12 -251
- duty/callables/mypy.py +11 -490
- duty/callables/pytest.py +12 -470
- duty/callables/ruff.py +12 -394
- duty/callables/safety.py +11 -76
- duty/callables/ssort.py +12 -33
- duty/callables/twine.py +12 -279
- duty/cli.py +10 -316
- duty/collection.py +12 -228
- duty/context.py +12 -107
- duty/decorator.py +12 -108
- duty/exceptions.py +13 -10
- duty/tools.py +63 -0
- duty/validation.py +12 -262
- {duty-1.6.0.dist-info → duty-1.6.2.dist-info}/METADATA +5 -4
- duty-1.6.2.dist-info/RECORD +81 -0
- {duty-1.6.0.dist-info → duty-1.6.2.dist-info}/WHEEL +1 -1
- {duty-1.6.0.dist-info → duty-1.6.2.dist-info}/entry_points.txt +1 -1
- duty/tools/__init__.py +0 -50
- duty/tools/_yore.py +0 -54
- duty-1.6.0.dist-info/RECORD +0 -55
- {duty-1.6.0.dist-info → duty-1.6.2.dist-info}/licenses/LICENSE +0 -0
duty/__init__.py
CHANGED
|
@@ -5,6 +5,53 @@ A simple task runner.
|
|
|
5
5
|
|
|
6
6
|
from __future__ import annotations
|
|
7
7
|
|
|
8
|
-
from
|
|
8
|
+
from failprint import lazy
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
from duty._internal.cli import (
|
|
11
|
+
empty,
|
|
12
|
+
get_duty_parser,
|
|
13
|
+
get_parser,
|
|
14
|
+
main,
|
|
15
|
+
parse_args,
|
|
16
|
+
parse_commands,
|
|
17
|
+
parse_options,
|
|
18
|
+
print_help,
|
|
19
|
+
specified_options,
|
|
20
|
+
split_args,
|
|
21
|
+
)
|
|
22
|
+
from duty._internal.collection import Collection, Duty, DutyListType, default_duties_file
|
|
23
|
+
from duty._internal.context import CmdType, Context
|
|
24
|
+
from duty._internal.decorator import create_duty, duty
|
|
25
|
+
from duty._internal.exceptions import DutyFailure
|
|
26
|
+
from duty._internal.tools._base import LazyStderr, LazyStdout, Tool
|
|
27
|
+
from duty._internal.validation import ParamsCaster, cast_arg, to_bool, validate
|
|
28
|
+
|
|
29
|
+
__all__: list[str] = [
|
|
30
|
+
"CmdType",
|
|
31
|
+
"Collection",
|
|
32
|
+
"Context",
|
|
33
|
+
"Duty",
|
|
34
|
+
"DutyFailure",
|
|
35
|
+
"DutyListType",
|
|
36
|
+
"LazyStderr",
|
|
37
|
+
"LazyStdout",
|
|
38
|
+
"ParamsCaster",
|
|
39
|
+
"Tool",
|
|
40
|
+
"cast_arg",
|
|
41
|
+
"create_duty",
|
|
42
|
+
"default_duties_file",
|
|
43
|
+
"duty",
|
|
44
|
+
"empty",
|
|
45
|
+
"get_duty_parser",
|
|
46
|
+
"get_parser",
|
|
47
|
+
"lazy",
|
|
48
|
+
"main",
|
|
49
|
+
"parse_args",
|
|
50
|
+
"parse_commands",
|
|
51
|
+
"parse_options",
|
|
52
|
+
"print_help",
|
|
53
|
+
"specified_options",
|
|
54
|
+
"split_args",
|
|
55
|
+
"to_bool",
|
|
56
|
+
"validate",
|
|
57
|
+
]
|
duty/__main__.py
CHANGED
|
File without changes
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# YORE: Bump 2: Remove file.
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import warnings
|
|
6
|
+
|
|
7
|
+
from duty._internal.callables import (
|
|
8
|
+
autoflake, # noqa: F401
|
|
9
|
+
black, # noqa: F401
|
|
10
|
+
blacken_docs, # noqa: F401
|
|
11
|
+
build, # noqa: F401
|
|
12
|
+
coverage, # noqa: F401
|
|
13
|
+
flake8, # noqa: F401
|
|
14
|
+
git_changelog, # noqa: F401
|
|
15
|
+
griffe, # noqa: F401
|
|
16
|
+
interrogate, # noqa: F401
|
|
17
|
+
isort, # noqa: F401
|
|
18
|
+
mkdocs, # noqa: F401
|
|
19
|
+
mypy, # noqa: F401
|
|
20
|
+
pytest, # noqa: F401
|
|
21
|
+
ruff, # noqa: F401
|
|
22
|
+
safety, # noqa: F401
|
|
23
|
+
ssort, # noqa: F401
|
|
24
|
+
twine, # noqa: F401
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
warnings.warn(
|
|
28
|
+
"Callables are deprecated in favor of our new `duty.tools`. "
|
|
29
|
+
"They are easier to use and provide more functionality "
|
|
30
|
+
"like automatically computing `command` values in `ctx.run()` calls. "
|
|
31
|
+
"Old callables will be removed in a future version.",
|
|
32
|
+
DeprecationWarning,
|
|
33
|
+
stacklevel=1,
|
|
34
|
+
)
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# YORE: Bump 2: Remove file.
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from failprint import lazy
|
|
6
|
+
|
|
7
|
+
from duty._internal.callables import _io
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@lazy(name="autoflake")
|
|
11
|
+
def run(
|
|
12
|
+
*files: str,
|
|
13
|
+
config: str | None = None,
|
|
14
|
+
check: bool | None = None,
|
|
15
|
+
check_diff: bool | None = None,
|
|
16
|
+
imports: list[str] | None = None,
|
|
17
|
+
remove_all_unused_imports: bool | None = None,
|
|
18
|
+
recursive: bool | None = None,
|
|
19
|
+
jobs: int | None = None,
|
|
20
|
+
exclude: list[str] | None = None,
|
|
21
|
+
expand_star_imports: bool | None = None,
|
|
22
|
+
ignore_init_module_imports: bool | None = None,
|
|
23
|
+
remove_duplicate_keys: bool | None = None,
|
|
24
|
+
remove_unused_variables: bool | None = None,
|
|
25
|
+
remove_rhs_for_unused_variables: bool | None = None,
|
|
26
|
+
ignore_pass_statements: bool | None = None,
|
|
27
|
+
ignore_pass_after_docstring: bool | None = None,
|
|
28
|
+
quiet: bool | None = None,
|
|
29
|
+
verbose: bool | None = None,
|
|
30
|
+
stdin_display_name: str | None = None,
|
|
31
|
+
in_place: bool | None = None,
|
|
32
|
+
stdout: bool | None = None,
|
|
33
|
+
) -> int:
|
|
34
|
+
r"""Run `autoflake`.
|
|
35
|
+
|
|
36
|
+
Parameters:
|
|
37
|
+
*files: Files to format.
|
|
38
|
+
config: Explicitly set the config file instead of auto determining based on file location.
|
|
39
|
+
check: Return error code if changes are needed.
|
|
40
|
+
check_diff: Return error code if changes are needed, also display file diffs.
|
|
41
|
+
imports: By default, only unused standard library imports are removed; specify a comma-separated list of additional modules/packages.
|
|
42
|
+
remove_all_unused_imports: Remove all unused imports (not just those from the standard library).
|
|
43
|
+
recursive: Drill down directories recursively.
|
|
44
|
+
jobs: Number of parallel jobs; match CPU count if value is 0 (default: 0).
|
|
45
|
+
exclude: Exclude file/directory names that match these comma-separated globs.
|
|
46
|
+
expand_star_imports: Expand wildcard star imports with undefined names; this only triggers if there is only one star import in the file; this is skipped if there are any uses of `__all__` or `del` in the file.
|
|
47
|
+
ignore_init_module_imports: Exclude `__init__.py` when removing unused imports.
|
|
48
|
+
remove_duplicate_keys: Remove all duplicate keys in objects.
|
|
49
|
+
remove_unused_variables: Remove unused variables.
|
|
50
|
+
remove_rhs_for_unused_variables: Remove RHS of statements when removing unused variables (unsafe).
|
|
51
|
+
ignore_pass_statements: Ignore all pass statements.
|
|
52
|
+
ignore_pass_after_docstring: Ignore pass statements after a newline ending on `\"\"\"`.
|
|
53
|
+
quiet: Suppress output if there are no issues.
|
|
54
|
+
verbose: Print more verbose logs (you can repeat `-v` to make it more verbose).
|
|
55
|
+
stdin_display_name: The name used when processing input from stdin.
|
|
56
|
+
in_place: Make changes to files instead of printing diffs.
|
|
57
|
+
stdout: Print changed text to stdout. defaults to true when formatting stdin, or to false otherwise.
|
|
58
|
+
"""
|
|
59
|
+
from autoflake import _main as autoflake # noqa: PLC0415
|
|
60
|
+
|
|
61
|
+
cli_args = list(files)
|
|
62
|
+
|
|
63
|
+
if check:
|
|
64
|
+
cli_args.append("--check")
|
|
65
|
+
|
|
66
|
+
if check_diff:
|
|
67
|
+
cli_args.append("--check-diff")
|
|
68
|
+
|
|
69
|
+
if imports:
|
|
70
|
+
cli_args.append("--imports")
|
|
71
|
+
cli_args.append(",".join(imports))
|
|
72
|
+
|
|
73
|
+
if remove_all_unused_imports:
|
|
74
|
+
cli_args.append("--remove-all-unused-imports")
|
|
75
|
+
|
|
76
|
+
if recursive:
|
|
77
|
+
cli_args.append("--recursive")
|
|
78
|
+
|
|
79
|
+
if jobs:
|
|
80
|
+
cli_args.append("--jobs")
|
|
81
|
+
cli_args.append(str(jobs))
|
|
82
|
+
|
|
83
|
+
if exclude:
|
|
84
|
+
cli_args.append("--exclude")
|
|
85
|
+
cli_args.append(",".join(exclude))
|
|
86
|
+
|
|
87
|
+
if expand_star_imports:
|
|
88
|
+
cli_args.append("--expand-star-imports")
|
|
89
|
+
|
|
90
|
+
if ignore_init_module_imports:
|
|
91
|
+
cli_args.append("--ignore-init-module-imports")
|
|
92
|
+
|
|
93
|
+
if remove_duplicate_keys:
|
|
94
|
+
cli_args.append("--remove-duplicate-keys")
|
|
95
|
+
|
|
96
|
+
if remove_unused_variables:
|
|
97
|
+
cli_args.append("--remove-unused-variables")
|
|
98
|
+
|
|
99
|
+
if remove_rhs_for_unused_variables:
|
|
100
|
+
cli_args.append("remove-rhs-for-unused-variables")
|
|
101
|
+
|
|
102
|
+
if ignore_pass_statements:
|
|
103
|
+
cli_args.append("--ignore-pass-statements")
|
|
104
|
+
|
|
105
|
+
if ignore_pass_after_docstring:
|
|
106
|
+
cli_args.append("--ignore-pass-after-docstring")
|
|
107
|
+
|
|
108
|
+
if quiet:
|
|
109
|
+
cli_args.append("--quiet")
|
|
110
|
+
|
|
111
|
+
if verbose:
|
|
112
|
+
cli_args.append("--verbose")
|
|
113
|
+
|
|
114
|
+
if stdin_display_name:
|
|
115
|
+
cli_args.append("--stdin-display-name")
|
|
116
|
+
cli_args.append(stdin_display_name)
|
|
117
|
+
|
|
118
|
+
if config:
|
|
119
|
+
cli_args.append("--config")
|
|
120
|
+
cli_args.append(config)
|
|
121
|
+
|
|
122
|
+
if in_place:
|
|
123
|
+
cli_args.append("--in-place")
|
|
124
|
+
|
|
125
|
+
if stdout:
|
|
126
|
+
cli_args.append("--stdout")
|
|
127
|
+
|
|
128
|
+
return autoflake(
|
|
129
|
+
cli_args,
|
|
130
|
+
standard_out=_io._LazyStdout(),
|
|
131
|
+
standard_error=_io._LazyStderr(),
|
|
132
|
+
)
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# YORE: Bump 2: Remove file.
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from failprint import lazy
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@lazy(name="black")
|
|
9
|
+
def run(
|
|
10
|
+
*src: str,
|
|
11
|
+
config: str | None = None,
|
|
12
|
+
code: str | None = None,
|
|
13
|
+
line_length: int | None = None,
|
|
14
|
+
target_version: str | None = None,
|
|
15
|
+
check: bool | None = None,
|
|
16
|
+
diff: bool | None = None,
|
|
17
|
+
color: bool | None = None,
|
|
18
|
+
fast: bool | None = None,
|
|
19
|
+
pyi: bool | None = None,
|
|
20
|
+
ipynb: bool | None = None,
|
|
21
|
+
python_cell_magics: str | None = None,
|
|
22
|
+
skip_source_first_line: bool | None = None,
|
|
23
|
+
skip_string_normalization: bool | None = None,
|
|
24
|
+
skip_magic_trailing_comma: bool | None = None,
|
|
25
|
+
experimental_string_processing: bool | None = None,
|
|
26
|
+
preview: bool | None = None,
|
|
27
|
+
quiet: bool | None = None,
|
|
28
|
+
verbose: bool | None = None,
|
|
29
|
+
required_version: str | None = None,
|
|
30
|
+
include: str | None = None,
|
|
31
|
+
exclude: str | None = None,
|
|
32
|
+
extend_exclude: str | None = None,
|
|
33
|
+
force_exclude: str | None = None,
|
|
34
|
+
stdin_filename: str | None = None,
|
|
35
|
+
workers: int | None = None,
|
|
36
|
+
) -> None:
|
|
37
|
+
r"""Run `black`.
|
|
38
|
+
|
|
39
|
+
Parameters:
|
|
40
|
+
src: Format the directories and file paths.
|
|
41
|
+
config: Read configuration from this file path.
|
|
42
|
+
code: Format the code passed in as a string.
|
|
43
|
+
line_length: How many characters per line to allow [default: 120].
|
|
44
|
+
target_version: Python versions that should be supported by Black's output.
|
|
45
|
+
By default, Black will try to infer this from the project metadata in pyproject.toml.
|
|
46
|
+
If this does not yield conclusive results, Black will use per-file auto-detection.
|
|
47
|
+
check: Don't write the files back, just return the status. Return code 0 means nothing would change.
|
|
48
|
+
Return code 1 means some files would be reformatted. Return code 123 means there was an internal error.
|
|
49
|
+
diff: Don't write the files back, just output a diff for each file on stdout.
|
|
50
|
+
color: Show colored diff. Only applies when `--diff` is given.
|
|
51
|
+
fast: If --fast given, skip temporary sanity checks. [default: --safe]
|
|
52
|
+
pyi: Format all input files like typing stubs regardless of file extension
|
|
53
|
+
(useful when piping source on standard input).
|
|
54
|
+
ipynb: Format all input files like Jupyter Notebooks regardless of file extension
|
|
55
|
+
(useful when piping source on standard input).
|
|
56
|
+
python_cell_magics: When processing Jupyter Notebooks, add the given magic to the list of known python-magics
|
|
57
|
+
(capture, prun, pypy, python, python3, time, timeit). Useful for formatting cells with custom python magics.
|
|
58
|
+
skip_source_first_line: Skip the first line of the source code.
|
|
59
|
+
skip_string_normalization: Don't normalize string quotes or prefixes.
|
|
60
|
+
skip_magic_trailing_comma: Don't use trailing commas as a reason to split lines.
|
|
61
|
+
preview: Enable potentially disruptive style changes that may be added
|
|
62
|
+
to Black's main functionality in the next major release.
|
|
63
|
+
quiet: Don't emit non-error messages to stderr. Errors are still emitted; silence those with 2>/dev/null.
|
|
64
|
+
verbose: Also emit messages to stderr about files that were not changed or were ignored due to exclusion patterns.
|
|
65
|
+
required_version: Require a specific version of Black to be running (useful for unifying results
|
|
66
|
+
across many environments e.g. with a pyproject.toml file).
|
|
67
|
+
It can be either a major version number or an exact version.
|
|
68
|
+
include: A regular expression that matches files and directories that should be included on recursive searches.
|
|
69
|
+
An empty value means all files are included regardless of the name. Use forward slashes for directories
|
|
70
|
+
on all platforms (Windows, too). Exclusions are calculated first, inclusions later [default: (\.pyi?|\.ipynb)$].
|
|
71
|
+
exclude: A regular expression that matches files and directories that should be excluded on recursive searches.
|
|
72
|
+
An empty value means no paths are excluded. Use forward slashes for directories on all platforms (Windows, too).
|
|
73
|
+
Exclusions are calculated first, inclusions later [default: /(\.direnv|\.eggs|\.git|\.hg|\.mypy_cache|\.nox|
|
|
74
|
+
\.tox|\.venv|venv|\.svn|\.ipynb_checkpoints|_build|buck-out|build|dist|__pypackages__)/].
|
|
75
|
+
extend_exclude: Like --exclude, but adds additional files and directories on top of the excluded ones
|
|
76
|
+
(useful if you simply want to add to the default).
|
|
77
|
+
force_exclude: Like --exclude, but files and directories matching this regex will be excluded
|
|
78
|
+
even when they are passed explicitly as arguments.
|
|
79
|
+
stdin_filename: The name of the file when passing it through stdin. Useful to make sure Black will respect
|
|
80
|
+
--force-exclude option on some editors that rely on using stdin.
|
|
81
|
+
workers: Number of parallel workers [default: number CPUs in the system].
|
|
82
|
+
"""
|
|
83
|
+
from black import main as black # noqa: PLC0415
|
|
84
|
+
|
|
85
|
+
cli_args = list(src)
|
|
86
|
+
|
|
87
|
+
if config:
|
|
88
|
+
cli_args.append("--config")
|
|
89
|
+
cli_args.append(config)
|
|
90
|
+
|
|
91
|
+
if code:
|
|
92
|
+
cli_args.append("--code")
|
|
93
|
+
cli_args.append(code)
|
|
94
|
+
|
|
95
|
+
if line_length:
|
|
96
|
+
cli_args.append("--line-length")
|
|
97
|
+
cli_args.append(str(line_length))
|
|
98
|
+
|
|
99
|
+
if target_version:
|
|
100
|
+
cli_args.append("--target-version")
|
|
101
|
+
cli_args.append(target_version)
|
|
102
|
+
|
|
103
|
+
if check:
|
|
104
|
+
cli_args.append("--check")
|
|
105
|
+
|
|
106
|
+
if diff:
|
|
107
|
+
cli_args.append("--diff")
|
|
108
|
+
|
|
109
|
+
if color is True:
|
|
110
|
+
cli_args.append("--color")
|
|
111
|
+
elif color is False:
|
|
112
|
+
cli_args.append("--no-color")
|
|
113
|
+
|
|
114
|
+
if fast:
|
|
115
|
+
cli_args.append("--fast")
|
|
116
|
+
|
|
117
|
+
if pyi:
|
|
118
|
+
cli_args.append("--pyi")
|
|
119
|
+
|
|
120
|
+
if ipynb:
|
|
121
|
+
cli_args.append("--ipynb")
|
|
122
|
+
|
|
123
|
+
if python_cell_magics:
|
|
124
|
+
cli_args.append("--python-cell-magics")
|
|
125
|
+
cli_args.append(python_cell_magics)
|
|
126
|
+
|
|
127
|
+
if skip_source_first_line:
|
|
128
|
+
cli_args.append("--skip_source_first_line")
|
|
129
|
+
|
|
130
|
+
if skip_string_normalization:
|
|
131
|
+
cli_args.append("--skip_string_normalization")
|
|
132
|
+
|
|
133
|
+
if skip_magic_trailing_comma:
|
|
134
|
+
cli_args.append("--skip_magic_trailing_comma")
|
|
135
|
+
|
|
136
|
+
if experimental_string_processing:
|
|
137
|
+
cli_args.append("--experimental_string_processing")
|
|
138
|
+
|
|
139
|
+
if preview:
|
|
140
|
+
cli_args.append("--preview")
|
|
141
|
+
|
|
142
|
+
if quiet:
|
|
143
|
+
cli_args.append("--quiet")
|
|
144
|
+
|
|
145
|
+
if verbose:
|
|
146
|
+
cli_args.append("--verbose")
|
|
147
|
+
|
|
148
|
+
if required_version:
|
|
149
|
+
cli_args.append("--required-version")
|
|
150
|
+
cli_args.append(required_version)
|
|
151
|
+
|
|
152
|
+
if include:
|
|
153
|
+
cli_args.append("--include")
|
|
154
|
+
cli_args.append(include)
|
|
155
|
+
|
|
156
|
+
if exclude:
|
|
157
|
+
cli_args.append("--exclude")
|
|
158
|
+
cli_args.append(exclude)
|
|
159
|
+
|
|
160
|
+
if extend_exclude:
|
|
161
|
+
cli_args.append("--extend-exclude")
|
|
162
|
+
cli_args.append(extend_exclude)
|
|
163
|
+
|
|
164
|
+
if force_exclude:
|
|
165
|
+
cli_args.append("--force-exclude")
|
|
166
|
+
cli_args.append(force_exclude)
|
|
167
|
+
|
|
168
|
+
if stdin_filename:
|
|
169
|
+
cli_args.append("--stdin-filename")
|
|
170
|
+
cli_args.append(stdin_filename)
|
|
171
|
+
|
|
172
|
+
if workers:
|
|
173
|
+
cli_args.append("--workers")
|
|
174
|
+
cli_args.append(str(workers))
|
|
175
|
+
|
|
176
|
+
return black(cli_args, prog_name="black")
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# YORE: Bump 2: Remove file.
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from re import Pattern
|
|
8
|
+
from typing import TYPE_CHECKING
|
|
9
|
+
|
|
10
|
+
from failprint import lazy
|
|
11
|
+
|
|
12
|
+
if TYPE_CHECKING:
|
|
13
|
+
from collections.abc import Sequence
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@lazy(name="blacken_docs")
|
|
17
|
+
def run(
|
|
18
|
+
*paths: str | Path,
|
|
19
|
+
exts: Sequence[str] | None = None,
|
|
20
|
+
exclude: Sequence[str | Pattern] | None = None,
|
|
21
|
+
skip_errors: bool = False,
|
|
22
|
+
rst_literal_blocks: bool = False,
|
|
23
|
+
line_length: int | None = None,
|
|
24
|
+
string_normalization: bool = True,
|
|
25
|
+
is_pyi: bool = False,
|
|
26
|
+
is_ipynb: bool = False,
|
|
27
|
+
skip_source_first_line: bool = False,
|
|
28
|
+
magic_trailing_comma: bool = True,
|
|
29
|
+
python_cell_magics: set[str] | None = None,
|
|
30
|
+
preview: bool = False,
|
|
31
|
+
check_only: bool = False,
|
|
32
|
+
) -> int:
|
|
33
|
+
"""Run `blacken-docs`.
|
|
34
|
+
|
|
35
|
+
Parameters:
|
|
36
|
+
*paths: Directories and files to format.
|
|
37
|
+
exts: List of extensions to select files with.
|
|
38
|
+
exclude: List of regular expressions to exclude files.
|
|
39
|
+
skip_errors: Don't exit non-zero for errors from Black (normally syntax errors).
|
|
40
|
+
rst_literal_blocks: Also format literal blocks in reStructuredText files (more below).
|
|
41
|
+
line_length: How many characters per line to allow.
|
|
42
|
+
string_normalization: Normalize string quotes or prefixes.
|
|
43
|
+
is_pyi: Format all input files like typing stubs regardless of file extension.
|
|
44
|
+
is_ipynb: Format all input files like Jupyter Notebooks regardless of file extension.
|
|
45
|
+
skip_source_first_line: Skip the first line of the source code.
|
|
46
|
+
magic_trailing_comma: Use trailing commas as a reason to split lines.
|
|
47
|
+
python_cell_magics: When processing Jupyter Notebooks, add the given magic to the list
|
|
48
|
+
of known python-magics (capture, prun, pypy, python, python3, time, timeit).
|
|
49
|
+
Useful for formatting cells with custom python magics.
|
|
50
|
+
preview: Enable potentially disruptive style changes that may be added
|
|
51
|
+
to Black's main functionality in the next major release.
|
|
52
|
+
check_only: Don't modify files but indicate when changes are necessary
|
|
53
|
+
with a message and non-zero return code.
|
|
54
|
+
|
|
55
|
+
Returns:
|
|
56
|
+
Success/failure.
|
|
57
|
+
"""
|
|
58
|
+
import black # noqa: PLC0415
|
|
59
|
+
from blacken_docs import format_file # noqa: PLC0415
|
|
60
|
+
|
|
61
|
+
exts = ("md", "py") if exts is None else tuple(ext.lstrip(".") for ext in exts)
|
|
62
|
+
if exclude:
|
|
63
|
+
exclude = tuple(re.compile(regex, re.I) if isinstance(regex, str) else regex for regex in exclude)
|
|
64
|
+
filepaths = set()
|
|
65
|
+
for path in paths:
|
|
66
|
+
path = Path(path) # noqa: PLW2901
|
|
67
|
+
if path.is_file():
|
|
68
|
+
filepaths.add(path.as_posix())
|
|
69
|
+
else:
|
|
70
|
+
for ext in exts:
|
|
71
|
+
filepaths |= {filepath.as_posix() for filepath in path.rglob(f"*.{ext}")}
|
|
72
|
+
|
|
73
|
+
black_mode = black.Mode(
|
|
74
|
+
line_length=line_length or black.DEFAULT_LINE_LENGTH,
|
|
75
|
+
string_normalization=string_normalization,
|
|
76
|
+
is_pyi=is_pyi,
|
|
77
|
+
is_ipynb=is_ipynb,
|
|
78
|
+
skip_source_first_line=skip_source_first_line,
|
|
79
|
+
magic_trailing_comma=magic_trailing_comma,
|
|
80
|
+
python_cell_magics=python_cell_magics or set(),
|
|
81
|
+
preview=preview,
|
|
82
|
+
)
|
|
83
|
+
retv = 0
|
|
84
|
+
for filepath in sorted(filepaths):
|
|
85
|
+
retv |= format_file(
|
|
86
|
+
filepath,
|
|
87
|
+
black_mode,
|
|
88
|
+
skip_errors=skip_errors,
|
|
89
|
+
rst_literal_blocks=rst_literal_blocks,
|
|
90
|
+
check_only=check_only,
|
|
91
|
+
)
|
|
92
|
+
return retv
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# YORE: Bump 2: Remove file.
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Literal
|
|
6
|
+
|
|
7
|
+
from failprint import lazy
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@lazy(name="build")
|
|
11
|
+
def run(
|
|
12
|
+
srcdir: str | None = None,
|
|
13
|
+
*,
|
|
14
|
+
version: bool = False,
|
|
15
|
+
verbose: bool = False,
|
|
16
|
+
sdist: bool = False,
|
|
17
|
+
wheel: bool = False,
|
|
18
|
+
outdir: str | None = None,
|
|
19
|
+
skip_dependency_check: bool = False,
|
|
20
|
+
no_isolation: bool = False,
|
|
21
|
+
installer: Literal["pip", "uv"] | None = None,
|
|
22
|
+
config_setting: list[str] | None = None,
|
|
23
|
+
) -> None:
|
|
24
|
+
"""Run `build`.
|
|
25
|
+
|
|
26
|
+
Parameters:
|
|
27
|
+
srcdir: Source directory (defaults to current directory).
|
|
28
|
+
version: Show program's version number and exit.
|
|
29
|
+
verbose: Increase verbosity
|
|
30
|
+
sdist: Build a source distribution (disables the default behavior).
|
|
31
|
+
wheel: Build a wheel (disables the default behavior).
|
|
32
|
+
outdir: Output directory (defaults to `{srcdir}/dist`).
|
|
33
|
+
skip_dependency_check: Do not check that build dependencies are installed.
|
|
34
|
+
no_isolation: Disable building the project in an isolated virtual environment.
|
|
35
|
+
Build dependencies must be installed separately when this option is used.
|
|
36
|
+
installer: Python package installer to use (defaults to pip).
|
|
37
|
+
config_setting: Settings to pass to the backend. Multiple settings can be provided.
|
|
38
|
+
"""
|
|
39
|
+
from build.__main__ import main as build # noqa: PLC0415
|
|
40
|
+
|
|
41
|
+
cli_args = []
|
|
42
|
+
|
|
43
|
+
if srcdir:
|
|
44
|
+
cli_args.append(srcdir)
|
|
45
|
+
|
|
46
|
+
if version:
|
|
47
|
+
cli_args.append("--version")
|
|
48
|
+
|
|
49
|
+
if verbose:
|
|
50
|
+
cli_args.append("--verbose")
|
|
51
|
+
|
|
52
|
+
if sdist:
|
|
53
|
+
cli_args.append("--sdist")
|
|
54
|
+
|
|
55
|
+
if wheel:
|
|
56
|
+
cli_args.append("--wheel")
|
|
57
|
+
|
|
58
|
+
if outdir:
|
|
59
|
+
cli_args.append("--outdir")
|
|
60
|
+
cli_args.append(outdir)
|
|
61
|
+
|
|
62
|
+
if skip_dependency_check:
|
|
63
|
+
cli_args.append("--skip-dependency-check")
|
|
64
|
+
|
|
65
|
+
if no_isolation:
|
|
66
|
+
cli_args.append("--no-isolation")
|
|
67
|
+
|
|
68
|
+
if installer:
|
|
69
|
+
cli_args.append("--installer")
|
|
70
|
+
cli_args.append(installer)
|
|
71
|
+
|
|
72
|
+
if config_setting:
|
|
73
|
+
for setting in config_setting:
|
|
74
|
+
cli_args.append(f"--config-setting={setting}")
|
|
75
|
+
|
|
76
|
+
build(cli_args)
|