Skip to content

Commit

Permalink
Chore: Format and lint code using Ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed Aug 27, 2024
1 parent b1e4e37 commit e1f009e
Show file tree
Hide file tree
Showing 41 changed files with 1,307 additions and 1,218 deletions.
32 changes: 19 additions & 13 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from crate.theme.rtd.conf.sqlalchemy_cratedb import *
from crate.theme.rtd.conf.sqlalchemy_cratedb import * # noqa: F403

# Fallback guards, when parent theme does not introduce them.
if "html_theme_options" not in globals():
Expand All @@ -11,21 +11,27 @@
sitemap_url_scheme = "{link}"

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

intersphinx_mapping.update({
'py': ('https://docs.python.org/3/', None),
'sa': ('https://docs.sqlalchemy.org/en/20/', None),
'dask': ('https://docs.dask.org/en/stable/', None),
'pandas': ('https://pandas.pydata.org/docs/', None),
})
intersphinx_mapping.update(
{
"py": ("https://docs.python.org/3/", None),
"sa": ("https://docs.sqlalchemy.org/en/20/", None),
"dask": ("https://docs.dask.org/en/stable/", None),
"pandas": ("https://pandas.pydata.org/docs/", None),
}
)

linkcheck_anchors = True
linkcheck_ignore = [r"https://github.com/crate/cratedb-examples/blob/main/by-language/python-sqlalchemy/.*"]
linkcheck_ignore = [
r"https://github.com/crate/cratedb-examples/blob/main/by-language/python-sqlalchemy/.*"
]

rst_prolog = """
.. |nbsp| unicode:: 0xA0
Expand Down
216 changes: 112 additions & 104 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ requires = [
"versioningit",
]

[tool.versioningit.vcs]
method = "git"
default-tag = "0.0.0"

[project]
name = "sqlalchemy-cratedb"
description = "SQLAlchemy dialect for CrateDB."
Expand Down Expand Up @@ -84,34 +80,32 @@ dynamic = [
"version",
]
dependencies = [
'backports.zoneinfo<1; python_version < "3.9"',
"crate==1.0.0dev0",
"backports.zoneinfo<1; python_version<'3.9'",
"crate==1.0.0.dev0",
"geojson<4,>=2.5",
'importlib-resources; python_version < "3.9"',
"importlib-resources; python_version<'3.9'",
"sqlalchemy<2.1,>=1",
"verlib2==0.2",
]
[project.optional-dependencies]
all = [
optional-dependencies.all = [
"sqlalchemy-cratedb[vector]",
]
develop = [
"black<25",
optional-dependencies.develop = [
"mypy<1.12",
"poethepoet<0.28",
"pyproject-fmt<2.3",
"ruff<0.7",
"validate-pyproject<0.20",
]
doc = [
optional-dependencies.doc = [
"crate-docs-theme>=0.26.5",
"sphinx>=3.5,<9",
]
release = [
optional-dependencies.release = [
"build<2",
"twine<6",
]
test = [
optional-dependencies.test = [
"cratedb-toolkit[testing]",
"dask[dataframe]",
"pandas<2.3",
Expand All @@ -120,54 +114,81 @@ test = [
"pytest-cov<6",
"pytest-mock<4",
]
vector = [
optional-dependencies.vector = [
"numpy",
]
[project.urls]
changelog = "https://github.com/crate/sqlalchemy-cratedb/blob/main/CHANGES.md"
documentation = "https://cratedb.com/docs/sqlalchemy-cratedb/"
homepage = "https://cratedb.com/docs/sqlalchemy-cratedb/"
repository = "https://github.com/crate/sqlalchemy-cratedb"
[project.entry-points."sqlalchemy.dialects"]
crate = "sqlalchemy_cratedb:dialect"
urls.changelog = "https://github.com/crate/sqlalchemy-cratedb/blob/main/CHANGES.md"
urls.documentation = "https://cratedb.com/docs/sqlalchemy-cratedb/"
urls.homepage = "https://cratedb.com/docs/sqlalchemy-cratedb/"
urls.repository = "https://github.com/crate/sqlalchemy-cratedb"
entry-points."sqlalchemy.dialects".crate = "sqlalchemy_cratedb:dialect"

[tool.black]
line-length = 100

[tool.coverage.paths]
source = [
"src/",
[tool.ruff]
line-length = 100

extend-exclude = [
]

[tool.coverage.run]
branch = false
omit = [
"tests/*",
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",
]

[tool.coverage.report]
fail_under = 0
show_missing = true
exclude_lines = [
"# pragma: no cover",
"raise NotImplemented"
lint.extend-ignore = [
# zip() without an explicit strict= parameter
"B905",
# Unnecessary generator (rewrite as a `dict` comprehension)
"C402",
# Unnecessary `map` usage (rewrite using a `set` comprehension)
"C417",
# df is a bad variable name. Be kinder to your future self.
"PD901",
# Unnecessary variable assignment before `return` statement
"RET504",
# Unnecessary `elif` after `return` statement
"RET505",
# Probable insecure usage of temporary file or directory
"S108",
# Possible SQL injection vector through string-based query construction
"S608",
]

[tool.mypy]
mypy_path = "src"
packages = ["sqlalchemy_cratedb"]
exclude = [
lint.per-file-ignores."examples/*" = [
"T201", # Allow `print`
]

lint.per-file-ignores."tests/*" = [
"S101", # Allow use of `assert`, and `print`
"S608", # Possible SQL injection vector through string-based query construction
"W291", # Trailing whitespace
"W293", # Blank line contains whitespace
]
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.pytest.ini_options]
addopts = """
Expand All @@ -179,7 +200,7 @@ log_level = "DEBUG"
log_cli_level = "DEBUG"
log_format = "%(asctime)-15s [%(name)-36s] %(levelname)-8s: %(message)s"
pythonpath = [
"src"
"src",
]
testpaths = [
"examples",
Expand All @@ -194,60 +215,44 @@ xfail_strict = true
markers = [
]

[tool.ruff]
line-length = 100

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

extend-ignore = [
# zip() without an explicit strict= parameter
"B905",
# df is a bad variable name. Be kinder to your future self.
"PD901",
# Unnecessary variable assignment before `return` statement
"RET504",
# Unnecessary `elif` after `return` statement
"RET505",
# Probable insecure usage of temporary file or directory
"S108",
[tool.coverage.run]
branch = false
omit = [
"tests/*",
]

extend-exclude = [
[tool.coverage.report]
fail_under = 0
show_missing = true
exclude_lines = [
"# pragma: no cover",
"raise NotImplemented",
]

[tool.ruff.per-file-ignores]
"*/tests/*" = [
"S101", # Allow use of `assert`, and `print`.
"S608", # Possible SQL injection vector through string-based query construction.
[tool.mypy]
mypy_path = "src"
packages = [ "sqlalchemy_cratedb" ]
exclude = [
]
"examples/*" = ["T201"] # Allow `print`
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.versioningit.vcs]
method = "git"
default-tag = "0.0.0"

# ===================
# Tasks configuration
Expand All @@ -256,23 +261,26 @@ extend-exclude = [
[tool.poe.tasks]

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

format = [
{ cmd = "black ." },
# Configure Ruff not to auto-fix (remove!):
# unused imports (F401), unused variables (F841), `print` statements (T201), and commented-out code (ERA001).
{ cmd = "ruff --fix --ignore=ERA --ignore=F401 --ignore=F841 --ignore=T20 --ignore=ERA001 ." },
# Format project metadata.
{ cmd = "pyproject-fmt --keep-full-version pyproject.toml" },

# Format code.
# Configure Ruff not to auto-fix a few items that are useful in workbench mode.
# e.g.: unused imports (F401), unused variables (F841), `print` statements (T201), commented-out code (ERA001)
{ cmd = "ruff format" },
{ cmd = "ruff check --fix --ignore=ERA --ignore=F401 --ignore=F841 --ignore=T20 --ignore=ERA001" },
]

lint = [
{ cmd = "ruff ." },
{ cmd = "black --check ." },
{ cmd = "ruff format --check" },
{ cmd = "ruff check" },
{ cmd = "validate-pyproject pyproject.toml" },
{ cmd = "mypy" },
# { cmd = "mypy" },
]

release = [
Expand Down
11 changes: 7 additions & 4 deletions src/sqlalchemy_cratedb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from .compat.api13 import monkeypatch_add_exec_driver_sql
from .dialect import dialect
from .predicate import match
from .sa_version import SA_1_4, SA_2_0, SA_VERSION
from .sa_version import SA_1_4, SA_VERSION
from .support import insert_bulk
from .type.array import ObjectArray
from .type.geo import Geopoint, Geoshape
Expand All @@ -34,7 +34,8 @@
import warnings

# SQLAlchemy 1.3 is effectively EOL.
SA13_DEPRECATION_WARNING = textwrap.dedent("""
SA13_DEPRECATION_WARNING = textwrap.dedent(
"""
WARNING: SQLAlchemy 1.3 is effectively EOL.
SQLAlchemy 1.3 is EOL since 2023-01-27.
Expand All @@ -43,8 +44,9 @@
- https://docs.sqlalchemy.org/en/14/changelog/migration_14.html
- https://docs.sqlalchemy.org/en/20/changelog/migration_20.html
""".lstrip("\n"))
warnings.warn(message=SA13_DEPRECATION_WARNING, category=DeprecationWarning)
""".lstrip("\n")
)
warnings.warn(message=SA13_DEPRECATION_WARNING, category=DeprecationWarning, stacklevel=2)

# SQLAlchemy 1.3 does not have the `exec_driver_sql` method, so add it.
monkeypatch_add_exec_driver_sql()
Expand All @@ -59,4 +61,5 @@
ObjectType,
match,
knn_match,
insert_bulk,
]
Loading

0 comments on commit e1f009e

Please sign in to comment.