Skip to content

Commit

Permalink
Replace flake8 and isort with ruff lint
Browse files Browse the repository at this point in the history
  • Loading branch information
KapJI committed Sep 13, 2024
1 parent ce652f9 commit da91e3a
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 187 deletions.
3 changes: 1 addition & 2 deletions .github/actions/install-deps/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,4 @@ runs:
- name: Install dependencies with uv
shell: bash
run: |
uv sync
run: uv sync
11 changes: 3 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ repos:
language: system
types: [python]
require_serial: true
- id: isort
name: isort
entry: uv run isort
- id: ruff
name: ruff check
entry: uv run ruff check --fix
language: system
types: [python]
require_serial: true
Expand All @@ -28,11 +28,6 @@ repos:
language: system
types: [python]
require_serial: true
- id: flake8
name: flake8
entry: uv run flake8
language: system
types: [python]
- id: pylint
name: pylint
entry: uv run pylint
Expand Down
13 changes: 4 additions & 9 deletions glocaltokens/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ def __init__(
network_device: NetworkDevice | None = None,
hardware: str | None = None,
):
"""
Initializes a Device.
"""
"""Initializes a Device."""
log_prefix = f"[Device - {device_name}(id={device_id})]"
LOGGER.debug("%s Initializing new Device instance", log_prefix)
self.device_id = device_id
Expand Down Expand Up @@ -136,8 +134,7 @@ def __init__(
android_id: str | None = None,
verbose: bool = False,
):
"""
Initialize an GLocalAuthenticationTokens instance with google account
"""Initialize an GLocalAuthenticationTokens instance with google account
credentials
:params
username: google account username;
Expand Down Expand Up @@ -360,8 +357,7 @@ def get_google_devices(
force_homegraph_reload: bool = False,
discovery_timeout: int = DISCOVERY_TIMEOUT,
) -> list[Device]:
"""
Returns a list of google devices with their local authentication tokens,
"""Returns a list of google devices with their local authentication tokens,
and IP and ports if set in models_list.
models_list: The list of accepted model names.
Expand Down Expand Up @@ -492,8 +488,7 @@ def get_google_devices_json(
zeroconf_instance: Zeroconf | None = None,
force_homegraph_reload: bool = False,
) -> str:
"""
Returns a json list of google devices with their local authentication tokens,
"""Returns a json list of google devices with their local authentication tokens,
and IP and ports if set in models_list.
models_list: The list of accepted model names.
Expand Down
6 changes: 3 additions & 3 deletions glocaltokens/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

from __future__ import annotations

from collections.abc import Callable
import logging
from threading import Event
from typing import Callable, NamedTuple
from typing import NamedTuple

from zeroconf import ServiceBrowser, ServiceInfo, ServiceListener, Zeroconf

Expand All @@ -25,8 +26,7 @@ class NetworkDevice(NamedTuple):


class CastListener(ServiceListener):
"""
Zeroconf Cast Services collection.
"""Zeroconf Cast Services collection.
Credit (pychromecast):
https://github.com/home-assistant-libs/pychromecast/
"""
Expand Down
3 changes: 1 addition & 2 deletions glocaltokens/utils/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
def censor(
text: str | None, hide_length: bool = False, hide_first_letter: bool = False
) -> str:
"""
Hide sensitive information.
"""Hide sensitive information.
text: The text to censure.
"""
Expand Down
158 changes: 132 additions & 26 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ repository = "https://github.com/leikoilja/glocaltokens"
requires-python = ">=3.9"
dynamic = ["version"]
dependencies = [
"ghome-foyer-api >= 1.0.0",
"gpsoauth >= 1.1.1",
"simplejson >= 3.19.3",
"ghome-foyer-api>=1.0.0",
"gpsoauth>=1.1.1",
"simplejson>=3.19.3",
# Note, we want to keep versions of grpcio, requests and zeroconf similar to Home Assistant
# https://github.com/home-assistant/core/blob/2024.9.0/homeassistant/package_constraints.txt
"grpcio >= 1.59.0",
"requests >= 2.32.3",
"zeroconf >= 0.133.0",
"grpcio>=1.59.0",
"requests>=2.32.3",
"zeroconf>=0.133.0",
]

[project.urls]
Expand All @@ -39,22 +39,16 @@ dependencies = [

[tool.uv]
dev-dependencies = [
"codespell >= 2.3.0",
"faker >= 20.1.0",
"flake8 >= 6.1.0",
"flake8-bugbear >= 23.12.2",
"flake8-comprehensions >= 3.15.0",
"flake8-simplify >= 0.21.0",
"flake8-use-fstring >= 1.4",
"grpc-stubs >= 1.53.0.5",
"isort >= 5.13.2",
"mock >= 5.1.0",
"mypy >= 1.11.0",
"pre-commit >= 3.8.0",
"pylint >= 3.2.7",
"pytest >= 7.4.4",
"codespell>=2.3.0",
"faker>=20.1.0",
"grpc-stubs>=1.53.0.5",
"mock>=5.1.0",
"mypy>=1.11.0",
"pre-commit>=3.8.0",
"pylint>=3.2.7",
"pytest>=7.4.4",
"ruff>=0.6.4",
"types-protobuf >= 4.25.0.20240417",
"types-protobuf>=4.25.0.20240417",
]

[build-system]
Expand All @@ -68,6 +62,117 @@ source = "vcs"
required-version = ">=0.6.0"
target-version = "py39"

[tool.ruff.lint]
select = [
"A001", # Variable {name} is shadowing a Python builtin
"ASYNC", # flake8-async
"B", # flake8-bugbear
"BLE",
"C", # complexity, including flake8-comprehensions
"COM818", # Trailing comma on bare tuple prohibited
"D", # flake8-docstrings
"DTZ003", # Use datetime.now(tz=) instead of datetime.utcnow()
"DTZ004", # Use datetime.fromtimestamp(ts, tz=) instead of datetime.utcfromtimestamp(ts)
"E", # pycodestyle
"F", # pyflakes/autoflake
"FLY", # flynt
"FURB", # refurb
"G", # flake8-logging-format
"I", # isort
"INP", # flake8-no-pep420
"ISC", # flake8-implicit-str-concat
"ICN001", # import concentions; {name} should be imported as {asname}
"LOG", # flake8-logging
"N804", # First argument of a class method should be named cls
"N805", # First argument of a method should be named self
"N815", # Variable {name} in class scope should not be mixedCase
"PERF", # Perflint
"PGH", # pygrep-hooks
"PIE", # flake8-pie
"PL", # pylint
"PT", # flake8-pytest-style
"PTH", # flake8-use-pathlib
"PYI", # flake8-pyi
"RET", # flake8-return
"RSE", # flake8-raise
"RUF005", # Consider iterable unpacking instead of concatenation
"RUF006", # Store a reference to the return value of asyncio.create_task
"RUF010", # Use explicit conversion flag
"RUF013", # PEP 484 prohibits implicit Optional
"RUF017", # Avoid quadratic list summation
"RUF018", # Avoid assignment expressions in assert statements
"RUF019", # Unnecessary key check before dictionary access
# "RUF100", # Unused `noqa` directive; temporarily every now and then to clean them up
"S102", # Use of exec detected
"S103", # bad-file-permissions
"S108", # hardcoded-temp-file
"S306", # suspicious-mktemp-usage
"S307", # suspicious-eval-usage
"S313", # suspicious-xmlc-element-tree-usage
"S314", # suspicious-xml-element-tree-usage
"S315", # suspicious-xml-expat-reader-usage
"S316", # suspicious-xml-expat-builder-usage
"S317", # suspicious-xml-sax-usage
"S318", # suspicious-xml-mini-dom-usage
"S319", # suspicious-xml-pull-dom-usage
"S320", # suspicious-xmle-tree-usage
"S601", # paramiko-call
"S602", # subprocess-popen-with-shell-equals-true
"S604", # call-with-shell-equals-true
"S608", # hardcoded-sql-expression
"S609", # unix-command-wildcard-injection
"SIM", # flake8-simplify
"SLF", # flake8-self
"SLOT", # flake8-slots
"T100", # Trace found: {name} used
"TCH", # flake8-type-checking
"TID251", # Banned imports
"TRY", # tryceratops
"UP", # pyupgrade
"W", # pycodestyle
]
ignore = [
"D202", # No blank lines allowed after function docstring
"D203", # 1 blank line required before class docstring
"D213", # Multi-line docstring summary should start at the second line
"PLR0911", # Too many return statements ({returns} > {max_returns})
"PLR0912", # Too many branches ({branches} > {max_branches})
"PLR0913", # Too many arguments to function call ({c_args} > {max_args})
"PLR0915", # Too many statements ({statements} > {max_statements})
"PLW2901", # Outer {outer_kind} variable {name} overwritten by inner {inner_kind} target
"TRY003", # Avoid specifying long messages outside the exception class
# May conflict with the formatter, https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
"W191",
"E111",
"E114",
"E117",
"D206",
"D300",
"Q",
"COM812",
"COM819",
"ISC001",
]

[tool.ruff.lint.isort]
force-sort-within-sections = true
combine-as-imports = true
split-on-trailing-comma = false

[tool.ruff.lint.flake8-pytest-style]
fixture-parentheses = false
mark-parentheses = false

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

[tool.pylint.main]
py-version = "3.9"
load-plugins = [
"pylint.extensions.code_style",
"pylint.extensions.typing",
]

[tool.pylint.master]
extension-pkg-whitelist = [
"_socket",
Expand All @@ -86,18 +191,19 @@ min-similarity-lines = 7
# Reasons disabled:
# too-many-* - are not enforced for the sake of readability
# too-few-* - same as too-many-*
# ---
# Pylint CodeStyle plugin
# consider-using-namedtuple-or-dataclass - too opinionated
# consider-using-assignment-expr - decision to use := better left to devs
disable = [
"too-few-public-methods",
"too-many-arguments",
"too-many-instance-attributes",
"too-many-locals",
"consider-using-namedtuple-or-dataclass",
"consider-using-assignment-expr",
]

[tool.isort]
profile = "black"
force_sort_within_sections = true
combine_as_imports = true

[tool.mypy]
python_version = "3.9"
show_error_codes = true
Expand Down
17 changes: 0 additions & 17 deletions setup.cfg

This file was deleted.

7 changes: 2 additions & 5 deletions tests/assertions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Common assertion helper classes used for unittesting
"""
"""Common assertion helper classes used for unittesting"""

# pylint: disable=invalid-name
from unittest import TestCase
Expand All @@ -21,8 +19,7 @@ def assertDevice(
homegraph_device: Device,
homegraph_device_struct: GetHomeGraphResponse.Home.Device,
) -> None:
"""
Custom assertion because we create Device class object
"""Custom assertion because we create Device class object
for each of received homegraph devices,
while in testing homegraph devices that we create are of type Struct
"""
Expand Down
3 changes: 1 addition & 2 deletions tests/factory/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ def homegraph_device(
def homegraph_devices(
self, min_devices: int = 1, max_devices: int = 10, count: int | None = None
) -> list[GetHomeGraphResponse.Home.Device]:
"""
Generates a random amount of devices, in the range specified.
"""Generates a random amount of devices, in the range specified.
min_devices:
The number minimum of devices to generate. Should be greater than 0
Expand Down
4 changes: 1 addition & 3 deletions tests/test_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@


class NetworkDeviceTests(TestCase):
"""
NetworkDevice specific tests
"""
"""NetworkDevice specific tests"""

def test_initialization(self) -> None:
"""Initialization tests"""
Expand Down
Loading

0 comments on commit da91e3a

Please sign in to comment.