Skip to content

Commit c951463

Browse files
committed
Replace flake8, black and isort with ruff
1 parent 63ab596 commit c951463

File tree

6 files changed

+119
-87
lines changed

6 files changed

+119
-87
lines changed

.pre-commit-config.yaml

Lines changed: 39 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,42 @@
11
# See https://pre-commit.com for more information
22
# See https://pre-commit.com/hooks.html for more hooks
33
repos:
4-
- repo: https://github.com/psf/black
5-
rev: 25.1.0
6-
hooks:
7-
- id: black
8-
types: []
9-
files: ^.*.pyi?$
10-
exclude: ^doc/
11-
- repo: https://github.com/pre-commit/pre-commit-hooks
12-
rev: v5.0.0
13-
hooks:
14-
- id: no-commit-to-branch
15-
- id: trailing-whitespace
16-
- id: end-of-file-fixer
17-
- id: check-yaml
18-
- id: check-added-large-files
19-
- id: check-ast
20-
- id: check-merge-conflict
21-
- id: check-json
22-
- id: detect-private-key
23-
exclude: ^.*/rsakey.pem$
24-
- id: mixed-line-ending
25-
- id: pretty-format-json
26-
args: [--autofix]
27-
- repo: https://github.com/PyCQA/flake8
28-
rev: 7.3.0
29-
hooks:
30-
- id: flake8
31-
exclude: ^setup.py$
32-
additional_dependencies: [flake8-docstrings, flake8-bugbear, flake8-logging-format, flake8-builtins, flake8-eradicate, flake8-fixme, pep8-naming, flake8-pep3101, flake8-annotations-complexity,flake8-pyi]
33-
- repo: https://github.com/PyCQA/isort
34-
rev: 6.0.1
35-
hooks:
36-
- id: isort
37-
- repo: https://github.com/pre-commit/mirrors-mypy
38-
rev: v1.16.1
39-
hooks:
40-
- id: mypy
41-
exclude: (setup.py|tests/.*.py|doc/.*)
42-
types: []
43-
files: ^.*.pyi?$
44-
additional_dependencies: [lxml-stubs,types-docutils]
45-
- repo: https://github.com/pre-commit/pygrep-hooks
46-
rev: v1.10.0
47-
hooks:
48-
- id: rst-backticks
4+
- repo: https://github.com/astral-sh/ruff-pre-commit
5+
rev: v0.12.3
6+
hooks:
7+
- id: ruff
8+
args: ["--fix"]
9+
types: [python]
10+
- id: ruff-format
11+
types: [python]
12+
13+
- repo: https://github.com/pre-commit/pre-commit-hooks
14+
rev: v5.0.0
15+
hooks:
16+
- id: no-commit-to-branch
17+
- id: trailing-whitespace
18+
- id: end-of-file-fixer
19+
- id: check-yaml
20+
- id: check-added-large-files
21+
- id: check-ast
22+
- id: check-merge-conflict
23+
- id: check-json
24+
- id: detect-private-key
25+
exclude: ^.*/rsakey.pem$
26+
- id: mixed-line-ending
27+
- id: pretty-format-json
28+
args: [--autofix]
29+
30+
- repo: https://github.com/pre-commit/mirrors-mypy
31+
rev: v1.16.1
32+
hooks:
33+
- id: mypy
34+
exclude: (setup.py|tests/.*.py|doc/.*)
35+
types: []
36+
files: ^.*.pyi?$
37+
additional_dependencies: [lxml-stubs, types-docutils]
38+
39+
- repo: https://github.com/pre-commit/pygrep-hooks
40+
rev: v1.10.0
41+
hooks:
42+
- id: rst-backticks

pyproject.toml

Lines changed: 63 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
[build-system]
2+
requires = ["setuptools>=42", "wheel", "setuptools_scm[toml]>=3.4", "pkgconfig>=1.5.1", "lxml>=3.8, !=4.7.0"]
3+
14
[tool.mypy]
25
files = ['src']
36
ignore_missing_imports = false
@@ -19,32 +22,69 @@ warn_no_return = true
1922
no_implicit_reexport = true
2023
show_error_codes = true
2124

22-
[tool.black]
23-
line_length = 130
24-
skip-string-normalization = true
25-
target_version = ['py39']
26-
include = '\.pyi?$'
27-
exclude = '''
25+
[tool.ruff]
26+
# Maximum line length, same as your original Black + Flake8 config
27+
line-length = 130
2828

29-
(
30-
/(
31-
\.eggs # exclude a few common directories in the
32-
| \.git # root of the project
33-
| \.mypy_cache
34-
| \.tox
35-
| build
36-
| dist
37-
)/
38-
)
39-
'''
29+
# Target Python version (used for autofixes and style rules)
30+
target-version = "py39"
4031

41-
[tool.isort]
42-
profile = 'black'
43-
known_first_party = ['xmlsec']
44-
known_third_party = ['lxml', 'pytest', '_pytest', 'hypothesis']
32+
# Enable rule categories:
33+
# E = pycodestyle (style issues, like indentation, whitespace, etc.)
34+
# F = pyflakes (unused imports, undefined names)
35+
# D = pydocstyle (docstring format/style issues)
36+
# I = isort (import sorting)
37+
# B = flake8-bugbear (common bugs & anti-patterns)
38+
# UP = pyupgrade (auto-upgrade syntax for newer Python)
39+
# SIM = flake8-simplify (simplifiable code patterns)
40+
# RUF = Ruff-native rules (extra, performance-optimized checks)
41+
select = ["E", "F", "D", "I", "B", "UP", "SIM", "RUF"]
4542

46-
[build-system]
47-
requires = ['setuptools>=42', 'wheel', 'setuptools_scm[toml]>=3.4', "pkgconfig>=1.5.1", "lxml>=3.8, !=4.7.0"]
43+
# Directories and files to exclude from linting and formatting
44+
exclude = [
45+
".venv*", # virtual environments
46+
".git", # git directory
47+
"build", # build output
48+
"dist", # distribution packages
49+
"libs", # vendor libraries
50+
".eggs", # setuptools egg folders
51+
".direnv*", # direnv environments
52+
"*_pb2.pyi" # protobuf-generated type stubs
53+
]
54+
55+
# File-specific rule ignores (equivalent to flake8's `per-file-ignores`)
56+
[tool.ruff.per-file-ignores]
57+
"*.pyi" = [
58+
# Ignore formatting and import errors in stub files
59+
"E301", # expected 1 blank line, found 0
60+
"E302", # expected 2 blank lines, found 1
61+
"E305", # expected 2 blank lines after class or function
62+
"E501", # line too long
63+
"E701", # multiple statements on one line
64+
"F401", # unused import
65+
"F822" # undefined name in `__all__`
66+
]
67+
"doc/source/conf.py" = [
68+
"D1" # missing docstring in public module/class/function
69+
]
70+
"doc/source/examples/*.py" = [
71+
"D1", # allow missing docstrings in examples
72+
"E501" # allow long lines in code examples
73+
]
74+
"tests/*.py" = [
75+
"D1" # allow missing docstrings in test files
76+
]
77+
78+
[tool.ruff.format]
79+
# Always use single quotes (e.g., 'text' instead of "text")
80+
quote-style = "single"
81+
82+
# Format code with or without trailing commas
83+
# true = prefer trailing commas where valid
84+
skip-magic-trailing-comma = false
85+
86+
# Enforce Unix-style line endings (LF)
87+
line-ending = "lf"
4888

4989
[tool.cibuildwheel]
5090
build = [

requirements-test.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
-r requirements.txt
2-
pytest>=4.6.9
3-
lxml-stubs
2+
3+
pytest==8.4.1
4+
lxml-stubs==0.5.1
5+
ruff[format]==0.12.3

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
lxml >= 3.8.0, !=4.7.0
1+
lxml==6.0.0

setup.cfg

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,11 @@ source-dir = doc/source
1212
build-dir = doc/build
1313
all_files = 1
1414

15-
[upload_docs]
16-
upload_dir = doc/build/html
17-
18-
[flake8]
19-
per-file-ignores =
20-
*.pyi: E301, E302, E305, E501, E701, F401, F822
21-
doc/source/conf.py: D1
22-
doc/source/examples/*.py: D1, E501
23-
tests/*.py: D1
24-
exclude = .venv*,.git,*_pb2.pyi,build,dist,libs,.eggs,.direnv*
25-
max-line-length = 130
15+
# [flake8]
16+
# per-file-ignores =
17+
# *.pyi: E301, E302, E305, E501, E701, F401, F822
18+
# doc/source/conf.py: D1
19+
# doc/source/examples/*.py: D1, E501
20+
# tests/*.py: D1
21+
# exclude = .venv*,.git,*_pb2.pyi,build,dist,libs,.eggs,.direnv*
22+
# max-line-length = 130

setup.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ def prepare_static_build(self, build_platform):
596596
long_description_content_type='text/markdown',
597597
ext_modules=[pyxmlsec],
598598
cmdclass={'build_ext': build_ext},
599-
python_requires='>=3.5',
599+
python_requires='>=3.9',
600600
setup_requires=setup_reqs,
601601
install_requires=['lxml>=3.8'],
602602
author="Bulat Gaifullin",
@@ -619,12 +619,11 @@ def prepare_static_build(self, build_platform):
619619
'Operating System :: OS Independent',
620620
'Programming Language :: C',
621621
'Programming Language :: Python :: 3',
622-
'Programming Language :: Python :: 3.5',
623-
'Programming Language :: Python :: 3.6',
624-
'Programming Language :: Python :: 3.7',
625-
'Programming Language :: Python :: 3.8',
626622
'Programming Language :: Python :: 3.9',
623+
'Programming Language :: Python :: 3.10',
627624
'Programming Language :: Python :: 3.11',
625+
'Programming Language :: Python :: 3.12',
626+
'Programming Language :: Python :: 3.13',
628627
'Topic :: Text Processing :: Markup :: XML',
629628
'Typing :: Typed',
630629
],

0 commit comments

Comments
 (0)