Skip to content

Commit

Permalink
Use ruff for linting and formatting (#139)
Browse files Browse the repository at this point in the history
Simplify the tooling by converting to use ruff & fix reported issues.
  • Loading branch information
rytilahti authored Nov 6, 2023
1 parent 85de9cf commit 19fa08f
Show file tree
Hide file tree
Showing 14 changed files with 127 additions and 258 deletions.
28 changes: 2 additions & 26 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,9 @@ jobs:
run: |
python -m pip install --upgrade pip poetry
poetry install
- name: "Run pyupgrade"
- name: "Linting and code formating (ruff)"
run: |
poetry run pre-commit run pyupgrade --all-files
- name: "Code formating (black)"
run: |
poetry run pre-commit run black --all-files
- name: "Code formating (flake8)"
run: |
poetry run pre-commit run flake8 --all-files
- name: "Order of imports (isort)"
run: |
poetry run pre-commit run isort --all-files
poetry run pre-commit run ruff --all-files
- name: "Typing checks (mypy)"
run: |
poetry run pre-commit run mypy --all-files
- name: "Run trailing-whitespace"
run: |
poetry run pre-commit run trailing-whitespace --all-files
- name: "Run end-of-file-fixer"
run: |
poetry run pre-commit run end-of-file-fixer --all-files
- name: "Run check-docstring-first"
run: |
poetry run pre-commit run check-docstring-first --all-files
- name: "Run debug-statements"
run: |
poetry run pre-commit run debug-statements --all-files
- name: "Run check-ast"
run: |
poetry run pre-commit run check-ast --all-files
35 changes: 5 additions & 30 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +1,10 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.4
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-docstring-first
- id: check-yaml
- id: debug-statements
- id: check-ast

- repo: https://github.com/ambv/black
rev: 23.10.1
hooks:
- id: black
language_version: python3

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

- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.10.1
hooks:
- id: isort
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.6.1
Expand All @@ -32,9 +13,3 @@ repos:
args: [--no-strict-optional, --ignore-missing-imports]
additional_dependencies:
- types-attrs

- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
hooks:
- id: pyupgrade
args: ['--py38-plus']
7 changes: 0 additions & 7 deletions MANIFEST.in

This file was deleted.

139 changes: 27 additions & 112 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 25 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ packages = [
[tool.poetry.scripts]
songpal = "songpal.main:cli"


[tool.poetry.dependencies]
python = "^3.8"
click = ">=8"
Expand All @@ -23,9 +22,32 @@ async_upnp_client = ">=0.32"

[tool.poetry.dev-dependencies]
pre-commit = "*"
ruff = "*"
mypy = "*"
isort = "*"
tox = "*"

[tool.ruff]
exclude = [
".git",
".tox",
"__pycache__",
]
ignore = [
"D105", # Missing docstring in magic method
"D107", # Missing docstring in `__init__`
"D204",
]
line-length = 88
select = [
"E", # pycodestyle
"F", # pyflakes
"D", # pydocstyle
"I", # isort
"UP", # pyupgrade
"W", # warnings
]

[tool.ruff.pydocstyle]
convention = "pep257"

[build-system]
requires = ["poetry-core"]
Expand Down
2 changes: 1 addition & 1 deletion songpal/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def convert_is_active(x) -> bool:


def convert_title(x) -> str:
"""Trim trailing characters on the title"""
"""Trim trailing characters on the title."""
return x.strip()


Expand Down
6 changes: 3 additions & 3 deletions songpal/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ async def create_post_request(self, method: str, params: Dict = None):
if res.status != 200:
res_json = await res.json(content_type=None)
raise SongpalException(
"Got a non-ok (status %s) response for %s"
% (res.status, method),
f"Got a non-ok (status {res.status}) response for {method}",
error=res_json.get("error"),
)

Expand Down Expand Up @@ -313,12 +312,13 @@ async def get_zones(self) -> List[Zone]:
return zones

async def get_zone(self, name) -> Zone:
"""Get zone by name."""
zones = await self.get_zones()
try:
zone = next(x for x in zones if x.title == name)
return zone
except StopIteration:
raise SongpalException("Unable to find zone %s" % name)
raise SongpalException(f"Unable to find zone {name}")

async def get_setting(self, service: str, method: str, target: str):
"""Get a single setting for service.
Expand Down
10 changes: 10 additions & 0 deletions songpal/discovery.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
"""Discovery module.
This module uses async_upnp_client to discover devices supporting the
urn:schemas-sony-com:service:ScalarWebAPI:1 service used by this library.
"""

import logging
from xml import etree

Expand All @@ -11,6 +17,8 @@

@attr.s
class DiscoveredDevice:
"""Container for discovered device information."""

name = attr.ib()
model_number = attr.ib()
udn = attr.ib()
Expand All @@ -22,6 +30,8 @@ class DiscoveredDevice:


class Discover:
"""Implementation of UPnP discoverer for supported devices."""

@staticmethod
async def discover(timeout, debug=0, callback=None, source_address=None):
"""Discover supported devices."""
Expand Down
Loading

0 comments on commit 19fa08f

Please sign in to comment.