Skip to content
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

Introduce ruff #363

Merged
merged 77 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
6df20ce
ci: introduce ruff
sujuka99 Sep 26, 2023
b94737f
ci: exclude snapshots
sujuka99 Sep 26, 2023
0833e1b
ci(ruff): ignore F401 in tests/*/__init__.py
sujuka99 Sep 26, 2023
a4c92a7
ci(ruff): fix order
sujuka99 Sep 26, 2023
c8bd70c
ci(ruff): comment out rules in nursery, remove comment
sujuka99 Sep 26, 2023
c7bb733
ci(ruff): Autofix "D"
sujuka99 Sep 26, 2023
6379c78
ci(ruff): improve comments
sujuka99 Sep 26, 2023
c70873c
ci(ruff-pydocstyle): improve rule selection
sujuka99 Sep 26, 2023
738e21b
ci(ruff): autofix "D"
sujuka99 Sep 26, 2023
11a54a5
chore: fix docstrings flagged by "D"
sujuka99 Sep 26, 2023
53ba27d
ci(ruff-pyupgrade): autofix
sujuka99 Sep 26, 2023
d090ff0
chore: manually fix code flagged by "UP"
sujuka99 Sep 26, 2023
feb6df3
chore: update snapshots
sujuka99 Sep 26, 2023
cc06875
ci(ruff): add rule ignores for "B"
sujuka99 Sep 26, 2023
687f37d
ci(ruff): configure "B"
sujuka99 Sep 26, 2023
1b6e29c
chore: manually fix code flagged by "B"
sujuka99 Sep 26, 2023
1621db1
chore: fix code flagged by "INP"
sujuka99 Sep 26, 2023
d0eefab
chore(ruff): fix code flagged by "BLE"
sujuka99 Sep 26, 2023
301284e
ci(ruff-commas): autofix
sujuka99 Sep 26, 2023
c7b3251
chore(ruff-comprehensions): ignore "C408"
sujuka99 Sep 26, 2023
0c2c7c1
ci(ruff-errmsg): autofix "EM"
sujuka99 Sep 26, 2023
0160c08
ci(ruff-pie): autofix
sujuka99 Sep 26, 2023
dd29e3a
ci(ruff-pie): exclude "PIE804"
sujuka99 Sep 26, 2023
49e9e4a
ci(ruff-pytest): autofix "PT"
sujuka99 Sep 26, 2023
b93c3d8
chore(ruff-pytest): manually fix code flagged by "PT"
sujuka99 Sep 26, 2023
9a8678a
ci(ruff-raise): autofix "RSE"
sujuka99 Sep 26, 2023
f90dd22
ci(ruff-return): autofix "RET"
sujuka99 Sep 26, 2023
68b824b
ci(ruff-simplify): autofix "SIM"
sujuka99 Sep 26, 2023
57fd749
ci(ruff-type-checking): disable "TCH" temporarily
sujuka99 Sep 26, 2023
57d9b50
ci(ruff): remove "ARG"
sujuka99 Sep 26, 2023
4e2dd33
ci(ruff-pathlib): autofix "PTH"
sujuka99 Sep 26, 2023
2d8129e
chore(ruff-pathlib): manually fix code flagged by "PTH"
sujuka99 Sep 26, 2023
07bf0f4
chore(ruff-pygrep): manually fix code flagged by "PGH"
sujuka99 Sep 26, 2023
8664342
ci(ruff-pylint): autofix "PL"
sujuka99 Sep 26, 2023
0d65ea8
ci(ruff): ignore "PLW2901"
sujuka99 Sep 26, 2023
54d4b4e
chore(ruff-pylint): manually fix code flagged by "PL"
sujuka99 Sep 26, 2023
8be0263
ci(ruff-tryceratops): autofix "TRY"
sujuka99 Sep 26, 2023
e73f9ab
chore(ruff-tryceratops): manually fix code flagged by "TRY"
sujuka99 Sep 26, 2023
794c60d
chore(pre-commit): pass pre-commit checks
sujuka99 Sep 26, 2023
d3d430d
Merge remote-tracking branch 'origin/main' into ci/introduce-ruff
sujuka99 Sep 26, 2023
14c3c99
chore: lint
sujuka99 Sep 26, 2023
c272a06
ci(ruff): enable "TCH" partly
sujuka99 Sep 26, 2023
750555f
ci(ruff): enable "TCH002"
sujuka99 Sep 26, 2023
502574b
ci(ruff): configure
sujuka99 Sep 26, 2023
31cd2be
chore: remove leftover file
sujuka99 Sep 26, 2023
9d4a761
ci: update workflow
sujuka99 Sep 26, 2023
25b0c08
chore: pass tests
sujuka99 Sep 26, 2023
0b9f26c
ci(ruff-type-checking): Add "TCH001" with proper config
sujuka99 Sep 27, 2023
bdee94d
style: one-liner
sujuka99 Sep 27, 2023
847d4e9
ci(ruff): Ignore COM812
sujuka99 Sep 27, 2023
5a6c3d1
Revert "ci(ruff-commas): autofix"
sujuka99 Sep 27, 2023
1e03e1a
test: whether matcher works
sujuka99 Sep 27, 2023
2fab625
test: problem checker
sujuka99 Sep 27, 2023
e3b7122
fix: ci
sujuka99 Sep 27, 2023
884445f
ci(ruff): format output as "text" in the CI only
sujuka99 Sep 27, 2023
0eb104d
fix(ruff): pre-commit wrong arg
sujuka99 Sep 27, 2023
47b3377
fix: ruff args in pre-commit
sujuka99 Sep 27, 2023
60a500b
fix(ci): ruff pre-commit hook
sujuka99 Sep 27, 2023
571c43f
ci: attempt to fix
sujuka99 Sep 27, 2023
3283ec0
fix: problem matcher regex
sujuka99 Sep 27, 2023
6622b59
fix: regex problem matchr
sujuka99 Sep 27, 2023
797aec7
ci: only lint once with ruff
sujuka99 Sep 27, 2023
fcfbcaf
chore: lint ci
sujuka99 Sep 27, 2023
049a3db
fix(ci): deduplicate pre-commit run
sujuka99 Sep 27, 2023
5229ff1
ci: always run ruff
sujuka99 Sep 27, 2023
ed8b99d
fix(ci): windows
sujuka99 Sep 27, 2023
4a82df1
chore: lint and format
sujuka99 Sep 27, 2023
966dd85
docs: add ruff badge
sujuka99 Sep 27, 2023
2712048
ci(ruff): configure isort
sujuka99 Sep 28, 2023
22409bf
chore(ruff): remove comment
sujuka99 Sep 28, 2023
b255ea3
tests: rewrite snapshots
sujuka99 Oct 2, 2023
2b6ac1b
ci: better access to python version
sujuka99 Oct 2, 2023
d1aeac5
ci: remove ruff-ci pre-commit hook
sujuka99 Oct 2, 2023
c56ef96
ci: remove repeating repo definitions pre-commit
sujuka99 Oct 2, 2023
a2c5a7f
chore: typing
sujuka99 Oct 2, 2023
1d7a04b
ci: update ruff
sujuka99 Oct 2, 2023
5aa5936
ci: remove future import that breaks ruff
sujuka99 Oct 6, 2023
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
17 changes: 17 additions & 0 deletions .github/ruff-matcher.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"problemMatcher": [
{
"owner": "ruff",
"pattern": [
{
"regexp": "^(.*):(\\d+):(\\d+):\\s([\\da-zA-Z]+)\\s(.*)$",
"file": 1,
"line": 2,
"column": 3,
"code": 4,
"message": 5
}
]
}
]
}
Empty file added .github/scripts/__init__.py
Empty file.
20 changes: 10 additions & 10 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,16 @@ jobs:
- name: Install dependencies
run: poetry install --no-interaction

- name: Lint (flake8)
run: poetry run pre-commit run flake8 --all-files --show-diff-on-failure

- name: Order of imports (isort)
run: poetry run pre-commit run isort --all-files --show-diff-on-failure
- name: Lint (ruff)
shell: bash
run: |
if [[ "$RUNNER_OS" == "Linux" && "${{ matrix.python-version }}" == "3.10" ]]
then
echo "::add-matcher::.github/ruff-matcher.json"
poetry run ruff check . --config pyproject.toml --output-format text --no-fix
else
poetry run pre-commit run ruff --all-files --show-diff-on-failure
fi;

- name: Formatting (black)
run: poetry run pre-commit run black --all-files --show-diff-on-failure
sujuka99 marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -59,11 +64,6 @@ jobs:
- name: Generate pipeline definitions
run: poetry run pre-commit run gen-docs-components --all-files --show-diff-on-failure

# TODO: enable when PEP 604 incompatibilty is in typer is resolved https://github.com/tiangolo/typer/issues/348
disrupted marked this conversation as resolved.
Show resolved Hide resolved
# See https://github.com/tiangolo/typer/pull/522
# - name: Syntax (pyupgrade)
# run: poetry run pre-commit run --hook-stage manual pyupgrade --all-files

- name: Test
run: poetry run pytest tests

Expand Down
31 changes: 8 additions & 23 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,43 +1,28 @@
repos:
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
args: ["--settings", "setup.cfg"]
exclude: ^tests/.*snapshots/
- repo: local
hooks:
- id: ruff
name: ruff
entry: ruff check .
args: [ --config, pyproject.toml, --fix, --show-fixes, --exit-non-zero-on-fix ]
language: system
types_or: [python]
require_serial: true # run once for all files
pass_filenames: false
- id: black
name: black
entry: black
language: system
types_or: [python, pyi]
require_serial: true # run once for all files
exclude: ^tests/.*snapshots/
- repo: https://github.com/pycqa/flake8
rev: 5.0.4
hooks:
- id: flake8
args: ["--config", "setup.cfg"]
exclude: ^tests/.*snapshots/
- repo: local
hooks:
- id: pyright
name: pyright
entry: pyright
language: system
types: [python]
require_serial: true # run once for all files
exclude: ^tests/.*snapshots/
- repo: https://github.com/asottile/pyupgrade
rev: v3.1.0
hooks:
- id: pyupgrade
stages: [manual]
args: ["--py310-plus"]
exclude: ^tests/.*snapshots/
- repo: local
hooks:
- id: gen-schema
name: gen-schema
entry: python hooks/gen_schema.py
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[![Build status](https://github.com/bakdata/kpops/actions/workflows/ci.yaml/badge.svg)](https://github.com/bakdata/kpops/actions/workflows/ci.yaml)
[![pypi](https://img.shields.io/pypi/v/kpops.svg)](https://pypi.org/project/kpops)
[![versions](https://img.shields.io/pypi/pyversions/kpops.svg)](https://github.com/bakdata/kpops)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
sujuka99 marked this conversation as resolved.
Show resolved Hide resolved
[![license](https://img.shields.io/github/license/bakdata/kpops.svg)](https://github.com/bakdata/kpops/blob/main/LICENSE)

## Key features
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/schema/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$ref": "#/definitions/PipelineConfig",
"definitions": {
"HelmConfig": {
"description": "Global Helm configuration",
"description": "Global Helm configuration.",
"properties": {
"api_version": {
"description": "Kubernetes API version used for Capabilities.APIVersions",
Expand Down
44 changes: 22 additions & 22 deletions docs/docs/schema/pipeline.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"definitions": {
"FromSection": {
"additionalProperties": false,
"description": "Holds multiple input topics",
"description": "Holds multiple input topics.",
"properties": {
"components": {
"additionalProperties": {
Expand All @@ -28,7 +28,7 @@
},
"FromTopic": {
"additionalProperties": false,
"description": "Input topic",
"description": "Input topic.",
"properties": {
"role": {
"description": "Custom identifier belonging to a topic; define only if `type` is `pattern` or `None`",
Expand All @@ -48,7 +48,7 @@
"type": "object"
},
"HelmRepoConfig": {
"description": "Helm repository configuration",
"description": "Helm repository configuration.",
"properties": {
"repo_auth_flags": {
"allOf": [
Expand Down Expand Up @@ -85,7 +85,7 @@
"type": "object"
},
"InputTopicTypes": {
"description": "Input topic types\n\nINPUT (input topic), PATTERN (extra-topic-pattern or input-topic-pattern)",
"description": "Input topic types.\n\nINPUT (input topic), PATTERN (extra-topic-pattern or input-topic-pattern)",
"enum": [
"input",
"pattern"
Expand All @@ -97,7 +97,7 @@
"additionalProperties": {
"type": "string"
},
"description": "Settings specific to Kafka Connectors",
"description": "Settings specific to Kafka Connectors.",
"properties": {
"connector.class": {
"title": "Connector.Class",
Expand All @@ -111,7 +111,7 @@
"type": "object"
},
"KafkaSinkConnector": {
"description": "Kafka sink connector model",
"description": "Kafka sink connector model.",
"properties": {
"app": {
"allOf": [
Expand Down Expand Up @@ -183,7 +183,7 @@
},
"type": {
"default": "kafka-sink-connector",
"description": "Kafka sink connector model",
"description": "Kafka sink connector model.",
"enum": [
"kafka-sink-connector"
],
Expand All @@ -206,7 +206,7 @@
"type": "object"
},
"KafkaSourceConnector": {
"description": "Kafka source connector model",
"description": "Kafka source connector model.",
"properties": {
"app": {
"allOf": [
Expand Down Expand Up @@ -283,7 +283,7 @@
},
"type": {
"default": "kafka-source-connector",
"description": "Kafka source connector model",
"description": "Kafka source connector model.",
"enum": [
"kafka-source-connector"
],
Expand Down Expand Up @@ -384,13 +384,13 @@
"type": "object"
},
"KubernetesAppConfig": {
"description": "Settings specific to Kubernetes Apps",
"description": "Settings specific to Kubernetes Apps.",
"properties": {},
"title": "KubernetesAppConfig",
"type": "object"
},
"OutputTopicTypes": {
"description": "Types of output topic\n\nOUTPUT (output topic), ERROR (error topic)",
"description": "Types of output topic.\n\nOUTPUT (output topic), ERROR (error topic)",
"enum": [
"output",
"error"
Expand All @@ -399,7 +399,7 @@
"type": "string"
},
"ProducerApp": {
"description": "Producer component\nThis producer holds configuration to use as values for the streams bootstrap producer helm chart. Note that the producer does not support error topics.",
"description": "Producer component.\nThis producer holds configuration to use as values for the streams bootstrap producer helm chart. Note that the producer does not support error topics.",
"properties": {
"app": {
"allOf": [
Expand Down Expand Up @@ -462,7 +462,7 @@
},
"type": {
"default": "producer-app",
"description": "Producer component\nThis producer holds configuration to use as values for the streams bootstrap producer helm chart. Note that the producer does not support error topics.",
"description": "Producer component.\nThis producer holds configuration to use as values for the streams bootstrap producer helm chart. Note that the producer does not support error topics.",
"enum": [
"producer-app"
],
Expand All @@ -485,7 +485,7 @@
"type": "object"
},
"ProducerStreamsConfig": {
"description": "Kafka Streams settings specific to Producer",
"description": "Kafka Streams settings specific to Producer.",
"properties": {
"brokers": {
"description": "Brokers",
Expand Down Expand Up @@ -519,7 +519,7 @@
"type": "object"
},
"ProducerValues": {
"description": "Settings specific to producers",
"description": "Settings specific to producers.",
"properties": {
"nameOverride": {
"description": "Override name with this value",
Expand All @@ -543,7 +543,7 @@
"type": "object"
},
"RepoAuthFlags": {
"description": "Authorisation-related flags for `helm repo`",
"description": "Authorisation-related flags for `helm repo`.",
"properties": {
"ca_file": {
"description": "Path to CA bundle file to verify certificates of HTTPS-enabled servers",
Expand Down Expand Up @@ -578,7 +578,7 @@
"type": "object"
},
"StreamsApp": {
"description": "StreamsApp component that configures a streams bootstrap app",
"description": "StreamsApp component that configures a streams bootstrap app.",
"properties": {
"app": {
"allOf": [
Expand Down Expand Up @@ -645,7 +645,7 @@
},
"type": {
"default": "streams-app",
"description": "StreamsApp component that configures a streams bootstrap app",
"description": "StreamsApp component that configures a streams bootstrap app.",
"enum": [
"streams-app"
],
Expand All @@ -668,7 +668,7 @@
"type": "object"
},
"StreamsAppAutoScaling": {
"description": "Kubernetes Event-driven Autoscaling config",
"description": "Kubernetes Event-driven Autoscaling config.",
"properties": {
"consumerGroup": {
"description": "Name of the consumer group used for checking the offset on the topic and processing the related lag.",
Expand Down Expand Up @@ -771,7 +771,7 @@
"type": "object"
},
"StreamsConfig": {
"description": "Streams Bootstrap streams section",
"description": "Streams Bootstrap streams section.",
"properties": {
"brokers": {
"description": "Brokers",
Expand Down Expand Up @@ -854,7 +854,7 @@
"type": "object"
},
"ToSection": {
"description": "Holds multiple output topics",
"description": "Holds multiple output topics.",
"properties": {
"models": {
"additionalProperties": {
Expand All @@ -880,7 +880,7 @@
},
"TopicConfig": {
"additionalProperties": false,
"description": "Configure an output topic",
"description": "Configure an output topic.",
"properties": {
"configs": {
"additionalProperties": {
Expand Down
2 changes: 1 addition & 1 deletion hooks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""KPOps pre-commit hooks"""
"""KPOps pre-commit hooks."""
from pathlib import Path

PATH_ROOT = Path(__file__).parents[1]
2 changes: 1 addition & 1 deletion hooks/gen_docs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


class IterableStrEnum(str, Enum):
"""Polyfill that also introduces dict-like behavior
"""Polyfill that also introduces dict-like behavior.

Introduces constructors that return a ``Iterator`` object
either containing all items, only their names or their values.
Expand Down
4 changes: 2 additions & 2 deletions hooks/gen_schema.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Generates the stock KPOps editor integration schemas"""
"""Generates the stock KPOps editor integration schemas."""
from contextlib import redirect_stdout
from io import StringIO
from pathlib import Path
Expand All @@ -10,7 +10,7 @@


def gen_schema(scope: SchemaScope):
"""Generates the specified schema and saves it to a file.
"""Generate the specified schema and save it to a file.

The file is located in docs/docs/schema and is named ``<scope.value>.json``

Expand Down
8 changes: 5 additions & 3 deletions kpops/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging
from enum import Enum
from pathlib import Path
from typing import TYPE_CHECKING, Iterator, Optional
from typing import TYPE_CHECKING, Optional

import dtyper
import typer
Expand All @@ -23,14 +23,16 @@
from kpops.utils.gen_schema import SchemaScope, gen_config_schema, gen_pipeline_schema

if TYPE_CHECKING:
from collections.abc import Iterator

from kpops.components.base_components import PipelineComponent

LOG_DIVIDER = "#" * 100

app = dtyper.Typer(pretty_exceptions_enable=False)

BASE_DIR_PATH_OPTION: Path = typer.Option(
default=Path("."),
default=Path(),
exists=True,
dir_okay=True,
file_okay=False,
Expand Down Expand Up @@ -371,7 +373,7 @@ def clean(
def version_callback(show_version: bool) -> None:
if show_version:
typer.echo(f"KPOps {__version__}")
raise typer.Exit()
raise typer.Exit


@app.callback()
Expand Down
Loading