Skip to content

Commit

Permalink
ci: Replace isort, black and pylint with Ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
zusorio committed Dec 18, 2024
1 parent d209180 commit c247393
Show file tree
Hide file tree
Showing 13 changed files with 188 additions and 280 deletions.
42 changes: 5 additions & 37 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,39 +27,12 @@ repos:
- id: end-of-file-fixer
- id: fix-byte-order-marker
- id: trailing-whitespace
- repo: https://github.com/pylint-dev/pylint
rev: v3.3.1
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.2
hooks:
- id: pylint
additional_dependencies:
- mccabe
require_serial: false
args:
- -rn
- -sn
- -dfixme
- -dduplicate-code
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.10.0
hooks:
- id: black
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
- repo: https://github.com/PyCQA/docformatter
rev: eb1df347edd128b30cd3368dddc3aa65edcfac38
hooks:
- id: docformatter
additional_dependencies:
- docformatter[tomli]
- repo: https://github.com/PyCQA/pydocstyle
rev: 6.3.0
hooks:
- id: pydocstyle
exclude: '^tests/'
additional_dependencies:
- pydocstyle[toml]
- id: ruff
args: [--extend-ignore=FIX, --fix]
- id: ruff-format
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.2
hooks:
Expand Down Expand Up @@ -131,11 +104,6 @@ repos:
stages: [commit-msg]
additional_dependencies:
- '@commitlint/config-conventional'
- repo: https://github.com/asottile/pyupgrade
rev: v3.17.0
hooks:
- id: pyupgrade
args: ['--py311-plus']
- repo: https://github.com/hadolint/hadolint
rev: v2.12.0
hooks:
Expand Down
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
~ SPDX-License-Identifier: Apache-2.0
-->

<!--
SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors
SPDX-License-Identifier: Apache-2.0
-->

# MBSE Docker images

Expand Down
2 changes: 1 addition & 1 deletion capella/install_dropins.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def extract_repositories_and_install_ius(dropins: dict[str, t.Any]) -> None:
if not dropin_slug:
continue

if not dropin_slug in dropins:
if dropin_slug not in dropins:
raise KeyError(
f"Dropin '{dropin_slug}' not found in list of supported dropins."
)
Expand Down
2 changes: 1 addition & 1 deletion capella/setup/disable_semantic_browser_auto_refresh.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def _replace_content_in_line_of_file(
sys.stdout.write(line)
continue
if old in line:
line = line.replace(old, new)
line = line.replace(old, new) # noqa: PLW2901
logger.info(
"Replaced `%s` with `%s` in line number: `%d`",
old,
Expand Down
188 changes: 79 additions & 109 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ build-backend = "setuptools.build_meta"
dynamic = ["version"]

name = "capella-dockerimages"
requires-python = ">=3.11, <3.12"
requires-python = ">=3.11, <3.13"
license = { text = "Apache-2.0" }
authors = [{ name = "DB InfraGO AG" }]
dependencies = ["PyYAML", "requests", "prometheus_client"]
Expand All @@ -20,18 +20,91 @@ Homepage = "https://github.com/DSD-DBS/capella-dockerimages"
[project.optional-dependencies]
test = ["docker>=6.1.0", "pytest", "capellambse[decl]", "chardet"]
dev = [
"black",
"isort",
"ruff",
"mypy",
"pylint",
"types-PyYAML",
"types-lxml",
"types-requests",
]

[tool.black]
[tool.ruff]
line-length = 79
target-version = ["py311"]

[tool.ruff.lint]
extend-select = [
"ARG", # flake8-unused-arguments
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"C90", # mccabe
"D", # pydocstyle
"DTZ", # flake8-datetimez
"ERA", # eradicate
"FA", # flake8-future-annotations
"FBT", # flake8-boolean-trap
"FIX", # flake8-fixme
"FURB", # refurb
"G", # flake8-logging-format
"I", # isort
"ICN", # flake8-import-conventions
"ISC001", # "Implicitly concatenated string literals on one line"
"ISC003", # "Explicitly concatenated string should be implicitly concatenated"
"LOG", # flake8-logging
"PIE", # flake8-pie
"PL", # pylint
"PT", # flake8-pytest-style
"RET", # flake8-return
"RUF", # ruff
"SIM", # flake8-simplify
"TC005", # "Found empty type-checking block"
"T1", # flake8-debugger
"UP", # pyupgrade
"YTT", # flake8-2020
]
extend-ignore = [
"D1", # Missing docstring in _
"D201", # No blank lines allowed before function docstring # auto-formatting
"D202", # No blank lines allowed after function docstring # auto-formatting
"D203", # 1 blank line required before class docstring # auto-formatting
"D204", # 1 blank line required after class docstring # auto-formatting
"D211", # No blank lines allowed before class docstring # auto-formatting
"D213", # Multi-line docstring summary should start at the second line
"DTZ001", # `tzinfo=None` passed to `datetime.datetime()`
"DTZ005", # `tz=None` passed to `datetime.datetime.now()`
"E402", # Module level import not at top of file
"ERA001", # Remove commented-out code
"F403", # `from _ import *` used; unable to detect undefined names
"F405", # `_` may be undefined, or defined from star imports
"FBT001", # Boolean-typed positional argument in function definition
"FBT002", # Boolean default positional argument in function definition
"LOG002", # Use `__name__` with `logging.getLogger()`
"PLC0414", # Import alias does not rename original package # used for explicit reexports
"PLR0904", # Too many public methods
"PLR0911", # Too many return statements
"PLR0912", # Too many branches
"PLR0913", # Too many arguments in function definition
"PLR0914", # Too many local variables
"PLR0915", # Too many statements
"PLR0916", # Too many Boolean expressions
"PLR0917", # Too many positional arguments
"PLR2004", # Magic value used in comparison
"SIM108", # Use ternary operator instead of `if`-`else`-block
]

[tool.ruff.lint.extend-per-file-ignores]
"__init__.py" = [
"PLE0604", # Invalid object in `__all__`, must contain only strings # false-positive when unpacking imported submodule __all__
]
"tests/test_*.py" = [
"F811", # Redefinition of unused `_` from line _
"PLR2004", # Magic value used in comparison, consider replacing `_` with a constant variable
]

[tool.ruff.lint.pydocstyle]
convention = "numpy"
ignore-decorators = ["typing.overload"]

[tool.ruff.lint.mccabe]
max-complexity = 14

[tool.coverage.run]
branch = true
Expand All @@ -46,13 +119,6 @@ exclude_also = [
]
skip_covered = true

[tool.docformatter]
wrap-descriptions = 72
wrap-summaries = 79

[tool.isort]
profile = 'black'
line_length = 79

[tool.mypy]
check_untyped_defs = true
Expand All @@ -69,102 +135,6 @@ python_version = "3.11"
module = ["docker.*"]
ignore_missing_imports = true

[tool.pydocstyle]
convention = "numpy"
add-select = [
"D212", # Multi-line docstring summary should start at the first line
"D402", # First line should not be the function’s “signature”
"D417", # Missing argument descriptions in the docstring
]
add-ignore = [
"D100", # Missing docstring in public module
"D101", # Missing docstring in public class
"D103", # Missing docstring in public function
"D104", # Missing docstring in public package
"D201", # No blank lines allowed before function docstring # auto-formatting
"D202", # No blank lines allowed after function docstring # auto-formatting
"D203", # 1 blank line required before class docstring # auto-formatting
"D204", # 1 blank line required after class docstring # auto-formatting
"D211", # No blank lines allowed before class docstring # auto-formatting
"D213", # Multi-line docstring summary should start at the second line
]

[tool.pylint.format]
ignore-long-lines = '^\s*(?:(?:__ |\.\. __: )?https?://[^ ]+$|def test_.*|[A-Za-z0-9_\.]+(?: ?:)?$)'

[tool.pylint.master]
init-import = "yes"
load-plugins = ["pylint.extensions.mccabe", "pylint.extensions.bad_builtin"]
max-complexity = 14
max-line-length = 79
extension-pkg-allow-list = ["lxml.builder", "lxml.etree"]


[tool.pylint.messages_control]
disable = [
"broad-except",
"global-statement",
"import-outside-toplevel",
"missing-class-docstring",
"missing-function-docstring",
"missing-module-docstring",
"no-else-break",
"no-else-continue",
"no-else-raise",
"no-else-return",
"protected-access",
"redefined-builtin",
"too-few-public-methods",
"too-many-ancestors",
"too-many-arguments",
"too-many-positional-arguments",
"too-many-boolean-expressions",
"too-many-branches",
"too-many-instance-attributes",
"too-many-lines",
"too-many-locals",
"too-many-public-methods",
"too-many-return-statements",
"too-many-statements",

# Auto-formatting
"bad-indentation",
"inconsistent-quotes",
"line-too-long",
"missing-final-newline",
"mixed-line-endings",
"multiple-imports",
"multiple-statements",
"trailing-newlines",
"trailing-whitespace",
"unexpected-line-ending-format",
"ungrouped-imports",
"wrong-import-order",
"wrong-import-position",

# Handled by mypy
"arguments-differ",
"assignment-from-no-return",
"import-error",
"missing-kwoa",
"no-member",
"no-value-for-parameter",
"redundant-keyword-arg",
"signature-differs",
"syntax-error",
"too-many-function-args",
"unbalanced-tuple-unpacking",
"undefined-variable",
"unexpected-keyword-arg",
]
enable = [
"c-extension-no-member",
"deprecated-pragma",
"use-symbolic-message-instead",
"useless-suppression",
]


[tool.pytest.ini_options]
addopts = """
--strict-config
Expand Down
11 changes: 5 additions & 6 deletions remote/tests/test_metrics.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors
# SPDX-License-Identifier: Apache-2.0
"""Unit tests for metrics."""

import time
import typing as t
from unittest import mock
Expand All @@ -11,15 +12,12 @@

@pytest.fixture(name="idler")
def fixture_idler() -> metrics.IdleTimer:
"""Return an instance of `metrics.IdleTime`"""
"""Return an instance of `metrics.IdleTime`."""
return metrics.IdleTimer()


def print_no_display(*__: t.Any, **_: t.Any) -> mock.MagicMock:
"""
Just print: 'could not open display', the response of xprintidle
when there is no X server.
"""
"""Just print: 'could not open display', the response of xprintidle when there is no X server."""
return mock.MagicMock(stdout="couldn't open display")


Expand Down Expand Up @@ -64,5 +62,6 @@ def test_get_idletime_increases_after_display_is_closed(

second_idletime = idler.get_idletime()

assert isinstance(idletime, float) and isinstance(second_idletime, float)
assert isinstance(idletime, float)
assert isinstance(second_idletime, float)
assert idletime < second_idletime
Loading

0 comments on commit c247393

Please sign in to comment.