Skip to content

Commit

Permalink
Change development env.
Browse files Browse the repository at this point in the history
- Lint using ruff.
- Manage venvs with tox.
  • Loading branch information
denpamusic committed Dec 10, 2023
1 parent beffb54 commit 9ad4546
Show file tree
Hide file tree
Showing 5 changed files with 213 additions and 60 deletions.
18 changes: 3 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,10 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install pyplumio==0.5.10 pytest-homeassistant-custom-component psutil-home-assistant fnv-hash-fast aiohttp_cors mypy pylint flake8 flake8-pyproject black
python -m pip install tox tox-gh-actions coverage
- name: Check typing
run: |
mypy .
- name: Lint
run: |
black --check custom_components/plum_ecomax
pylint custom_components/plum_ecomax
flake8 .
- name: Run tests
run: |
coverage run -m pytest tests/
coverage report -m
- name: Test with tox
run: tox

- if: github.event_name != 'pull_request'
uses: paambaati/codeclimate-action@v5.0.0
Expand Down
4 changes: 0 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
"editor.codeActionsOnSave": {
"source.organizeImports": true
},
"isort.args": [
"--profile",
"black"
],
"editor.rulers": [
72,
88
Expand Down
243 changes: 202 additions & 41 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,45 +1,39 @@
[tool.pylint.MASTER]
py-version = "3.11"
ignore = [
"tests",
]
jobs = 2

[tool.pylint.BASIC]
good-names = [
"_",
"i",
"e",
"j",
"k",
"m",
"v",
"ip",
"dr",
[project]
name = "homeassistant-plum-ecomax"
authors = [
{name = "Denis Paavilainen", email = "denpa@denpa.pro"}
]
description = "Plum ecoMAX boiler controller integration for Home Assistant."
license = {text = "MIT License"}
version = "0" # Only used by tox

[tool.pylint."MESSAGES CONTROL"]
disable = [
"unused-argument",
"too-many-instance-attributes",
"duplicate-code",
]
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[tool.setuptools]
platforms = ["any"]
packages = ["custom_components"]

[tool.black]
target-version = ["py311"]

[tool.isort]
profile = "black"
force_sort_within_sections = true
combine_as_imports = true
[tool.codespell]
skip = ".git,.mypy_cache,.pytest_cache,.ruff_cache,.tox,.vscode,build,translations"
ignore-words-list = "hass"

[tool.mypy]
ignore_missing_imports = true
exclude = [
'^.github/',
'^.git/',
'^images/',
'^tests/',
".git",
".github",
".mypy_cache",
".pytest_cache",
".ruff_cache",
".tox",
".vscode",
"build",
"tests"
]

# Avoid unexpected keyword argument error in config_flow.py
Expand All @@ -48,14 +42,181 @@ disable_error_code = "call-arg"
[tool.pytest.ini_options]
asyncio_mode = "auto"

[tool.flake8]
exclude = ".git,.mypy_cache"
max-complexity = 25
[tool.ruff]
select = [
"B002", # Python does not support the unary prefix increment
"B007", # Loop control variable {name} not used within loop body
"B014", # Exception handler with duplicate exception
"B023", # Function definition does not bind loop variable {name}
"B026", # Star-arg unpacking after a keyword argument is strongly discouraged
"C", # complexity
"COM818", # Trailing comma on bare tuple prohibited
"D", # docstrings
"DTZ003", # Use datetime.now(tz=) instead of datetime.utcnow()
"DTZ004", # Use datetime.fromtimestamp(ts, tz=) instead of datetime.utcfromtimestamp(ts)
"E", # pycodestyle
"F", # pyflakes/autoflake
"G", # flake8-logging-format
"I", # isort
"ICN001", # import concentions; {name} should be imported as {asname}
"ISC001", # Implicitly concatenated string literals on one line
"N804", # First argument of a class method should be named cls
"N805", # First argument of a method should be named self
"N815", # Variable {name} in class scope should not be mixedCase
"PGH001", # No builtin eval() allowed
"PGH004", # Use specific rule codes when using noqa
"PLC0414", # Useless import alias. Import alias does not rename original package.
"PLC", # pylint
"PLE", # pylint
"PLR", # pylint
"PLW", # pylint
"Q000", # Double quotes found but single quotes preferred
"RUF006", # Store a reference to the return value of asyncio.create_task
"S102", # Use of exec detected
"S103", # bad-file-permissions
"S108", # hardcoded-temp-file
"S306", # suspicious-mktemp-usage
"S307", # suspicious-eval-usage
"S313", # suspicious-xmlc-element-tree-usage
"S314", # suspicious-xml-element-tree-usage
"S315", # suspicious-xml-expat-reader-usage
"S316", # suspicious-xml-expat-builder-usage
"S317", # suspicious-xml-sax-usage
"S318", # suspicious-xml-mini-dom-usage
"S319", # suspicious-xml-pull-dom-usage
"S320", # suspicious-xmle-tree-usage
"S601", # paramiko-call
"S602", # subprocess-popen-with-shell-equals-true
"S604", # call-with-shell-equals-true
"S608", # hardcoded-sql-expression
"S609", # unix-command-wildcard-injection
"SIM105", # Use contextlib.suppress({exception}) instead of try-except-pass
"SIM117", # Merge with-statements that use the same scope
"SIM118", # Use {key} in {dict} instead of {key} in {dict}.keys()
"SIM201", # Use {left} != {right} instead of not {left} == {right}
"SIM208", # Use {expr} instead of not (not {expr})
"SIM212", # Use {a} if {a} else {b} instead of {b} if not {a} else {a}
"SIM300", # Yoda conditions. Use 'age == 42' instead of '42 == age'.
"SIM401", # Use get from dict with default instead of an if block
"T100", # Trace found: {name} used
"T20", # flake8-print
"TID251", # Banned imports
"TRY004", # Prefer TypeError exception for invalid type
"TRY200", # Use raise from to specify exception cause
"TRY302", # Remove exception handler; error is immediately re-raised
"UP", # pyupgrade
"W", # pycodestyle
]

ignore = [
"E501",
"W503",
"E203",
"D202",
"W504",
"D202", # No blank lines allowed after function docstring
"D203", # 1 blank line required before class docstring
"D213", # Multi-line docstring summary should start at the second line
"D406", # Section name should end with a newline
"D407", # Section name underlining
"E501", # line too long
"E731", # do not assign a lambda expression, use a def

# Ignore ignored, as the rule is now back in preview/nursery, which cannot
# be ignored anymore without warnings.
# https://github.com/astral-sh/ruff/issues/7491
# "PLC1901", # Lots of false positives

# False positives https://github.com/astral-sh/ruff/issues/5386
"PLC0208", # Use a sequence type instead of a `set` when iterating over values
"PLR0911", # Too many return statements ({returns} > {max_returns})
"PLR0912", # Too many branches ({branches} > {max_branches})
"PLR0913", # Too many arguments to function call ({c_args} > {max_args})
"PLR0915", # Too many statements ({statements} > {max_statements})
"PLR2004", # Magic value used in comparison, consider replacing {value} with a constant variable
"PLW2901", # Outer {outer_kind} variable {name} overwritten by inner {inner_kind} target
"UP006", # keep type annotation style as is
"UP007", # keep type annotation style as is
# Ignored due to performance: https://github.com/charliermarsh/ruff/issues/2923
"UP038", # Use `X | Y` in `isinstance` call instead of `(X, Y)`

]

[tool.ruff.flake8-import-conventions.extend-aliases]
voluptuous = "vol"
"homeassistant.helpers.area_registry" = "ar"
"homeassistant.helpers.config_validation" = "cv"
"homeassistant.helpers.device_registry" = "dr"
"homeassistant.helpers.entity_registry" = "er"
"homeassistant.helpers.issue_registry" = "ir"
"homeassistant.util.dt" = "dt_util"

[tool.ruff.flake8-pytest-style]
fixture-parentheses = false

[tool.ruff.flake8-tidy-imports.banned-api]
"async_timeout".msg = "use asyncio.timeout instead"
"pytz".msg = "use zoneinfo instead"

[tool.ruff.isort]
force-sort-within-sections = true
known-first-party = [
"custom_components.plum_ecomax",
]
noqa-require-code = true
combine-as-imports = true
split-on-trailing-comma = false

[tool.ruff.mccabe]
max-complexity = 25

[tool.coverage.report]
exclude_lines = [
"if TYPE_CHECKING:",
"@overload"
]

[tool.tox]
legacy_tox_ini = """
[tox]
envlist = lint, type, py311
isolated_build = True
skip_missing_interpreters = True
ignore_basepython_conflict = True
[gh-actions]
python =
3.11: lint, type, py311
[testenv]
deps =
-r{toxinidir}/requirements.txt
-r{toxinidir}/requirements_test.txt
coverage
commands =
coverage run --source=custom_components/plum_ecomax -m pytest tests/
coverage report -m
[testenv:lint]
deps =
-r{toxinidir}/requirements.txt
codespell
ruff
black
commands =
codespell
black --check --quiet .
ruff .
[testenv:test]
deps =
-r{toxinidir}/requirements.txt
-r{toxinidir}/requirements_test.txt
commands =
pytest
[testenv:type]
deps =
-r{toxinidir}/requirements.txt
mypy
commands =
mypy .
"""
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pyplumio==0.5.10
homeassistant
6 changes: 6 additions & 0 deletions requirements_test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pytest-homeassistant-custom-component
psutil-home-assistant
fnv-hash-fast
aiohttp_cors
pytest
pytest-asyncio

0 comments on commit 9ad4546

Please sign in to comment.