Skip to content

Commit 4062036

Browse files
committed
introduce pre-commit
Signed-off-by: oleg.hoefling <[email protected]>
1 parent e8ec653 commit 4062036

25 files changed

+163
-454
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
!.appveyor*
66
!.git*
77
!.readthedocs.yaml
8+
!.pre-commit-config.yaml
89

910
# Python
1011
/dist

.pre-commit-config.yaml

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# See https://pre-commit.com for more information
2+
# See https://pre-commit.com/hooks.html for more hooks
3+
exclude: ".*.diff" # exclude patches
4+
repos:
5+
- repo: https://github.com/psf/black
6+
rev: 22.6.0
7+
hooks:
8+
- id: black
9+
types: []
10+
files: ^.*.pyi?$
11+
exclude: ^doc/
12+
- repo: https://github.com/pre-commit/pre-commit-hooks
13+
rev: v4.3.0
14+
hooks:
15+
- id: no-commit-to-branch
16+
- id: trailing-whitespace
17+
- id: end-of-file-fixer
18+
- id: check-yaml
19+
- id: check-added-large-files
20+
- id: check-ast
21+
- id: check-merge-conflict
22+
- id: check-json
23+
- id: detect-private-key
24+
- id: mixed-line-ending
25+
- id: pretty-format-json
26+
args: [--autofix]
27+
- repo: https://github.com/PyCQA/flake8
28+
rev: 5.0.4
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: 5.10.1
35+
hooks:
36+
- id: isort
37+
- repo: https://github.com/pre-commit/mirrors-mypy
38+
rev: v0.971
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.9.0
47+
hooks:
48+
- id: rst-backticks

doc/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ help:
1717
# Catch-all target: route all unknown targets to Sphinx using the new
1818
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
1919
%: Makefile
20-
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

doc/source/conf.py

+13-10
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
import urllib.request
55

66
import lxml
7-
from docutils.nodes import reference
8-
from packaging.version import parse
7+
from docutils.nodes import Text, reference
8+
from packaging.version import Version, parse
9+
from sphinx.addnodes import pending_xref
10+
from sphinx.application import Sphinx
11+
from sphinx.environment import BuildEnvironment
912
from sphinx.errors import ExtensionError
1013

1114
if sys.version_info >= (3, 8):
@@ -23,22 +26,22 @@
2326
master_doc = 'index'
2427

2528
project = u'python-xmlsec'
26-
copyright = u'2020, Oleg Hoefling <[email protected]>'
29+
copyright = u'2020, Oleg Hoefling <[email protected]>' # noqa: A001
2730
author = u'Bulat Gaifullin <[email protected]>'
2831
release = importlib_metadata.version('xmlsec')
29-
parsed = parse(release)
32+
parsed: Version = parse(release)
3033
version = '{}.{}'.format(parsed.major, parsed.minor)
3134

3235
language = None
33-
exclude_patterns = []
36+
exclude_patterns: list[str] = []
3437
pygments_style = 'sphinx'
3538
todo_include_todos = False
3639

3740
html_theme = 'furo'
38-
html_static_path = []
41+
html_static_path: list[str] = []
3942
htmlhelp_basename = 'python-xmlsecdoc'
4043

41-
latex_elements = {}
44+
latex_elements: dict[str, str] = {}
4245
latex_documents = [
4346
(
4447
master_doc,
@@ -72,7 +75,7 @@
7275
lxml_element_cls_doc_uri = 'https://lxml.de/api/lxml.etree._Element-class.html'
7376

7477

75-
def lxml_element_doc_reference(app, env, node, contnode):
78+
def lxml_element_doc_reference(app: Sphinx, env: BuildEnvironment, node: pending_xref, contnode: Text) -> reference:
7679
"""
7780
Handle a missing reference only if it is a ``lxml.etree._Element`` ref.
7881
@@ -83,13 +86,13 @@ def lxml_element_doc_reference(app, env, node, contnode):
8386
and node.get('reftarget', None) == 'lxml.etree._Element'
8487
and contnode.astext() in ('lxml.etree._Element', '_Element')
8588
):
86-
reftitle = '(in lxml v{})'.format(lxml.__version__)
89+
reftitle = '(in lxml v{})'.format(lxml.__version__) # type: ignore[attr-defined]
8790
newnode = reference('', '', internal=False, refuri=lxml_element_cls_doc_uri, reftitle=reftitle)
8891
newnode.append(contnode)
8992
return newnode
9093

9194

92-
def setup(app):
95+
def setup(app: Sphinx) -> None:
9396
# first, check whether the doc URL is still valid
9497
if urllib.request.urlopen(lxml_element_cls_doc_uri).getcode() != 200:
9598
raise ExtensionError('URL to `lxml.etree._Element` docs is not accesible.')

mypy.ini

-16
This file was deleted.

pyproject.toml

+21
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
[tool.mypy]
2+
files = ['src']
3+
ignore_missing_imports = false
4+
warn_unused_configs = true
5+
disallow_subclassing_any = true
6+
disallow_any_generics = true
7+
disallow_untyped_calls = true
8+
disallow_untyped_defs = true
9+
disallow_incomplete_defs = true
10+
check_untyped_defs = true
11+
disallow_untyped_decorators = true
12+
disallow_any_unimported = true
13+
strict_optional = true
14+
no_implicit_optional = true
15+
warn_redundant_casts = true
16+
warn_unused_ignores = true
17+
warn_return_any = true
18+
warn_no_return = true
19+
no_implicit_reexport = true
20+
show_error_codes = true
21+
122
[tool.black]
223
line_length = 130
324
skip-string-normalization = true

setup.py

+35-23
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
import tarfile
1111
import zipfile
1212
from distutils import log
13-
from distutils.version import StrictVersion as Version
1413
from distutils.errors import DistutilsError
14+
from distutils.version import StrictVersion as Version
1515
from pathlib import Path
1616
from urllib.request import urlcleanup, urljoin, urlopen, urlretrieve
1717

@@ -59,33 +59,23 @@ def latest_release_from_gnome_org_cache(url, lib_name):
5959

6060

6161
def latest_zlib_release():
62-
return latest_release_from_html(
63-
'https://zlib.net/fossils', re.compile('zlib-(?P<version>.*).tar.gz')
64-
)
62+
return latest_release_from_html('https://zlib.net/fossils', re.compile('zlib-(?P<version>.*).tar.gz'))
6563

6664

6765
def latest_libiconv_release():
68-
return latest_release_from_html(
69-
'https://ftp.gnu.org/pub/gnu/libiconv', re.compile('libiconv-(?P<version>.*).tar.gz')
70-
)
66+
return latest_release_from_html('https://ftp.gnu.org/pub/gnu/libiconv', re.compile('libiconv-(?P<version>.*).tar.gz'))
7167

7268

7369
def latest_libxml2_release():
74-
return latest_release_from_gnome_org_cache(
75-
'https://download.gnome.org/sources/libxml2', 'libxml2'
76-
)
70+
return latest_release_from_gnome_org_cache('https://download.gnome.org/sources/libxml2', 'libxml2')
7771

7872

7973
def latest_libxslt_release():
80-
return latest_release_from_gnome_org_cache(
81-
'https://download.gnome.org/sources/libxslt', 'libxslt'
82-
)
74+
return latest_release_from_gnome_org_cache('https://download.gnome.org/sources/libxslt', 'libxslt')
8375

8476

8577
def latest_xmlsec_release():
86-
return latest_release_from_html(
87-
'https://www.aleksey.com/xmlsec/download/', re.compile('xmlsec1-(?P<version>.*).tar.gz')
88-
)
78+
return latest_release_from_html('https://www.aleksey.com/xmlsec/download/', re.compile('xmlsec1-(?P<version>.*).tar.gz'))
8979

9080

9181
class build_ext(build_ext_orig):
@@ -265,7 +255,9 @@ def prepare_static_build_linux(self):
265255
self.info('{:10}: {}'.format('zlib', 'PYXMLSEC_ZLIB_VERSION unset, downloading latest from {}'.format(url)))
266256
else:
267257
url = 'https://zlib.net/fossils/zlib-{}.tar.gz'.format(self.zlib_version)
268-
self.info('{:10}: {}'.format('zlib', 'PYXMLSEC_ZLIB_VERSION={}, downloading from {}'.format(self.zlib_version, url)))
258+
self.info(
259+
'{:10}: {}'.format('zlib', 'PYXMLSEC_ZLIB_VERSION={}, downloading from {}'.format(self.zlib_version, url))
260+
)
269261
urlretrieve(url, str(zlib_tar))
270262

271263
# fetch libiconv
@@ -278,7 +270,11 @@ def prepare_static_build_linux(self):
278270
self.info('{:10}: {}'.format('zlib', 'PYXMLSEC_LIBICONV_VERSION unset, downloading latest from {}'.format(url)))
279271
else:
280272
url = 'https://ftp.gnu.org/pub/gnu/libiconv/libiconv-{}.tar.gz'.format(self.libiconv_version)
281-
self.info('{:10}: {}'.format('zlib', 'PYXMLSEC_LIBICONV_VERSION={}, downloading from {}'.format(self.libiconv_version, url)))
273+
self.info(
274+
'{:10}: {}'.format(
275+
'zlib', 'PYXMLSEC_LIBICONV_VERSION={}, downloading from {}'.format(self.libiconv_version, url)
276+
)
277+
)
282278
urlretrieve(url, str(libiconv_tar))
283279

284280
# fetch libxml2
@@ -290,8 +286,14 @@ def prepare_static_build_linux(self):
290286
self.info('{:10}: {}'.format('libxml2', 'PYXMLSEC_LIBXML2_VERSION unset, downloading latest from {}'.format(url)))
291287
else:
292288
version_prefix, _ = self.libxml2_version.split('.', -1)
293-
url = 'https://download.gnome.org/sources/libxml2/{}/libxml2-{}.tar.xz'.format(version_prefix, self.libxml2_version)
294-
self.info('{:10}: {}'.format('libxml2', 'PYXMLSEC_LIBXML2_VERSION={}, downloading from {}'.format(self.libxml2_version, url)))
289+
url = 'https://download.gnome.org/sources/libxml2/{}/libxml2-{}.tar.xz'.format(
290+
version_prefix, self.libxml2_version
291+
)
292+
self.info(
293+
'{:10}: {}'.format(
294+
'libxml2', 'PYXMLSEC_LIBXML2_VERSION={}, downloading from {}'.format(self.libxml2_version, url)
295+
)
296+
)
295297
libxml2_tar = self.libs_dir / 'libxml2.tar.xz'
296298
urlretrieve(url, str(libxml2_tar))
297299

@@ -304,8 +306,14 @@ def prepare_static_build_linux(self):
304306
self.info('{:10}: {}'.format('libxslt', 'PYXMLSEC_LIBXSLT_VERSION unset, downloading latest from {}'.format(url)))
305307
else:
306308
version_prefix, _ = self.libxslt_version.split('.', -1)
307-
url = 'https://download.gnome.org/sources/libxslt/{}/libxslt-{}.tar.xz'.format(version_prefix, self.libxslt_version)
308-
self.info('{:10}: {}'.format('libxslt', 'PYXMLSEC_LIBXSLT_VERSION={}, downloading from {}'.format(self.libxslt_version, url)))
309+
url = 'https://download.gnome.org/sources/libxslt/{}/libxslt-{}.tar.xz'.format(
310+
version_prefix, self.libxslt_version
311+
)
312+
self.info(
313+
'{:10}: {}'.format(
314+
'libxslt', 'PYXMLSEC_LIBXSLT_VERSION={}, downloading from {}'.format(self.libxslt_version, url)
315+
)
316+
)
309317
libxslt_tar = self.libs_dir / 'libxslt.tar.gz'
310318
urlretrieve(url, str(libxslt_tar))
311319

@@ -318,7 +326,11 @@ def prepare_static_build_linux(self):
318326
self.info('{:10}: {}'.format('xmlsec1', 'PYXMLSEC_XMLSEC1_VERSION unset, downloading latest from {}'.format(url)))
319327
else:
320328
url = 'https://www.aleksey.com/xmlsec/download/xmlsec1-{}.tar.gz'.format(self.xmlsec1_version)
321-
self.info('{:10}: {}'.format('xmlsec1', 'PYXMLSEC_XMLSEC1_VERSION={}, downloading from {}'.format(self.xmlsec1_version, url)))
329+
self.info(
330+
'{:10}: {}'.format(
331+
'xmlsec1', 'PYXMLSEC_XMLSEC1_VERSION={}, downloading from {}'.format(self.xmlsec1_version, url)
332+
)
333+
)
322334
xmlsec1_tar = self.libs_dir / 'xmlsec1.tar.gz'
323335
urlretrieve(url, str(xmlsec1_tar))
324336

src/xmlsec/__init__.pyi

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
from collections.abc import Callable, Iterable
2-
from typing import Any, AnyStr, IO, TypeVar, overload
3-
from _typeshed import GenericPath, Self, StrOrBytesPath
2+
from typing import IO, Any, AnyStr, TypeVar, overload
43

4+
from _typeshed import GenericPath, Self, StrOrBytesPath
55
from lxml.etree import _Element
66

7-
from xmlsec import constants as constants, tree as tree
8-
from xmlsec.constants import __KeyData as KeyData, __Transform as Transform
7+
from xmlsec import constants as constants
8+
from xmlsec import tree as tree
9+
from xmlsec.constants import __KeyData as KeyData
10+
from xmlsec.constants import __Transform as Transform
911

1012
_E = TypeVar('_E', bound=_Element)
1113

@@ -44,12 +46,12 @@ class Key:
4446
@classmethod
4547
def from_binary_file(cls: type[Self], klass: KeyData, filename: StrOrBytesPath) -> Self: ...
4648
@classmethod
47-
def from_file(cls: type[Self], file: GenericPath | IO[AnyStr], format: int, password: str | None = ...) -> Self: ...
49+
def from_file(cls: type[Self], file: GenericPath[AnyStr] | IO[AnyStr], format: int, password: str | None = ...) -> Self: ...
4850
@classmethod
4951
def from_memory(cls: type[Self], data: AnyStr, format: int, password: str | None = ...) -> Self: ...
5052
@classmethod
5153
def generate(cls: type[Self], klass: KeyData, size: int, type: int) -> Self: ...
52-
def load_cert_from_file(self, file: GenericPath | IO[AnyStr], format: int) -> None: ...
54+
def load_cert_from_file(self, file: GenericPath[AnyStr] | IO[AnyStr], format: int) -> None: ...
5355
def load_cert_from_memory(self, data: AnyStr, format: int) -> None: ...
5456
def __copy__(self: Self) -> Self: ...
5557
def __deepcopy__(self: Self) -> Self: ...

0 commit comments

Comments
 (0)