Skip to content

Commit

Permalink
Merge pull request #243 from Aiven-Open/joelynch/config-files
Browse files Browse the repository at this point in the history
Migrate mypy and ruff config to pyproject.toml
  • Loading branch information
aris-aiven authored Oct 19, 2024
2 parents d76fb8f + 3d89db7 commit 1263a72
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 259 deletions.
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ repos:
hooks:
# Run the formatter.
- id: ruff-format
args: [--config=ruff.toml]

- repo: https://github.com/timothycrosley/isort
rev: 5.12.0
Expand Down
3 changes: 2 additions & 1 deletion astacus/common/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ def wrap(self, i: Sequence[T]) -> Iterator[T]:
self.add_total(len(i))
except TypeError:
# Can't compute progress for this iterator
return i
yield from i
return None

for item in i:
yield item
Expand Down
94 changes: 0 additions & 94 deletions mypy.ini

This file was deleted.

168 changes: 167 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ classifiers=[
"Intended Audience :: System Administrators",
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Database :: Database Engines/Servers",
"Topic :: Software Development :: Libraries",
]
Expand Down Expand Up @@ -101,7 +102,7 @@ dev = [
"pytest-timeout==2.1.0",
"pytest-watch==4.2.0",
"pytest==7.2.2",
"mypy==1.9.0",
"mypy==1.11.2",
# Types for things that don't seem to have them
"types-botocore>=1.0.2",
"types-PyYAML>=6.0.12.2",
Expand Down Expand Up @@ -148,3 +149,168 @@ source = [
"astacus",
"tests"
]

[tool.mypy]
python_version = "3.12"
plugins = ["pydantic.mypy"]
exclude = [
"setup.py",
"vendor/",
"venv/",
"astacus/proto/",
]
show_error_codes = true
warn_unreachable = true
no_implicit_reexport = true
warn_redundant_casts = true
warn_unused_ignores = true
disallow_subclassing_any = true

[tool.pydantic-mypy]
# even if Config.extra != forbid, prevent extra args
init_forbid_extra = true
# validate types on __init__, do not go for type coercion
init_typed = true
# We don't want use of indirect population without explicit alias
warn_required_dynamic_aliases = true

[[tool.mypy.overrides]]
module = "cassandra.*,graphlib,kazoo.*,systemd"
ignore_missing_imports = true

[[tool.mypy.overrides]]
module = "google.protobuf"
ignore_errors = true

[[tool.mypy.overrides]]
module = "astacus.common.cassandra,astacus.coordinator.cassandra,astacus.node.cassandra"
disallow_incomplete_defs = true
disallow_untyped_defs = true

[tool.ruff]
target-version = "py311"
line-length = 125
force-exclude = true

[tool.ruff.lint]
# A list of rule codes or prefixes to enable, in addition to those specified by 'select'.
extend-select = [
# flake8-bugbear
# mutable-argument-default - Do not use mutable data structures for argument defaults.
"B006",
# pydocstyle
"D",
# flake8-datetimez
"DTZ",
# pycodestyle
"E",
# pyflakes
"F",
# flake8-logging-format
# logging-warn - Logging statement uses warn instead of warning.
"G010",
# isort
"I",
# flake8-no-pep420
"INP",
# flake8-pytest-style
"PT",
# Ruff-specific rules
# explicit-f-string-type-conversion - Use explicit conversion flag.
"RUF010",
# unused-noqa - Unused 'noqa' directive.
"RUF100",
# flake8-tidy-imports
"TID",
# pyupgrade
"UP",
# Open file with context handler.
"SIM115",
]
# A list of rule codes or prefixes to ignore.
ignore = [
# pydocstyle
# undocumented-public-module - Missing docstring in public module.
"D100",
# undocumented-public-class - Missing docstring in public class.
"D101",
# undocumented-public-method - Missing docstring in public method.
"D102",
# undocumented-public-function - Missing docstring in public function.
"D103",
# undocumented-public-package - Missing docstring in public package.
"D104",
# undocumented-magic-method - Missing docstring in magic method.
"D105",
# undocumented-public-nested-class - Missing docstring in public nested class.
"D106",
# undocumented-public-init - Missing docstring in __init__.
"D107",
# one-blank-line-before-class - 1 blank line required before class docstring.
# This configuration can't be enabled as it's incompatible with 'D211' (no-blank-line-before-class).
"D203",
# blank-line-after-summary - 1 blank line required between summary line and description.
# This configuration can't be enabled because automatic fix available is minimal.
"D205",
# non-imperative-mood - First line of docstring should be in imperative mood: "{first_line}".
"D401",
# one-blank-line-after-class - 1 blank line required after class docstring.
"D402",
# docstring-starts-with-this - First word of the docstring should not be "This".
"D404",
# multi-line-summary-second-line - Multi-line docstring summary should start at the second line.
# This configuration can't be enabled as it's incompatible with 'D212' (multi-line-summary-first-line).
"D213",
# undocumented-param - Missing argument description in the docstring for {definition}: {name}.
"D417",
# pycodestyle
# bare-except - Do not use bare except.
"E722",
# line-too-long - Line too long ({width} > {limit}).
"E501",
# flake8-pytest-style
# pytest-missing-fixture-name-underscore - Fixture '{function}' does not return anything, add leading underscore.
"PT004",
# pytest-incorrect-fixture-name-underscore - Fixture '{function}' returns a value, remove leading underscore.
"PT005",
# pytest-parametrize-values-wrong-type - Wrong values type in '@pytest.mark.parametrize' expected '{values}' of '{row}'.
"PT007",
# pytest-raises-too-broad - 'pytest.raises({exception})' is too broad, set the 'match' parameter or use a more specific exception.
"PT011",
# pytest-raises-with-multiple-statements - 'pytest.raises()' block should contain a single simple statement.
"PT012",
# pytest-incorrect-pytest-import - Found incorrect import of pytest, use simple 'import pytest' instead.
"PT013",
# pytest-assert-in-except - Found assertion on exception '{name}' in 'except' block, use 'pytest.raises()' instead.
"PT017",
# pytest-fixture-param-without-value - Fixture '{name}' without value is injected as parameter, use '@pytest.mark.usefixtures' instead.
"PT019",
# pyupgrade
# printf-string-formatting - Use format specifiers instead of percent format.
"UP031",
# f-string - Use f-string instead of 'format' call.
# This configuration can't be enabled since certain operations in f-strings are forbidden.
# For further details, refer to: 'ci/check_string_formats.py'.
"UP032",
]
# A list of rule codes or prefixes for which unsafe fixes should be considered safe.
extend-safe-fixes = [
# pydocstyle
"D"
]

[tool.ruff.lint.pydocstyle]
convention = "google"

[tool.ruff.lint.isort]
# Combines as imports on the same line.
combine-as-imports = true
# Whether to place import from imports before straight imports when sorting.
from-first = true
# The number of lines to place between "direct" and 'import from' imports.
lines-between-types = 1
# Put all imports into the same section bucket.
# This configuration breaks the Python convention.
no-sections = true
# Order imports by type, which is determined by case, in addition to alphabetically.
order-by-type = false
Loading

0 comments on commit 1263a72

Please sign in to comment.