From 9e9bfc252706fa66da164d1b3f04776e0d5be800 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Gajdu=C5=A1ek?= Date: Tue, 4 Jul 2023 10:39:07 +0200 Subject: [PATCH] Add pre-commit --- .flake8 | 2 ++ .github/workflows/pull_request.yaml | 28 ++++++++++++++++++++++++++ .gitignore | 2 ++ .pre-commit-config.yaml | 27 +++++++++++++++++++++++++ .vscode/settings.json | 2 +- LICENSE | 2 +- custom_components/feedparser/sensor.py | 22 +++++++++----------- pyproject.toml | 16 +++++++++++++++ 8 files changed, 87 insertions(+), 14 deletions(-) create mode 100644 .flake8 create mode 100644 .github/workflows/pull_request.yaml create mode 100644 .gitignore create mode 100644 .pre-commit-config.yaml create mode 100644 pyproject.toml diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..7da1f96 --- /dev/null +++ b/.flake8 @@ -0,0 +1,2 @@ +[flake8] +max-line-length = 100 diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml new file mode 100644 index 0000000..58b7138 --- /dev/null +++ b/.github/workflows/pull_request.yaml @@ -0,0 +1,28 @@ +name: CI/CQ + +on: + pull_request: + types: ["opened", "synchronize", "reopened"] + +jobs: + codechecks: + name: Code Quality + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ['3.10', '3.11'] + steps: + - name: Checkout Repository + uses: actions/checkout@v3 + + - name: Set Up Python-${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Pre Commit Checks + uses: pre-commit/action@v3.0.0 + + - name: Analysis (git diff) + if: failure() + run: git diff diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4ba2b71 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# Compiled python code. +*.pyc diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..5cf1073 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,27 @@ +# configuration for pre-commit git hooks + +repos: +- repo: https://github.com/asottile/reorder_python_imports + rev: v3.9.0 + hooks: + - id: reorder-python-imports +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: debug-statements +- repo: https://github.com/asottile/pyupgrade + rev: v3.3.0 + hooks: + - id: pyupgrade + args: [--py38-plus] +- repo: https://github.com/psf/black + rev: 22.10.0 + hooks: + - id: black +- repo: https://github.com/pycqa/flake8 + rev: 6.0.0 + hooks: + - id: flake8 diff --git a/.vscode/settings.json b/.vscode/settings.json index de288e1..163c984 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,3 @@ { "python.formatting.provider": "black" -} \ No newline at end of file +} diff --git a/LICENSE b/LICENSE index e06aa7f..a265d50 100644 --- a/LICENSE +++ b/LICENSE @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file +SOFTWARE. diff --git a/custom_components/feedparser/sensor.py b/custom_components/feedparser/sensor.py index 055ebc6..c134e09 100644 --- a/custom_components/feedparser/sensor.py +++ b/custom_components/feedparser/sensor.py @@ -1,21 +1,22 @@ """Feedparser sensor""" from __future__ import annotations -import asyncio import re from datetime import timedelta +import feedparser import homeassistant.helpers.config_validation as cv +import homeassistant.util.dt as dt import voluptuous as vol from dateutil import parser -from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity -from homeassistant.const import CONF_NAME, CONF_SCAN_INTERVAL +from homeassistant.components.sensor import PLATFORM_SCHEMA +from homeassistant.components.sensor import SensorEntity +from homeassistant.const import CONF_NAME +from homeassistant.const import CONF_SCAN_INTERVAL from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback -from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType -import homeassistant.util.dt as dt - -import feedparser +from homeassistant.helpers.typing import ConfigType +from homeassistant.helpers.typing import DiscoveryInfoType __version__ = "0.1.11" @@ -25,7 +26,7 @@ CONF_FEED_URL = "feed_url" CONF_DATE_FORMAT = "date_format" -CONF_LOCAL_TIME = "local_time" +CONF_LOCAL_TIME = "local_time" CONF_INCLUSIONS = "inclusions" CONF_EXCLUSIONS = "exclusions" CONF_SHOW_TOPN = "show_topn" @@ -46,7 +47,6 @@ ) -"""@asyncio.coroutine""" async def async_setup_platform( hass: HomeAssistant, config: ConfigType, @@ -129,9 +129,7 @@ def update(self): if "image" in self._inclusions and "image" not in entry_value.keys(): images = [] if "summary" in entry.keys(): - images = re.findall( - r"", entry["summary"] - ) + images = re.findall(r"", entry["summary"]) if images: entry_value["image"] = images[0] else: diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..04c1d3a --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,16 @@ +[tool.black] +line-length = 100 +skip-string-normalization = true +include = '\.pyi?$' +exclude = ''' +/( + \.git + | \.hg + | \.mypy_cache + | \.venv + | _build + | buck-out + | build + | dist +)/ +'''