Skip to content

Commit 79d978a

Browse files
committed
QA and CI: Format code using ruff. Validate using ruff and mypy.
1 parent a525a63 commit 79d978a

26 files changed

Lines changed: 1372 additions & 942 deletions

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ jobs:
6363
echo "Invoking tests with CrateDB ${CRATEDB_VERSION}"
6464
6565
# Run linter.
66-
flake8 src bin
66+
poe lint
6767
6868
# Run tests.
6969
coverage run bin/test -vvv

DEVELOP.rst

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ see, for example, `useful command-line options for zope-testrunner`_.
3232

3333
Run all tests::
3434

35-
bin/test
35+
poe test
3636

3737
Run specific tests::
3838

@@ -83,6 +83,23 @@ are listening on the default CrateDB transport port to avoid side effects with
8383
the test layer.
8484

8585

86+
Formatting and linting code
87+
===========================
88+
89+
To use Ruff for code formatting, according to the standards configured in
90+
``pyproject.toml``, use::
91+
92+
poe format
93+
94+
To lint the code base using Ruff and mypy, use::
95+
96+
poe lint
97+
98+
Linting and software testing, all together now::
99+
100+
poe check
101+
102+
86103
Renew certificates
87104
==================
88105

bootstrap.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ function main() {
110110
}
111111

112112
function lint() {
113-
flake8 "$@" src bin
113+
poe lint
114114
}
115115

116116
main

docs/conf.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
# ruff: noqa: F403, F405
12
from crate.theme.rtd.conf.python import *
23

3-
44
if "sphinx.ext.intersphinx" not in extensions:
55
extensions += ["sphinx.ext.intersphinx"]
66

@@ -9,21 +9,25 @@
99
intersphinx_mapping = {}
1010

1111

12-
intersphinx_mapping.update({
13-
'py': ('https://docs.python.org/3/', None),
14-
'urllib3': ('https://urllib3.readthedocs.io/en/1.26.13/', None),
15-
})
12+
intersphinx_mapping.update(
13+
{
14+
"py": ("https://docs.python.org/3/", None),
15+
"urllib3": ("https://urllib3.readthedocs.io/en/1.26.13/", None),
16+
}
17+
)
1618

1719

1820
linkcheck_anchors = True
1921
linkcheck_ignore = []
2022

2123
# Disable version chooser.
22-
html_context.update({
23-
"display_version": False,
24-
"current_version": None,
25-
"versions": [],
26-
})
24+
html_context.update(
25+
{
26+
"display_version": False,
27+
"current_version": None,
28+
"versions": [],
29+
}
30+
)
2731

2832
rst_prolog = """
2933
.. |nbsp| unicode:: 0xA0

pyproject.toml

Lines changed: 100 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,102 @@
11
[tool.mypy]
2+
mypy_path = "src"
3+
packages = [
4+
"crate",
5+
]
6+
exclude = [
7+
]
8+
check_untyped_defs = true
9+
explicit_package_bases = true
10+
ignore_missing_imports = true
11+
implicit_optional = true
12+
install_types = true
13+
namespace_packages = true
14+
non_interactive = true
215

3-
# Needed until `mypy-0.990` for `ConverterDefinition` in `converter.py`.
4-
# https://github.com/python/mypy/issues/731#issuecomment-1260976955
5-
enable_recursive_aliases = true
16+
17+
[tool.ruff]
18+
line-length = 80
19+
20+
extend-exclude = [
21+
"/example_*",
22+
]
23+
24+
lint.select = [
25+
# Builtins
26+
"A",
27+
# Bugbear
28+
"B",
29+
# comprehensions
30+
"C4",
31+
# Pycodestyle
32+
"E",
33+
# eradicate
34+
"ERA",
35+
# Pyflakes
36+
"F",
37+
# isort
38+
"I",
39+
# pandas-vet
40+
"PD",
41+
# return
42+
"RET",
43+
# Bandit
44+
"S",
45+
# print
46+
"T20",
47+
"W",
48+
# flake8-2020
49+
"YTT",
50+
]
51+
52+
lint.extend-ignore = [
53+
# Unnecessary variable assignment before `return` statement
54+
"RET504",
55+
# Unnecessary `elif` after `return` statement
56+
"RET505",
57+
]
58+
59+
lint.per-file-ignores."example_*" = [
60+
"ERA001", # Found commented-out code
61+
"T201", # Allow `print`
62+
]
63+
lint.per-file-ignores."devtools/*" = [
64+
"T201", # Allow `print`
65+
]
66+
lint.per-file-ignores."examples/*" = [
67+
"ERA001", # Found commented-out code
68+
"T201", # Allow `print`
69+
]
70+
lint.per-file-ignores."tests/*" = [
71+
"S106", # Possible hardcoded password assigned to argument: "password"
72+
"S311", # Standard pseudo-random generators are not suitable for cryptographic purposes
73+
]
74+
75+
76+
# ===================
77+
# Tasks configuration
78+
# ===================
79+
80+
[tool.poe.tasks]
81+
82+
check = [
83+
"lint",
84+
"test",
85+
]
86+
87+
format = [
88+
{ cmd = "ruff format ." },
89+
# Configure Ruff not to auto-fix (remove!):
90+
# unused imports (F401), unused variables (F841), `print` statements (T201), and commented-out code (ERA001).
91+
{ cmd = "ruff check --fix --ignore=ERA --ignore=F401 --ignore=F841 --ignore=T20 --ignore=ERA001 ." },
92+
]
93+
94+
lint = [
95+
{ cmd = "ruff format --check ." },
96+
{ cmd = "ruff check ." },
97+
{ cmd = "mypy" },
98+
]
99+
100+
test = [
101+
{ cmd = "bin/test" },
102+
]

setup.cfg

Lines changed: 0 additions & 2 deletions
This file was deleted.

setup.py

Lines changed: 57 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -19,78 +19,84 @@
1919
# with Crate these terms will supersede the license and you may use the
2020
# software solely pursuant to the terms of the relevant commercial agreement.
2121

22-
from setuptools import setup, find_packages
2322
import os
2423
import re
2524

25+
from setuptools import find_packages, setup
26+
2627

2728
def read(path):
2829
with open(os.path.join(os.path.dirname(__file__), path)) as f:
2930
return f.read()
3031

3132

32-
long_description = read('README.rst')
33+
long_description = read("README.rst")
3334
versionf_content = read("src/crate/client/__init__.py")
3435
version_rex = r'^__version__ = [\'"]([^\'"]*)[\'"]$'
3536
m = re.search(version_rex, versionf_content, re.M)
3637
if m:
3738
version = m.group(1)
3839
else:
39-
raise RuntimeError('Unable to find version string')
40+
raise RuntimeError("Unable to find version string")
4041

4142
setup(
42-
name='crate',
43+
name="crate",
4344
version=version,
44-
url='https://github.com/crate/crate-python',
45-
author='Crate.io',
46-
author_email='office@crate.io',
47-
package_dir={'': 'src'},
48-
description='CrateDB Python Client',
45+
url="https://github.com/crate/crate-python",
46+
author="Crate.io",
47+
author_email="office@crate.io",
48+
package_dir={"": "src"},
49+
description="CrateDB Python Client",
4950
long_description=long_description,
50-
long_description_content_type='text/x-rst',
51-
platforms=['any'],
52-
license='Apache License 2.0',
53-
keywords='cratedb db api dbapi database sql http rdbms olap',
54-
packages=find_packages('src'),
55-
namespace_packages=['crate'],
51+
long_description_content_type="text/x-rst",
52+
platforms=["any"],
53+
license="Apache License 2.0",
54+
keywords="cratedb db api dbapi database sql http rdbms olap",
55+
packages=find_packages("src"),
56+
namespace_packages=["crate"],
5657
install_requires=[
57-
'urllib3<2.3',
58-
'verlib2==0.2.0',
58+
"urllib3<2.3",
59+
"verlib2==0.2.0",
5960
],
60-
extras_require=dict(
61-
test=['tox>=3,<5',
62-
'zope.testing>=4,<6',
63-
'zope.testrunner>=5,<7',
64-
'zc.customdoctests>=1.0.1,<2',
65-
'backports.zoneinfo<1; python_version<"3.9"',
66-
'certifi',
67-
'createcoverage>=1,<2',
68-
'stopit>=1.1.2,<2',
69-
'flake8>=4,<8',
70-
'pytz',
71-
],
72-
doc=['sphinx>=3.5,<9',
73-
'crate-docs-theme>=0.26.5'],
74-
),
75-
python_requires='>=3.6',
76-
package_data={'': ['*.txt']},
61+
extras_require={
62+
"doc": [
63+
"crate-docs-theme>=0.26.5",
64+
"sphinx>=3.5,<9",
65+
],
66+
"test": [
67+
'backports.zoneinfo<1; python_version<"3.9"',
68+
"certifi",
69+
"createcoverage>=1,<2",
70+
"mypy<1.14",
71+
"poethepoet<0.30",
72+
"ruff<0.8",
73+
"stopit>=1.1.2,<2",
74+
"tox>=3,<5",
75+
"pytz",
76+
"zc.customdoctests>=1.0.1,<2",
77+
"zope.testing>=4,<6",
78+
"zope.testrunner>=5,<7",
79+
],
80+
},
81+
python_requires=">=3.6",
82+
package_data={"": ["*.txt"]},
7783
classifiers=[
78-
'Development Status :: 5 - Production/Stable',
79-
'Intended Audience :: Developers',
80-
'License :: OSI Approved :: Apache Software License',
81-
'Operating System :: OS Independent',
82-
'Programming Language :: Python',
83-
'Programming Language :: Python :: 3',
84-
'Programming Language :: Python :: 3.6',
85-
'Programming Language :: Python :: 3.7',
86-
'Programming Language :: Python :: 3.8',
87-
'Programming Language :: Python :: 3.9',
88-
'Programming Language :: Python :: 3.10',
89-
'Programming Language :: Python :: 3.11',
90-
'Programming Language :: Python :: 3.12',
91-
'Programming Language :: Python :: 3.13',
92-
'Programming Language :: Python :: Implementation :: CPython',
93-
'Programming Language :: Python :: Implementation :: PyPy',
94-
'Topic :: Database'
84+
"Development Status :: 5 - Production/Stable",
85+
"Intended Audience :: Developers",
86+
"License :: OSI Approved :: Apache Software License",
87+
"Operating System :: OS Independent",
88+
"Programming Language :: Python",
89+
"Programming Language :: Python :: 3",
90+
"Programming Language :: Python :: 3.6",
91+
"Programming Language :: Python :: 3.7",
92+
"Programming Language :: Python :: 3.8",
93+
"Programming Language :: Python :: 3.9",
94+
"Programming Language :: Python :: 3.10",
95+
"Programming Language :: Python :: 3.11",
96+
"Programming Language :: Python :: 3.12",
97+
"Programming Language :: Python :: 3.13",
98+
"Programming Language :: Python :: Implementation :: CPython",
99+
"Programming Language :: Python :: Implementation :: PyPy",
100+
"Topic :: Database",
95101
],
96102
)

src/crate/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
# this is a namespace package
2323
try:
2424
import pkg_resources
25+
2526
pkg_resources.declare_namespace(__name__)
2627
except ImportError:
2728
import pkgutil
29+
2830
__path__ = pkgutil.extend_path(__path__, __name__)

src/crate/client/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
from .exceptions import Error
2424

2525
__all__ = [
26-
connect,
27-
Error,
26+
"connect",
27+
"Error",
2828
]
2929

3030
# version string read from setup.py using a regex. Take care not to break the

0 commit comments

Comments
 (0)