Skip to content

QA and CI: Format code using ruff. Validate using ruff and mypy. #660

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
echo "Invoking tests with CrateDB ${CRATEDB_VERSION}"

# Run linter.
flake8 src bin
poe lint

# Run tests.
coverage run bin/test -vvv
Expand Down
19 changes: 18 additions & 1 deletion DEVELOP.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ see, for example, `useful command-line options for zope-testrunner`_.

Run all tests::

bin/test
poe test

Run specific tests::

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


Formatting and linting code
===========================

To use Ruff for code formatting, according to the standards configured in
``pyproject.toml``, use::

poe format

To lint the code base using Ruff and mypy, use::

poe lint

Linting and software testing, all together now::

poe check


Renew certificates
==================

Expand Down
2 changes: 1 addition & 1 deletion bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function main() {
}

function lint() {
flake8 "$@" src bin
poe lint
}

main
24 changes: 14 additions & 10 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ruff: noqa: F403, F405
from crate.theme.rtd.conf.python import *


if "sphinx.ext.intersphinx" not in extensions:
extensions += ["sphinx.ext.intersphinx"]

Expand All @@ -9,21 +9,25 @@
intersphinx_mapping = {}


intersphinx_mapping.update({
'py': ('https://docs.python.org/3/', None),
'urllib3': ('https://urllib3.readthedocs.io/en/1.26.13/', None),
})
intersphinx_mapping.update(
{
"py": ("https://docs.python.org/3/", None),
"urllib3": ("https://urllib3.readthedocs.io/en/1.26.13/", None),
}
)


linkcheck_anchors = True
linkcheck_ignore = []

# Disable version chooser.
html_context.update({
"display_version": False,
"current_version": None,
"versions": [],
})
html_context.update(
{
"display_version": False,
"current_version": None,
"versions": [],
}
)

rst_prolog = """
.. |nbsp| unicode:: 0xA0
Expand Down
103 changes: 100 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,102 @@
[tool.mypy]
mypy_path = "src"
packages = [
"crate",
]
exclude = [
]
check_untyped_defs = true
explicit_package_bases = true
ignore_missing_imports = true
implicit_optional = true
install_types = true
namespace_packages = true
non_interactive = true

# Needed until `mypy-0.990` for `ConverterDefinition` in `converter.py`.
# https://github.com/python/mypy/issues/731#issuecomment-1260976955
enable_recursive_aliases = true

[tool.ruff]
line-length = 80

extend-exclude = [
"/example_*",
]

lint.select = [
# Builtins
"A",
# Bugbear
"B",
# comprehensions
"C4",
# Pycodestyle
"E",
# eradicate
"ERA",
# Pyflakes
"F",
# isort
"I",
# pandas-vet
"PD",
# return
"RET",
# Bandit
"S",
# print
"T20",
"W",
# flake8-2020
"YTT",
]

lint.extend-ignore = [
# Unnecessary variable assignment before `return` statement
"RET504",
# Unnecessary `elif` after `return` statement
"RET505",
]

lint.per-file-ignores."example_*" = [
"ERA001", # Found commented-out code
"T201", # Allow `print`
]
lint.per-file-ignores."devtools/*" = [
"T201", # Allow `print`
]
lint.per-file-ignores."examples/*" = [
"ERA001", # Found commented-out code
"T201", # Allow `print`
]
lint.per-file-ignores."tests/*" = [
"S106", # Possible hardcoded password assigned to argument: "password"
"S311", # Standard pseudo-random generators are not suitable for cryptographic purposes
]


# ===================
# Tasks configuration
# ===================

[tool.poe.tasks]

check = [
"lint",
"test",
]

format = [
{ cmd = "ruff format ." },
# Configure Ruff not to auto-fix (remove!):
# unused imports (F401), unused variables (F841), `print` statements (T201), and commented-out code (ERA001).
{ cmd = "ruff check --fix --ignore=ERA --ignore=F401 --ignore=F841 --ignore=T20 --ignore=ERA001 ." },
]

lint = [
{ cmd = "ruff format --check ." },
{ cmd = "ruff check ." },
{ cmd = "mypy" },
]

test = [
{ cmd = "bin/test" },
]
2 changes: 0 additions & 2 deletions setup.cfg

This file was deleted.

108 changes: 57 additions & 51 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,78 +19,84 @@
# with Crate these terms will supersede the license and you may use the
# software solely pursuant to the terms of the relevant commercial agreement.

from setuptools import setup, find_packages
import os
import re

from setuptools import find_packages, setup


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


long_description = read('README.rst')
long_description = read("README.rst")
versionf_content = read("src/crate/client/__init__.py")
version_rex = r'^__version__ = [\'"]([^\'"]*)[\'"]$'
m = re.search(version_rex, versionf_content, re.M)
if m:
version = m.group(1)
else:
raise RuntimeError('Unable to find version string')
raise RuntimeError("Unable to find version string")

setup(
name='crate',
name="crate",
version=version,
url='https://github.com/crate/crate-python',
author='Crate.io',
author_email='office@crate.io',
package_dir={'': 'src'},
description='CrateDB Python Client',
url="https://github.com/crate/crate-python",
author="Crate.io",
author_email="office@crate.io",
package_dir={"": "src"},
description="CrateDB Python Client",
long_description=long_description,
long_description_content_type='text/x-rst',
platforms=['any'],
license='Apache License 2.0',
keywords='cratedb db api dbapi database sql http rdbms olap',
packages=find_packages('src'),
namespace_packages=['crate'],
long_description_content_type="text/x-rst",
platforms=["any"],
license="Apache License 2.0",
keywords="cratedb db api dbapi database sql http rdbms olap",
packages=find_packages("src"),
namespace_packages=["crate"],
install_requires=[
'urllib3<2.3',
'verlib2==0.2.0',
"urllib3<2.3",
"verlib2==0.2.0",
],
extras_require=dict(
test=['tox>=3,<5',
'zope.testing>=4,<6',
'zope.testrunner>=5,<7',
'zc.customdoctests>=1.0.1,<2',
'backports.zoneinfo<1; python_version<"3.9"',
'certifi',
'createcoverage>=1,<2',
'stopit>=1.1.2,<2',
'flake8>=4,<8',
'pytz',
],
doc=['sphinx>=3.5,<9',
'crate-docs-theme>=0.26.5'],
),
python_requires='>=3.6',
package_data={'': ['*.txt']},
extras_require={
"doc": [
"crate-docs-theme>=0.26.5",
"sphinx>=3.5,<9",
],
"test": [
'backports.zoneinfo<1; python_version<"3.9"',
"certifi",
"createcoverage>=1,<2",
"mypy<1.14",
"poethepoet<0.30",
"ruff<0.8",
"stopit>=1.1.2,<2",
"tox>=3,<5",
"pytz",
"zc.customdoctests>=1.0.1,<2",
"zope.testing>=4,<6",
"zope.testrunner>=5,<7",
],
},
python_requires=">=3.6",
package_data={"": ["*.txt"]},
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'License :: OSI Approved :: Apache Software License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: 3.13',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Topic :: Database'
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"Topic :: Database",
],
)
2 changes: 2 additions & 0 deletions src/crate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
# this is a namespace package
try:
import pkg_resources

pkg_resources.declare_namespace(__name__)
except ImportError:
import pkgutil

__path__ = pkgutil.extend_path(__path__, __name__)
4 changes: 2 additions & 2 deletions src/crate/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
from .exceptions import Error

__all__ = [
connect,
Error,
"connect",
"Error",
]

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