Skip to content

Commit

Permalink
fix: Bump pre-commit hooks to fix isort issue
Browse files Browse the repository at this point in the history
CI is broken on main due to this isort issue, the root cause lies in an
underlying incompatible change in Poetry. The new version of isort has
dropped support for Python 3.7 so we bump CI to run on 3.11 instead (3.7
is EOL later this year anyway).

PyCQA/isort#2083

With the upgrade to flake8 6, we ran into an issue with comments in the
configuration file. Those comments are moved to their own lines above
the config instead, see issue below.

PyCQA/flake8#1756

Because of installation issues in the lint step, installation is altered
to only installed pre-commit which handles its own dependencies anyway.
Pylint is normalized to be installed just like the other pre-commit
hooks, the dependency on the environment is removed.
  • Loading branch information
aiven-anton committed Jan 30, 2023
1 parent 765ccd9 commit 2d27d39
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 30 deletions.
12 changes: 8 additions & 4 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ max-line-length = 125

# E203,W503: incompatibilities with black
# E722: also signaled by pylint (disabling here globally and on case-by-case basis with pylint)
# E501: line length
# E203: whitespace before ':'
# W503: line break before binary operator
# E722: do not use bare 'except'
ignore =
E501, # line length
E203, # whitespace before ':'
W503, # line break before binary operator
E722, # do not use bare 'except'
E501,
E203,
W503,
E722,
6 changes: 3 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Set up Python 3.7
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: 3.7
python-version: 3.11

- name: Install dependencies
run: pip install -r requirements-dev.txt
run: pip install 'pre-commit>=2.2.0'

# required for pylint
- name: Generate version.py
Expand Down
17 changes: 6 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
minimum_pre_commit_version: 2.9.2
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
rev: v4.4.0
hooks:
- id: trailing-whitespace
exclude: ^vendor/|^tests/.*/fixtures/.*|^tests/integration/test_data/.*
Expand All @@ -11,18 +11,18 @@ repos:
- id: debug-statements

- repo: https://github.com/PyCQA/isort
rev: 5.10.1
rev: 5.12.0
hooks:
- id: isort
name: isort (python)

- repo: https://github.com/psf/black
rev: 22.3.0
rev: 22.12.0
hooks:
- id: black

- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
rev: 6.0.0
hooks:
- id: flake8

Expand All @@ -33,16 +33,11 @@ repos:
name: Mypy Karapace
pass_filenames: false


# https://pre-commit.com/#repository-local-hooks
- repo: local
- repo: https://github.com/PyCQA/pylint
rev: v2.15.10
hooks:
- id: pylint
name: pylint
entry: pylint
language: system
types: [python]
files: \.py$
exclude: ^vendor/
args:
- --rcfile=.pylintrc
12 changes: 10 additions & 2 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ enable=
useless-suppression,

disable=
bad-continuation,
duplicate-code,
fixme,
import-outside-toplevel,
Expand All @@ -22,8 +21,17 @@ disable=
too-many-nested-blocks,
too-many-public-methods,
too-many-statements,
too-public-methods,
wrong-import-order,
import-error,
consider-using-f-string,
use-implicit-booleaness-not-comparison,
unspecified-encoding,
no-name-in-module,
unnecessary-dunder-call,
use-list-literal,
use-dict-literal,
deprecated-module,


[FORMAT]
max-line-length=125
Expand Down
2 changes: 1 addition & 1 deletion karapace/kafka_rest_apis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ async def topic_publish(self, topic: str, content_type: str, *, request: HTTPReq
await self.publish(topic, None, content_type, request)

@staticmethod
def validate_partition_id(partition_id: str, content_type: str) -> int: # pylint: disable=inconsistent-return-statements
def validate_partition_id(partition_id: str, content_type: str) -> int:
try:
return int(partition_id)
except ValueError:
Expand Down
2 changes: 0 additions & 2 deletions karapace/protobuf/protobuf_to_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

Timestamp_type_name = "Timestamp"

# pylint: disable=no-member


def datetime_to_timestamp(dt):
ts = Timestamp()
Expand Down
2 changes: 1 addition & 1 deletion karapace/protobuf/reserved_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def to_schema(self) -> str:
append_documentation(result, self.documentation)
result.append("reserved ")

for index in range(len(self.values)):
for index in range(len(self.values)): # pylint: disable=consider-using-enumerate
value = self.values[index]
if index > 0:
result.append(", ")
Expand Down
2 changes: 1 addition & 1 deletion karapace/rapu.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def cors_and_server_headers_for_request(*, request, origin="*"): # pylint: disa
"Server": SERVER_NAME,
}

def check_rest_headers(self, request: HTTPRequest) -> dict: # pylint:disable=inconsistent-return-statements
def check_rest_headers(self, request: HTTPRequest) -> dict:
method = request.method
default_content = "application/vnd.kafka.json.v2+json"
default_accept = "*/*"
Expand Down
2 changes: 1 addition & 1 deletion karapace/sentry/sentry_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from typing import Dict, Optional

# The Sentry SDK is optional, omit pylint import error
import sentry_sdk # pylint: disable=import-error
import sentry_sdk


class SentryClient(SentryClientAPI):
Expand Down
2 changes: 1 addition & 1 deletion karapace/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def default_json_serialization(obj: MappingProxyType) -> dict:
...


def default_json_serialization( # pylint: disable=inconsistent-return-statements
def default_json_serialization(
obj: Union[datetime, timedelta, Decimal, MappingProxyType],
) -> Union[str, float, dict]:
if isinstance(obj, datetime):
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_karapace.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_regression_server_must_exit_on_exception(
errfile = stack.enter_context((tmp_path / "karapace.err").open("w"))
config_path.write_text(json.dumps(config))
sock.bind(("127.0.0.1", port))
process = Popen(
process = Popen( # pylint: disable=consider-using-with
args=["python", "-m", "karapace.karapace_all", str(config_path)],
stdout=logfile,
stderr=errfile,
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/utils/kafka_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,5 @@ def configure_and_start_kafka(
),
)
env: Dict[bytes, bytes] = {}
proc = Popen(kafka_cmd, env=env)
proc = Popen(kafka_cmd, env=env) # pylint: disable=consider-using-with
return proc
2 changes: 1 addition & 1 deletion tests/integration/utils/zookeeper.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@ def configure_and_start_zk(config: ZKConfig, kafka_description: KafkaDescription
kafka_description,
)
)
proc = Popen(java_args, env=env)
proc = Popen(java_args, env=env) # pylint: disable=consider-using-with
return proc

0 comments on commit 2d27d39

Please sign in to comment.