From 739db113afc6deec5509116abf337119289ba710 Mon Sep 17 00:00:00 2001 From: Konstantin Deev Date: Thu, 17 Aug 2023 10:18:47 -0500 Subject: [PATCH] add pre-commit --- .github/workflows/hassfest.yaml | 2 +- .github/workflows/pre-commit.yml | 15 +++++++++++++ .pre-commit-config.yaml | 29 +++++++++++++++++++++++++ README.md | 2 +- pyproject.toml | 21 ++++++++++++++++++ ruff.toml | 37 ++++++++++++++++++++++++++++++++ 6 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/pre-commit.yml create mode 100644 .pre-commit-config.yaml create mode 100644 pyproject.toml create mode 100644 ruff.toml diff --git a/.github/workflows/hassfest.yaml b/.github/workflows/hassfest.yaml index afbde1a..5f7a071 100644 --- a/.github/workflows/hassfest.yaml +++ b/.github/workflows/hassfest.yaml @@ -11,4 +11,4 @@ jobs: runs-on: "ubuntu-latest" steps: - uses: "actions/checkout@v3" - - uses: "home-assistant/actions/hassfest@master" \ No newline at end of file + - uses: "home-assistant/actions/hassfest@master" diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 0000000..7c68dee --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,15 @@ +name: pre-commit + +on: + push: + pull_request: + schedule: + - cron: '0 0 * * *' + +jobs: + pre-commit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v3 + - uses: pre-commit/action@v3.0.0 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..837dba4 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,29 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: check-added-large-files + - id: trailing-whitespace + - id: end-of-file-fixer + - id: mixed-line-ending + args: ["--fix=lf"] + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.0.280 + hooks: + - id: ruff + args: ["--fix"] + + - repo: https://github.com/psf/black + rev: 23.7.0 + hooks: + - id: black + + - repo: https://github.com/PyCQA/flake8 + rev: 6.0.0 + hooks: + - id: flake8 + + - repo: https://github.com/PyCQA/isort + rev: 5.12.0 + hooks: + - id: isort diff --git a/README.md b/README.md index ebba25c..7609961 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Add `https://github.com/kdeyev/eyeonwater` as Repository and select the "Integra 2. Add EyeOnWater integration following [HACS instructions](https://github.com/hacs/integration) -Follow the configuration dialog: +Follow the configuration dialog: - Choose EyeOnWater hostname (choose eyeonwater.com unless you are in Canada). - Choose the measurement system you prefer to use. "Imperial" will create a water sensor counting gallons, "Metric" will create a water sensor counting cubic meters. - Use your username and password, which you use to log in on eyeonwater.com diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..b13d44a --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,21 @@ +[tool.black] +target-version = ["py39", "py310"] +exclude = 'generated' + +[tool.isort] +# https://github.com/PyCQA/isort/wiki/isort-Settings +profile = "black" +# will group `import x` and `from x import` of the same module. +force_sort_within_sections = true +known_first_party = [ + "homeassistant", + "tests", +] +forced_separate = [ + "tests", +] +combine_as_imports = true + +[flake8] +; ignore = E211, E999, F401, F821, W503 +max-doc-length = 72 diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 0000000..c1b6b78 --- /dev/null +++ b/ruff.toml @@ -0,0 +1,37 @@ +# The contents of this file is based on https://github.com/home-assistant/core/blob/dev/pyproject.toml + +target-version = "py310" + +select = ["ALL"] + +# All the ones without a comment were the ones that are currently violated +# by the codebase. The plan is to fix them all (when sensible) and then enable them. +ignore = [ + "ANN", + "ANN101", # Missing type annotation for {name} in method + "ANN401", # Dynamically typed expressions (typing.Any) are disallowed in {name} + "D401", # First line of docstring should be in imperative mood + "E501", # line too long + "FBT001", # Boolean positional arg in function definition + "FBT002", # Boolean default value in function definition + "FIX004", # Line contains HACK, consider resolving the issue + "PD901", # df is a bad variable name. Be kinder to your future self. + "PERF203",# `try`-`except` within a loop incurs performance overhead + "PLR0913", # Too many arguments to function call (N > 5) + "PLR2004", # Magic value used in comparison, consider replacing X with a constant variable + "S101", # Use of assert detected + "SLF001", # Private member accessed +] + +[per-file-ignores] +"tests/*.py" = ["ALL"] +".github/*py" = ["INP001"] + +[flake8-pytest-style] +fixture-parentheses = false + +[pyupgrade] +keep-runtime-typing = true + +[mccabe] +max-complexity = 25