From 3910e7d7bf2ab70bf719befaa1a608dba16486df Mon Sep 17 00:00:00 2001 From: Kevin Latka Date: Wed, 25 Sep 2024 11:43:26 +0200 Subject: [PATCH] Switch to ruff --- .flake8 | 2 - .github/workflows/hacs.yaml | 2 +- .github/workflows/hassfest.yaml | 2 +- .github/workflows/pre-commit-update.yaml | 2 +- .github/workflows/pre-commit.yaml | 6 +- .../{python-app.yaml => pytest.yaml} | 4 +- .github/workflows/release.yaml | 2 +- .pre-commit-config.yaml | 37 ++++++----- .yamllint | 61 +++++++++++++++++++ custom_components/nctalkbot/__init__.py | 4 +- custom_components/nctalkbot/config_flow.py | 18 ++++-- custom_components/nctalkbot/notify.py | 4 +- requirements.dev.txt | 3 - 13 files changed, 107 insertions(+), 40 deletions(-) delete mode 100644 .flake8 rename .github/workflows/{python-app.yaml => pytest.yaml} (92%) create mode 100644 .yamllint diff --git a/.flake8 b/.flake8 deleted file mode 100644 index 61d9081..0000000 --- a/.flake8 +++ /dev/null @@ -1,2 +0,0 @@ -[flake8] -max-line-length = 99 diff --git a/.github/workflows/hacs.yaml b/.github/workflows/hacs.yaml index ea6cf6f..7fd150a 100644 --- a/.github/workflows/hacs.yaml +++ b/.github/workflows/hacs.yaml @@ -1,6 +1,6 @@ name: HACS Action -on: +"on": push: pull_request: schedule: diff --git a/.github/workflows/hassfest.yaml b/.github/workflows/hassfest.yaml index 574d2c4..c9f1923 100644 --- a/.github/workflows/hassfest.yaml +++ b/.github/workflows/hassfest.yaml @@ -1,6 +1,6 @@ name: Validate with hassfest -on: +"on": push: pull_request: schedule: diff --git a/.github/workflows/pre-commit-update.yaml b/.github/workflows/pre-commit-update.yaml index f3df0d4..a66a584 100644 --- a/.github/workflows/pre-commit-update.yaml +++ b/.github/workflows/pre-commit-update.yaml @@ -1,6 +1,6 @@ name: Pre-commit auto-update -on: +"on": schedule: - cron: "0 0 * * *" diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml index b778efe..33bff12 100644 --- a/.github/workflows/pre-commit.yaml +++ b/.github/workflows/pre-commit.yaml @@ -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" diff --git a/.github/workflows/python-app.yaml b/.github/workflows/pytest.yaml similarity index 92% rename from .github/workflows/python-app.yaml rename to .github/workflows/pytest.yaml index 2f4b01e..7e83b63 100644 --- a/.github/workflows/python-app.yaml +++ b/.github/workflows/pytest.yaml @@ -1,6 +1,6 @@ -name: Python app +name: Pytest -on: [push, pull_request] +"on": [push, pull_request] jobs: build: diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index ff24bdd..b7bb392 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,6 +1,6 @@ name: Release -on: +"on": push: tags: - "*" diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 61a753d..ece5958 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,17 @@ 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 @@ -8,25 +19,13 @@ repos: - 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 diff --git a/.yamllint b/.yamllint new file mode 100644 index 0000000..aa14d14 --- /dev/null +++ b/.yamllint @@ -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 diff --git a/custom_components/nctalkbot/__init__.py b/custom_components/nctalkbot/__init__.py index e1a5a9c..14bdd4c 100644 --- a/custom_components/nctalkbot/__init__.py +++ b/custom_components/nctalkbot/__init__.py @@ -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: diff --git a/custom_components/nctalkbot/config_flow.py b/custom_components/nctalkbot/config_flow.py index c6e14a6..c36ee81 100644 --- a/custom_components/nctalkbot/config_flow.py +++ b/custom_components/nctalkbot/config_flow.py @@ -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) + ), } ) @@ -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") @@ -62,8 +66,10 @@ 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: @@ -71,7 +77,9 @@ async def async_step_user(self, user_input: dict[str, Any] | None = None) -> Flo 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 diff --git a/custom_components/nctalkbot/notify.py b/custom_components/nctalkbot/notify.py index 3233986..4724140 100644 --- a/custom_components/nctalkbot/notify.py +++ b/custom_components/nctalkbot/notify.py @@ -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." diff --git a/requirements.dev.txt b/requirements.dev.txt index 144de1e..b4a2191 100644 --- a/requirements.dev.txt +++ b/requirements.dev.txt @@ -1,5 +1,2 @@ pre-commit -flake8 -black ruff -pylint