Repository: home-assistant-libs/zwave-js-server-python (language: python)

Issue:
TODO: Switch to pyproject.toml



Discussion / hints:

Fix patch:
diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml
index 0c01a0cae..d5f65b048 100644
--- a/.github/workflows/publish-to-pypi.yml
+++ b/.github/workflows/publish-to-pypi.yml
@@ -19,7 +19,8 @@ jobs:
           pip install wheel
       - name: Build
         run: >-
-          python3 setup.py sdist bdist_wheel
+          pip install build
+          python -m build
       - name: Publish release to PyPI
         uses: pypa/gh-action-pypi-publish@v1.8.10
         with:
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 000000000..d7a1dc43f
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1,1 @@
+exclude test/*
diff --git a/pyproject.toml b/pyproject.toml
index 1b56881dd..235d132e5 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,17 +1,66 @@
-[tool.ruff]
-select = [
-    "D",
-    "E",
-    "F",
-    "G",
-    "I",
-    "PLC",
-    "PLE",
-    "PLR",
-    "PLW",
-    "UP",
-    "W",
+[build-system]
+requires = ["setuptools"]
+build-backend = "setuptools.build_meta"
+
+[project]
+name = "zwave-js-server-python"
+authors = [{ name = "Home Assistant Team", email = "hello@home-assistant.io" }]
+description = "Python wrapper for zwave-js-server"
+readme = "README.md"
+requires-python = ">=3.11"
+license = { file = "LICENSE" }
+keywords = ["home", "automation", "zwave", "zwave-js"]
+classifiers = [
+    "Development Status :: 4 - Beta",
+    "Intended Audience :: Developers",
+    "Natural Language :: English",
+    "Programming Language :: Python :: 3",
+    "Programming Language :: Python :: 3.11",
+    "Topic :: Home Automation",
 ]
+dependencies = ["aiohttp>3", "pydantic>=1.10.0"]
+dynamic = ["version"]
+
+[project.urls]
+"Source Code" = "https://github.com/home-assistant-libs/zwave-js-server-python"
+"Bug Reports" = "https://github.com/home-assistant-libs/zwave-js-server-python/issues"
+
+[project.scripts]
+zwave-js-server-python = "zwave_js_server.__main__:main"
+
+[tool.setuptools.dynamic]
+version = { attr = "zwave_js_server.const.__version__" }
+
+[tool.setuptools.packages.find]
+exclude = ["test", "test.*", "scripts"]
+
+[tool.setuptools.package-data]
+zwave_js_server = ["py.typed"]
+
+[tool.mypy]
+plugins = ["pydantic.mypy"]
+follow_imports = "skip"
+ignore_missing_imports = true
+check_untyped_defs = true
+disallow_incomplete_defs = true
+disallow_untyped_calls = true
+disallow_untyped_defs = true
+warn_return_any = false
+warn_unreachable = true
+warn_unused_ignores = true
+warn_incomplete_stub = true
+warn_redundant_casts = true
+warn_unused_configs = true
+
+[[tool.mypy.overrides]]
+module = "mypy-test.*"
+ignore_errors = true
+
+[tool.pytest.ini_options]
+asyncio_mode = "auto"
+
+[tool.ruff]
+select = ["D", "E", "F", "G", "I", "PLC", "PLE", "PLR", "PLW", "UP", "W"]
 ignore = [
     "D202",
     "D212",
@@ -22,10 +71,10 @@ ignore = [
     "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
+    "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
+    "UP006",   # keep type annotation style as is
+    "UP007",   # keep type annotation style as is
 ]
 exclude = [
     ".venv",
@@ -42,9 +91,7 @@ line-length = 88
 
 [tool.ruff.isort]
 force-sort-within-sections = true
-known-first-party = [
-    "zwave_js_server",
-]
+known-first-party = ["zwave_js_server"]
 combine-as-imports = true
 split-on-trailing-comma = false
 case-sensitive = true
diff --git a/setup.cfg b/setup.cfg
deleted file mode 100644
index abd9b9acb..000000000
--- a/setup.cfg
+++ /dev/null
@@ -1,20 +0,0 @@
-[mypy]
-plugins = pydantic.mypy
-follow_imports = skip
-ignore_missing_imports = true
-check_untyped_defs = true
-disallow_incomplete_defs = true
-disallow_untyped_calls = true
-disallow_untyped_defs = true
-warn_return_any = false
-warn_unreachable = true
-warn_unused_ignores = true
-warn_incomplete_stub = true
-warn_redundant_casts = true
-warn_unused_configs = true
-
-[mypy-test.*,]
-ignore_errors = true
-
-[tool:pytest]
-asyncio_mode = auto
diff --git a/setup.py b/setup.py
deleted file mode 100644
index c7ee36d43..000000000
--- a/setup.py
+++ /dev/null
@@ -1,38 +0,0 @@
-"""Setup module for zwave-js-server-python."""
-from pathlib import Path
-
-from setuptools import find_packages, setup
-
-PROJECT_DIR = Path(__file__).parent.resolve()
-README_FILE = PROJECT_DIR / "README.md"
-VERSION = "0.54.0"
-
-
-setup(
-    name="zwave-js-server-python",
-    version=VERSION,
-    url="https://github.com/home-assistant-libs/zwave-js-server-python",
-    download_url="https://github.com/home-assistant-libs/zwave-js-server-python",
-    author="Home Assistant Team",
-    author_email="hello@home-assistant.io",
-    description="Python wrapper for zwave-js-server",
-    long_description=README_FILE.read_text(encoding="utf-8"),
-    long_description_content_type="text/markdown",
-    packages=find_packages(exclude=["test.*", "test"]),
-    package_data={"zwave_js_server": ["py.typed"]},
-    python_requires=">=3.11",
-    install_requires=["aiohttp>3", "pydantic>=1.10.0"],
-    entry_points={
-        "console_scripts": ["zwave-js-server-python = zwave_js_server.__main__:main"]
-    },
-    include_package_data=True,
-    zip_safe=False,
-    classifiers=[
-        "Development Status :: 4 - Beta",
-        "Intended Audience :: Developers",
-        "Natural Language :: English",
-        "Programming Language :: Python :: 3",
-        "Programming Language :: Python :: 3.11",
-        "Topic :: Home Automation",
-    ],
-)
diff --git a/zwave_js_server/const/__init__.py b/zwave_js_server/const/__init__.py
index 455f21ef8..2e1df8d55 100644
--- a/zwave_js_server/const/__init__.py
+++ b/zwave_js_server/const/__init__.py
@@ -3,12 +3,11 @@
 
 from dataclasses import dataclass, field
 from enum import Enum, IntEnum
-from importlib import metadata
 import logging
 from typing import TypedDict
 
 PACKAGE_NAME = "zwave-js-server-python"
-__version__ = metadata.version(PACKAGE_NAME)
+__version__ = "0.54.0"
 
 # minimal server schema version we can handle
 MIN_SERVER_SCHEMA_VERSION = 33
diff --git a/zwave_js_server/event.py b/zwave_js_server/event.py
index d6e34b78d..9d88d1c30 100644
--- a/zwave_js_server/event.py
+++ b/zwave_js_server/event.py
@@ -1,9 +1,10 @@
 """Provide Event base classes for Z-Wave JS."""
 from __future__ import annotations
 
+from collections.abc import Callable
 from dataclasses import dataclass, field
 import logging
-from typing import Callable, Literal
+from typing import Literal
 
 try:
     from pydantic.v1 import BaseModel


Test patch:
diff --git a/test/model/test_node.py b/test/model/test_node.py
index c8238ba3e..1a8a042b3 100644
--- a/test/model/test_node.py
+++ b/test/model/test_node.py
@@ -1,7 +1,7 @@
 """Test the node model."""
 import asyncio
 from copy import deepcopy
-from datetime import datetime, timezone
+from datetime import UTC, datetime
 import json
 from typing import Any
 from unittest.mock import AsyncMock, patch
@@ -185,7 +185,7 @@ def test_from_state(client):
         },
     )
     node.receive_event(event)
-    assert node.last_seen == datetime(2023, 7, 18, 15, 42, 34, 701000, timezone.utc)
+    assert node.last_seen == datetime(2023, 7, 18, 15, 42, 34, 701000, UTC)
 
 
 async def test_highest_security_value(lock_schlage_be469, ring_keypad):