Skip to content

Commit f430219

Browse files
authored
Migrate linting to Ruff and update CI settings (#359)
Replace flake8, black, and isort with Ruff as the unified linter and formatter. - Applied auto-fixes from Ruff - Removed legacy configuration for flake8, black, and isort - Updated CI settings to prevent job cancelation on master
1 parent 63ab596 commit f430219

30 files changed

+460
-481
lines changed

.github/workflows/linuxbrew.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: linuxbrew
22
on: [push, pull_request]
33
concurrency:
44
group: ${{ github.workflow }}-${{ github.ref }}
5-
cancel-in-progress: true
5+
cancel-in-progress: ${{ github.ref_name != 'master' }}
66
jobs:
77
linuxbrew:
88
runs-on: ubuntu-latest

.github/workflows/macosx.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: macOS
22
on: [push, pull_request]
33
concurrency:
44
group: ${{ github.workflow }}-${{ github.ref }}
5-
cancel-in-progress: true
5+
cancel-in-progress: ${{ github.ref_name != 'master' }}
66
jobs:
77
macosx:
88
runs-on: macos-latest

.github/workflows/manylinux.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: manylinux
22
on: [push, pull_request]
33
concurrency:
44
group: ${{ github.workflow }}-${{ github.ref }}
5-
cancel-in-progress: true
5+
cancel-in-progress: ${{ github.ref_name != 'master' }}
66
jobs:
77
manylinux:
88
runs-on: ubuntu-latest

.github/workflows/sdist.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: sdist
22
on: [push, pull_request]
33
concurrency:
44
group: ${{ github.workflow }}-${{ github.ref }}
5-
cancel-in-progress: true
5+
cancel-in-progress: ${{ github.ref_name != 'master' }}
66
jobs:
77
sdist:
88
# Avoid Ubuntu 24.04 in sdist workflows, because it contains libxmlsec1-dev

.github/workflows/wheels.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ on:
1717

1818
concurrency:
1919
group: ${{ github.workflow }}-${{ github.ref }}
20-
cancel-in-progress: true
20+
cancel-in-progress: ${{ github.ref_name != 'master' }}
2121

2222
permissions: {}
2323

.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

doc/source/conf.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
source_suffix = '.rst'
2020
master_doc = 'index'
2121

22-
project = u'python-xmlsec'
23-
copyright = u'2020, Oleg Hoefling <[email protected]>' # noqa: A001
24-
author = u'Bulat Gaifullin <[email protected]>'
22+
project = 'python-xmlsec'
23+
copyright = '2020, Oleg Hoefling <[email protected]>'
24+
author = 'Bulat Gaifullin <[email protected]>'
2525
release = importlib.metadata.version('xmlsec')
2626
parsed: Version = parse(release)
27-
version = '{}.{}'.format(parsed.major, parsed.minor)
27+
version = f'{parsed.major}.{parsed.minor}'
2828

2929
exclude_patterns: list[str] = []
3030
pygments_style = 'sphinx'
@@ -39,19 +39,19 @@
3939
(
4040
master_doc,
4141
'python-xmlsec.tex',
42-
u'python-xmlsec Documentation',
43-
u'Bulat Gaifullin \\textless{}[email protected]\\textgreater{}',
42+
'python-xmlsec Documentation',
43+
'Bulat Gaifullin \\textless{}[email protected]\\textgreater{}',
4444
'manual',
4545
)
4646
]
4747

48-
man_pages = [(master_doc, 'python-xmlsec', u'python-xmlsec Documentation', [author], 1)]
48+
man_pages = [(master_doc, 'python-xmlsec', 'python-xmlsec Documentation', [author], 1)]
4949

5050
texinfo_documents = [
5151
(
5252
master_doc,
5353
'python-xmlsec',
54-
u'python-xmlsec Documentation',
54+
'python-xmlsec Documentation',
5555
author,
5656
'python-xmlsec',
5757
'One line description of project.',
@@ -63,10 +63,10 @@
6363
autodoc_docstring_signature = True
6464

6565

66-
rst_prolog = '''
66+
rst_prolog = """
6767
.. role:: xml(code)
6868
:language: xml
69-
'''
69+
"""
7070

7171
# LXML crossref'ing stuff:
7272
# LXML doesn't have an intersphinx docs,
@@ -75,8 +75,7 @@
7575

7676

7777
def lxml_element_doc_reference(app: Sphinx, env: BuildEnvironment, node: pending_xref, contnode: Text) -> reference:
78-
"""
79-
Handle a missing reference only if it is a ``lxml.etree._Element`` ref.
78+
"""Handle a missing reference only if it is a ``lxml.etree._Element`` ref.
8079
8180
We handle only :class:`lxml.etree._Element` and :class:`~lxml.etree._Element` nodes.
8281
"""
@@ -85,7 +84,7 @@ def lxml_element_doc_reference(app: Sphinx, env: BuildEnvironment, node: pending
8584
and node.get('reftarget', None) == 'lxml.etree._Element'
8685
and contnode.astext() in ('lxml.etree._Element', '_Element')
8786
):
88-
reftitle = '(in lxml v{})'.format(lxml.__version__) # type: ignore[attr-defined]
87+
reftitle = f'(in lxml v{lxml.__version__})' # type: ignore[attr-defined]
8988
newnode = reference('', '', internal=False, refuri=lxml_element_cls_doc_uri, reftitle=reftitle)
9089
newnode.append(contnode)
9190
return newnode

doc/source/examples/decrypt.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
key = xmlsec.Key.from_file('rsakey.pem', xmlsec.constants.KeyDataFormatPem)
77
manager.add_key(key)
88
enc_ctx = xmlsec.EncryptionContext(manager)
9-
root = etree.parse("enc1-res.xml").getroot()
10-
enc_data = xmlsec.tree.find_child(root, "EncryptedData", xmlsec.constants.EncNs)
9+
root = etree.parse('enc1-res.xml').getroot()
10+
enc_data = xmlsec.tree.find_child(root, 'EncryptedData', xmlsec.constants.EncNs)
1111
decrypted = enc_ctx.decrypt(enc_data)
1212
print(etree.tostring(decrypted))

doc/source/examples/encrypt.py

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
template,
1010
xmlsec.constants.TransformAes128Cbc,
1111
type=xmlsec.constants.TypeEncElement,
12-
ns="xenc",
12+
ns='xenc',
1313
)
1414

1515
xmlsec.template.encrypted_data_ensure_cipher_value(enc_data)
16-
key_info = xmlsec.template.encrypted_data_ensure_key_info(enc_data, ns="dsig")
16+
key_info = xmlsec.template.encrypted_data_ensure_key_info(enc_data, ns='dsig')
1717
enc_key = xmlsec.template.add_encrypted_key(key_info, xmlsec.constants.TransformRsaOaep)
1818
xmlsec.template.encrypted_data_ensure_cipher_value(enc_key)
1919
data = template.find('./Data')
@@ -24,20 +24,10 @@
2424
manager.add_key(key)
2525

2626
enc_ctx = xmlsec.EncryptionContext(manager)
27-
enc_ctx.key = xmlsec.Key.generate(
28-
xmlsec.constants.KeyDataAes, 128, xmlsec.constants.KeyDataTypeSession
29-
)
27+
enc_ctx.key = xmlsec.Key.generate(xmlsec.constants.KeyDataAes, 128, xmlsec.constants.KeyDataTypeSession)
3028
enc_data = enc_ctx.encrypt_xml(enc_data, data)
31-
enc_method = xmlsec.tree.find_child(
32-
enc_data, xmlsec.constants.NodeEncryptionMethod, xmlsec.constants.EncNs
33-
)
34-
key_info = xmlsec.tree.find_child(
35-
enc_data, xmlsec.constants.NodeKeyInfo, xmlsec.constants.DSigNs
36-
)
37-
enc_method = xmlsec.tree.find_node(
38-
key_info, xmlsec.constants.NodeEncryptionMethod, xmlsec.constants.EncNs
39-
)
40-
cipher_value = xmlsec.tree.find_node(
41-
key_info, xmlsec.constants.NodeCipherValue, xmlsec.constants.EncNs
42-
)
29+
enc_method = xmlsec.tree.find_child(enc_data, xmlsec.constants.NodeEncryptionMethod, xmlsec.constants.EncNs)
30+
key_info = xmlsec.tree.find_child(enc_data, xmlsec.constants.NodeKeyInfo, xmlsec.constants.DSigNs)
31+
enc_method = xmlsec.tree.find_node(key_info, xmlsec.constants.NodeEncryptionMethod, xmlsec.constants.EncNs)
32+
cipher_value = xmlsec.tree.find_node(key_info, xmlsec.constants.NodeCipherValue, xmlsec.constants.EncNs)
4333
print(etree.tostring(cipher_value))

doc/source/examples/verify.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
with open('sign1-res.xml') as fp:
66
template = etree.parse(fp).getroot()
77

8-
xmlsec.tree.add_ids(template, ["ID"])
8+
xmlsec.tree.add_ids(template, ['ID'])
99
signature_node = xmlsec.tree.find_node(template, xmlsec.constants.NodeSignature)
1010
# Create a digital signature context (no key manager is needed).
1111
ctx = xmlsec.SignatureContext()

0 commit comments

Comments
 (0)