py-topdir.mk: Use ruff and yapf
- Use ruff and yapf for the targets py-check-syntax, py-format and py-check-format.- Add a pyproject.toml for those. It also includes configuration for isort, albeit not being directly used in the linter targets.- Make .gitignore igore that in newly created projects.
- Add ruff, yapf and isort to pkg.requires.release, anticipating their use by CI.Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
d933c59ada
commit
36d854ce19
4 changed files with 81 additions and 1 deletions
75
conf/topdir/pyproject.toml
Normal file
75
conf/topdir/pyproject.toml
Normal file
|
|
@ -0,0 +1,75 @@
|
||||||
|
[tool.isort]
|
||||||
|
|
||||||
|
lines_between_sections = 1
|
||||||
|
lines_between_types = 1
|
||||||
|
|
||||||
|
# Make sure external deps are classified above
|
||||||
|
known_third_party = [
|
||||||
|
"yaml",
|
||||||
|
]
|
||||||
|
|
||||||
|
# Define semantic/dependency layers.
|
||||||
|
sections = [
|
||||||
|
"FUTURE",
|
||||||
|
"STDLIB",
|
||||||
|
"THIRDPARTY",
|
||||||
|
"JW_BASIC",
|
||||||
|
"FIRSTPARTY",
|
||||||
|
"LOCALFOLDER",
|
||||||
|
]
|
||||||
|
|
||||||
|
known_jw_basic = [
|
||||||
|
"jw.pkg",
|
||||||
|
]
|
||||||
|
|
||||||
|
# Catch other jw.* imports not assigned to a finer section.
|
||||||
|
known_first_party = [
|
||||||
|
"jw",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
[tool.ruff]
|
||||||
|
line-length = 88
|
||||||
|
|
||||||
|
[tool.ruff.format]
|
||||||
|
|
||||||
|
quote-style = "single"
|
||||||
|
|
||||||
|
[tool.ruff.lint]
|
||||||
|
|
||||||
|
select = [
|
||||||
|
"F", # Pyflakes, includes F401
|
||||||
|
"E", # pycodestyle errors
|
||||||
|
"W", # pycodestyle warnings
|
||||||
|
]
|
||||||
|
|
||||||
|
ignore = [
|
||||||
|
"E251",
|
||||||
|
]
|
||||||
|
|
||||||
|
unfixable = [
|
||||||
|
"E251",
|
||||||
|
]
|
||||||
|
|
||||||
|
[tool.yapf]
|
||||||
|
|
||||||
|
based_on_style = "pep8"
|
||||||
|
column_limit = 88
|
||||||
|
indent_width = 4
|
||||||
|
continuation_indent_width = 4
|
||||||
|
|
||||||
|
continuation_align_style = "space"
|
||||||
|
|
||||||
|
dedent_closing_brackets = true
|
||||||
|
coalesce_brackets = false
|
||||||
|
|
||||||
|
split_all_comma_separated_values = false
|
||||||
|
split_all_top_level_comma_separated_values = true
|
||||||
|
|
||||||
|
split_before_first_argument = true
|
||||||
|
split_arguments_when_comma_terminated = true
|
||||||
|
split_before_expression_after_opening_paren = true
|
||||||
|
|
||||||
|
spaces_around_default_or_named_assign = true
|
||||||
|
blank_line_before_nested_class_or_def = true
|
||||||
|
blank_lines_around_top_level_definition = 1
|
||||||
|
|
@ -21,6 +21,7 @@ devel = jw-pkg-run = VERSION-REVISION
|
||||||
run = bash, python3
|
run = bash, python3
|
||||||
build = make, time, xdg-utils, coreutils, cpio, xdg-utils, git-core
|
build = make, time, xdg-utils, coreutils, cpio, xdg-utils, git-core
|
||||||
devel = sudo, gawk, pkg-config
|
devel = sudo, gawk, pkg-config
|
||||||
|
release = python3-isort, python3-yapf, python3-ruff
|
||||||
|
|
||||||
[pkg.requires.centos]
|
[pkg.requires.centos]
|
||||||
run = hostname, python
|
run = hostname, python
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
TD_COPY_FILES +=
|
TD_COPY_FILES += pyproject.toml
|
||||||
|
|
||||||
PY_CHECK_EXCLUDE ?=
|
PY_CHECK_EXCLUDE ?=
|
||||||
PY_SRC_ROOT += $(wildcard $(TOPDIR)/src $(TOPDIR)/tools)
|
PY_SRC_ROOT += $(wildcard $(TOPDIR)/src $(TOPDIR)/tools)
|
||||||
|
|
@ -11,13 +11,16 @@ check-format: py-check-format
|
||||||
|
|
||||||
py-check: py-check-syntax py-check-format
|
py-check: py-check-syntax py-check-format
|
||||||
py-check-syntax:
|
py-check-syntax:
|
||||||
|
ruff check $(addprefix --exclude ,$(PY_CHECK_EXCLUDE)) $(PY_SRC_ROOT)
|
||||||
mypy $(addprefix --exclude ,$(PY_CHECK_EXCLUDE)) $(PY_SRC_ROOT)
|
mypy $(addprefix --exclude ,$(PY_CHECK_EXCLUDE)) $(PY_SRC_ROOT)
|
||||||
|
|
||||||
py-check-format:
|
py-check-format:
|
||||||
|
yapf --diff --recursive .
|
||||||
|
|
||||||
py-format:
|
py-format:
|
||||||
find . -type f -name '*.py' -print0 | \
|
find . -type f -name '*.py' -print0 | \
|
||||||
xargs -0 sed -i -E '1{/^# -\*- coding: utf-8 -\*-$$/{:a;N;/\n[[:space:]]*$$/ba;s/^# -\*- coding: utf-8 -\*-\n([[:space:]]*\n)*/ /;s/^ //}}'
|
xargs -0 sed -i -E '1{/^# -\*- coding: utf-8 -\*-$$/{:a;N;/\n[[:space:]]*$$/ba;s/^# -\*- coding: utf-8 -\*-\n([[:space:]]*\n)*/ /;s/^ //}}'
|
||||||
|
yapf --in-place --recursive .
|
||||||
|
|
||||||
py-format-assignments:
|
py-format-assignments:
|
||||||
find . \
|
find . \
|
||||||
|
|
|
||||||
|
|
@ -128,6 +128,7 @@ cat_gitignore()
|
||||||
*tmp*
|
*tmp*
|
||||||
__init__.py
|
__init__.py
|
||||||
__pycache__
|
__pycache__
|
||||||
|
pyproject.toml
|
||||||
EOT
|
EOT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue