diff --git a/.devcontainer/integration/devcontainer.json b/.devcontainer/integration/devcontainer.json index fb98ffca0..e4b0567b0 100644 --- a/.devcontainer/integration/devcontainer.json +++ b/.devcontainer/integration/devcontainer.json @@ -1,6 +1,20 @@ { "name": "BN Integration", "image": "mcr.microsoft.com/devcontainers/python:3.12", + "features": { + "ghcr.io/devcontainers/features/github-cli:1": { + "installDirectlyFromGitHubRelease": true, + "version": "latest" + }, + "ghcr.io/devcontainers/features/node:1": { + "nodeGypDependencies": true, + "version": "lts" + }, + "ghcr.io/devcontainers-contrib/features/poetry:2": { + "version": "latest" + }, + "ghcr.io/devcontainers/features/rust:1": {} + }, "postCreateCommand": "scripts/setup", "runArgs": [ "--network=host" @@ -44,8 +58,5 @@ } } }, - "remoteUser": "vscode", - "features": { - "ghcr.io/devcontainers/features/rust:1": {} - } + "remoteUser": "vscode" } \ No newline at end of file diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 4c9b91fde..027181fa5 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -8,7 +8,7 @@ on: - '**.py' # Run if pushed commits include a change to a Python (.py) file. - '.github/workflows/lint.yml' # Run if pushed commits include a change to a github actions workflow file. - 'requirements.txt' # Run if pushed commits include a change to the Python requirements.txt file. - - '.ruff.toml' # Run if ruff configuration file changes. + - '.pyprogject.toml' # Run if project configuration file changes. pull_request: branches: - "main" @@ -16,7 +16,7 @@ on: - '**.py' # Run if pushed commits include a change to a Python (.py) file. - '.github/workflows/lint.yml' # Run if pushed commits include a change to a github actions workflow file. - 'requirements.txt' # Run if pushed commits include a change to the Python requirements.txt file. - - '.ruff.toml' # Run if ruff configuration file changes. + - '.pyprogject.toml' # Run if project configuration file changes. workflow_dispatch: jobs: diff --git a/.ruff.toml b/.ruff.toml deleted file mode 100644 index 1445f9325..000000000 --- a/.ruff.toml +++ /dev/null @@ -1,48 +0,0 @@ -# The contents of this file is based on https://github.com/home-assistant/core/blob/dev/pyproject.toml - -target-version = "py312" - -[lint] -select = [ - "B007", # Loop control variable {name} not used within loop body - "B014", # Exception handler with duplicate exception - "C", # complexity - "D", # docstrings - "E", # pycodestyle - "F", # pyflakes/autoflake - "ICN001", # import concentions; {name} should be imported as {asname} - "PGH004", # Use specific rule codes when using noqa - "PLC0414", # Useless import alias. Import alias does not rename original package. - "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} - "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 - "T20", # flake8-print - "TRY004", # Prefer TypeError exception for invalid type - "RUF006", # Store a reference to the return value of asyncio.create_task - "UP", # pyupgrade - "W", # pycodestyle -] -ignore = [ - "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 - "D404", # First word of the docstring should not be This - "D406", # Section name should end with a newline - "D407", # Section name underlining - "D411", # Missing blank line before section - "E501", # line too long - "E731", # do not assign a lambda expression, use a def -] - -[lint.flake8-pytest-style] -fixture-parentheses = false - -[lint.pyupgrade] -keep-runtime-typing = true - -[lint.mccabe] -max-complexity = 25 diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 000000000..79a88351c --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,132 @@ +[tool.poetry] +authors = ["Andrew Jackson "] +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Framework :: AsyncIO", + "Intended Audience :: Developers", + "Natural Language :: English", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3", +] +description = "HA-Battery-Notes - A Home Assistant integration to provide battery notes of devices" +documentation = "https://github.com/andrew-codechimp/HA-Battery-Notes" +homepage = "https://github.com/andrew-codechimp/HA-Battery-Notes" +license = "MIT" +maintainers = ["Andrew Jackson "] +name = "HA-Battery-Notes" +packages = [] +readme = "README.md" +repository = "https://github.com/andrew-codechimp/HA-Battery-Notes" +version = "0.0.0" + +[tool.poetry.dependencies] +homeassistant = "2024.9.0" +python = ">=3.12,<3.13" + +[tool.poetry.group.dev.dependencies] +hass-nabucasa = "0.84.0" +pre-commit = "4.0.1" +pre-commit-hooks = "5.0.0" +pylint = "3.1.0" +ruff = "0.7.3" + +[tool.poetry.urls] +"Bug Tracker" = "https://github.com/andrew-codechimp/HA-Battery-Notes/issues" +Changelog = "https://github.com/andrew-codechimp/HA-Battery-Notes/releases" + +[build-system] +build-backend = "poetry.core.masonry.api" +requires = ["poetry-core"] + +[tool.lint.ruff] +ignore = [ + "ANN101", # Self... explanatory + "ANN401", # Opiniated warning on disallowing dynamically typed expressions + "D203", # Conflicts with other rules + "D213", # Conflicts with other rules + "TID252", # Relative imports + "RUF012", # Just broken + "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 + "D404", # First word of the docstring should not be This + "D406", # Section name should end with a newline + "D407", # Section name underlining + "D411", # Missing blank line before section + "E501", # line too long + "E731", # do not assign a lambda expression, use a def + + + # Formatter conflicts + "COM812", + "COM819", + "D206", + "E501", + "ISC001", + "Q000", + "Q001", + "Q002", + "Q003", + "W191", +] +select = ["ALL"] +src = ["custom_components/battery_notes"] + +[tool.link.flake8-import-conventions.extend-aliases] +"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" +voluptuous = "vol" + +[tool.lint.isort] +force-sort-within-sections = true +known-first-party = ["homeassistant"] +combine-as-imports = true + +[tool.pylint."MESSAGES CONTROL"] +# Reasons disabled: +# format - handled by ruff +# duplicate-code - unavoidable +# used-before-assignment - false positives with TYPE_CHECKING structures +disable = [ + "abstract-method", + "duplicate-code", + "format", + "unexpected-keyword-arg", + "used-before-assignment", +] + +[tool.mypy] +# Specify the target platform details in config, so your developers are +# free to run mypy on Windows, Linux, or macOS and get consistent +# results. +platform = "linux" +python_version = "3.12" + +# show error messages from unrelated files +follow_imports = "normal" + +# suppress errors about unsatisfied imports +ignore_missing_imports = true + +# be strict +# check_untyped_defs = true +# disallow_any_generics = true +# disallow_incomplete_defs = true +# disallow_subclassing_any = true +# disallow_untyped_calls = true +# disallow_untyped_decorators = true +# disallow_untyped_defs = true +# no_implicit_optional = true +# strict_optional = true +# warn_incomplete_stub = true +# warn_no_return = true +# warn_redundant_casts = true +# warn_return_any = true +# warn_unused_configs = true +# warn_unused_ignores = true + +[tool.ruff.lint.mccabe] +max-complexity = 25