Skip to content

Commit

Permalink
Switch to ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
klatka committed Sep 25, 2024
1 parent 83887ef commit 3910e7d
Show file tree
Hide file tree
Showing 13 changed files with 107 additions and 40 deletions.
2 changes: 0 additions & 2 deletions .flake8

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/hacs.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: HACS Action

on:
"on":
push:
pull_request:
schedule:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/hassfest.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Validate with hassfest

on:
"on":
push:
pull_request:
schedule:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pre-commit-update.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Pre-commit auto-update

on:
"on":
schedule:
- cron: "0 0 * * *"

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/pre-commit.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
name: Pre-commit

on: [push, pull_request]
"on": [push, pull_request]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.x
uses: actions/setup-python@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
# Semantic version range syntax or exact version of a Python version
python-version: "3.x"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Python app
name: Pytest

on: [push, pull_request]
"on": [push, pull_request]

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Release

on:
"on":
push:
tags:
- "*"
Expand Down
37 changes: 18 additions & 19 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.7
hooks:
- id: ruff
args:
- --fix
- id: ruff-format
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.35.1
hooks:
- id: yamllint
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: check-added-large-files
- id: trailing-whitespace
- id: end-of-file-fixer
- id: mixed-line-ending
args: ["--fix=lf"]
- id: check-toml
- id: check-yaml
- repo: https://github.com/pycqa/flake8
rev: 6.1.0
hooks:
- id: flake8
- repo: https://github.com/ambv/black
rev: 23.10.1
hooks:
- id: black
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
hooks:
- id: pyupgrade
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.3
hooks:
- id: prettier
- id: check-json
exclude: (.vscode|.devcontainer)
- id: no-commit-to-branch
args:
- --branch=main
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.39.0
rev: v0.42.0
hooks:
- id: markdownlint-fix
name: markdownlint-fix
Expand Down
61 changes: 61 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
ignore: |
tests/fixtures/core/config/yaml_errors/
rules:
braces:
level: error
min-spaces-inside: 0
max-spaces-inside: 1
min-spaces-inside-empty: -1
max-spaces-inside-empty: -1
brackets:
level: error
min-spaces-inside: 0
max-spaces-inside: 0
min-spaces-inside-empty: -1
max-spaces-inside-empty: -1
colons:
level: error
max-spaces-before: 0
max-spaces-after: 1
commas:
level: error
max-spaces-before: 0
min-spaces-after: 1
max-spaces-after: 1
comments:
level: error
require-starting-space: true
min-spaces-from-content: 1
comments-indentation:
level: error
document-end:
level: error
present: false
document-start:
level: error
present: false
empty-lines:
level: error
max: 1
max-start: 0
max-end: 1
hyphens:
level: error
max-spaces-after: 1
indentation:
level: error
spaces: 2
indent-sequences: true
check-multi-line-strings: false
key-duplicates:
level: error
line-length: disable
new-line-at-end-of-file:
level: error
new-lines:
level: error
type: unix
trailing-spaces:
level: error
truthy:
level: error
4 changes: 3 additions & 1 deletion custom_components/nctalkbot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
_LOGGER = logging.getLogger(__name__)


async def handle_webhook(hass: HomeAssistant, webhook_id: str, request: Request) -> Response:
async def handle_webhook(
hass: HomeAssistant, webhook_id: str, request: Request
) -> Response:
"""Handle webhook callback."""
server = request.headers.get("X-NEXTCLOUD-TALK-BACKEND")
if server is None:
Expand Down
18 changes: 13 additions & 5 deletions custom_components/nctalkbot/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@

STEP_USER_DATA_SCHEMA = vol.Schema(
{
vol.Required(CONF_URL): TextSelector(TextSelectorConfig(type=TextSelectorType.URL)),
vol.Required(CONF_URL): TextSelector(
TextSelectorConfig(type=TextSelectorType.URL)
),
}
)

Expand All @@ -41,7 +43,9 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):

VERSION = 1

async def async_step_user(self, user_input: dict[str, Any] | None = None) -> FlowResult:
async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
"""Handle a user initiated set up flow to create a webhook."""
if self._async_current_entries():
return self.async_abort(reason="already_configured")
Expand All @@ -62,16 +66,20 @@ async def async_step_user(self, user_input: dict[str, Any] | None = None) -> Flo
if not self.hass.components.cloud.async_is_connected():
return self.async_abort(reason="cloud_not_connected")

webhook_url = await self.hass.components.cloud.async_create_cloudhook(
webhook_id
webhook_url = (
await self.hass.components.cloud.async_create_cloudhook(
webhook_id
)
)
cloudhook = True
except AttributeError:
# probably replaced cloud component by custom integration
pass

if not cloudhook:
webhook_url = self.hass.components.webhook.async_generate_url(webhook_id)
webhook_url = self.hass.components.webhook.async_generate_url(
webhook_id
)

description_placeholder["webhook_url"] = webhook_url

Expand Down
4 changes: 3 additions & 1 deletion custom_components/nctalkbot/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ async def async_send_message(self, message="", **kwargs):
reply_to = kwargs["data"].get("reply_to", "")
silent = kwargs["data"].get("silent", False)

r = await self.bot.async_send_message(message, target, reply_to, silent)
r = await self.bot.async_send_message(
message, target, reply_to, silent
)
if not r.status_code == 201:
_LOGGER.error(
"Nextcloud Talk Bot rejected the message."
Expand Down
3 changes: 0 additions & 3 deletions requirements.dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
pre-commit
flake8
black
ruff
pylint

0 comments on commit 3910e7d

Please sign in to comment.