From 0afa2760319242803e9766582231e618a2194597 Mon Sep 17 00:00:00 2001 From: puddly <32534428+puddly@users.noreply.github.com> Date: Fri, 10 Feb 2023 15:44:41 -0500 Subject: [PATCH 1/4] Migrate to `pyproject.toml` and remove package versioning from Git repo --- .github/workflows/publish-to-pypi.yml | 22 ++++++++++------ pyproject.toml | 35 +++++++++++++++++++++++++- setup.cfg | 36 --------------------------- 3 files changed, 48 insertions(+), 45 deletions(-) delete mode 100644 setup.cfg diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml index f607e707..6a6124dd 100644 --- a/.github/workflows/publish-to-pypi.yml +++ b/.github/workflows/publish-to-pypi.yml @@ -1,26 +1,32 @@ name: Publish distributions to PyPI and TestPyPI on: - push: - tags: - - "*" + release: + types: + - published jobs: build-and-publish: name: Build and publish distributions to PyPI and TestPyPI runs-on: ubuntu-latest steps: - - uses: actions/checkout@master + - uses: actions/checkout@v3 - name: Set up Python 3.8 - uses: actions/setup-python@v1 + uses: actions/setup-python@v4 with: python-version: 3.8 + - name: Set package version + run: | + version="${{ github.event.release.tag_name }}" + version="${version,,}" # lowercase it + version="${version#v}" # remove `v` + sed -i "s/version = \"0\.0\.0\"/version = \"${version}\"/" pyproject.toml - name: Install wheel run: >- - pip install wheel + pip install wheel build - name: Build run: >- - python3 setup.py sdist bdist_wheel + python3 -m build - name: Publish distribution to PyPI - uses: pypa/gh-action-pypi-publish@master + uses: pypa/gh-action-pypi-publish@release/v1 with: password: ${{ secrets.PYPI_TOKEN }} diff --git a/pyproject.toml b/pyproject.toml index a820c54e..5825ddd8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,40 @@ [build-system] -requires = ["setuptools>=34.4.0", "wheel"] +requires = ["setuptools>=61.0.0"] build-backend = "setuptools.build_meta" +[project] +name = "zigpy-znp" +version = "0.0.0" +description = "A library for zigpy which communicates with TI ZNP radios" +urls = {repository = "https://github.com/zigpy/zigpy-znp"} +authors = [ + {name = "Alexei Chetroi", email = "alexei.chetroi@outlook.com"} +] +readme = "README.md" +license = {text = "GPL-3.0"} +requires-python = ">=3.8" +dependencies = [ + "zigpy>=0.52.0", + "async_timeout", + "voluptuous", + "coloredlogs", + "jsonschema", +] + +[tool.setuptools.packages.find] +exclude = ["tests", "tests.*"] + +[project.optional-dependencies] +testing = [ + "pytest>=7.1.2", + "pytest-asyncio>=0.19.0", + "pytest-timeout>=2.1.0", + "pytest-mock>=3.8.2", + "pytest-cov>=3.0.0", + "coveralls", +] + + [tool.black] safe = true quiet = true diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 48ed1daf..00000000 --- a/setup.cfg +++ /dev/null @@ -1,36 +0,0 @@ -[metadata] -name = zigpy-znp -description = A library for zigpy which communicates with TI ZNP radios -version = attr: zigpy_znp.__version__ -long_description = file: README.md -long_description_content_type = text/markdown; charset=UTF-8 -url = https://github.com/zigpy/zigpy-znp -author = Alexei Chetroi -author_email = alexei.chetroi@outlook.com -license = GPL-3.0 - -[options] -packages = find: -python_requires = >=3.8 -install_requires = - zigpy>=0.52.0 - async_timeout - voluptuous - coloredlogs - jsonschema - -[options.packages.find] -exclude = - tests - tests.* - -[options.extras_require] -# XXX: The order of these deps seems to matter -testing = - pytest>=7.1.2 - pytest-asyncio>=0.19.0 - pytest-timeout>=2.1.0 - pytest-mock>=3.8.2 - pytest-cov>=3.0.0 - coveralls - asynctest; python_version < "3.8.0" From 206df48dde317e9d69e82efd67b7c42617f9e538 Mon Sep 17 00:00:00 2001 From: puddly <32534428+puddly@users.noreply.github.com> Date: Fri, 10 Feb 2023 15:46:13 -0500 Subject: [PATCH 2/4] Remove version from `__init__.py` --- zigpy_znp/__init__.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/zigpy_znp/__init__.py b/zigpy_znp/__init__.py index 0e9f158d..e69de29b 100644 --- a/zigpy_znp/__init__.py +++ b/zigpy_znp/__init__.py @@ -1,6 +0,0 @@ -MAJOR_VERSION = 0 -MINOR_VERSION = 9 -PATCH_VERSION = 2 - -__short_version__ = f"{MAJOR_VERSION}.{MINOR_VERSION}" -__version__ = f"{__short_version__}.{PATCH_VERSION}" From 5015cb3b3c9175bdc61d9693dbfcbfb584c617b9 Mon Sep 17 00:00:00 2001 From: puddly <32534428+puddly@users.noreply.github.com> Date: Fri, 10 Feb 2023 15:47:49 -0500 Subject: [PATCH 3/4] Remove tox --- pyproject.toml | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 5825ddd8..9d210143 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -89,29 +89,3 @@ source = ["zigpy_znp"] [tool.pyupgrade] py37plus = true - -[tool.tox] -legacy_tox_ini = """ -[tox] -envlist = py37, py38, py39, lint, black -skip_missing_interpreters = True - -[testenv] -setenv = PYTHONPATH = {toxinidir} -extras = testing -commands = py.test --cov --cov-report=html - -[testenv:lint] -basepython = python3 -deps = flake8 -commands = flake8 - -[testenv:black] -deps = - black==20.8.b1 -setenv = - LC_ALL=C.UTF-8 - LANG=C.UTF-8 -commands= - black --check --fast {toxinidir}/zigpy_znp {toxinidir}/tests {toxinidir}/setup.py -""" From 0fa378b86093296e61416ee3b6a11aa31be6b125 Mon Sep 17 00:00:00 2001 From: puddly <32534428+puddly@users.noreply.github.com> Date: Fri, 10 Feb 2023 15:51:35 -0500 Subject: [PATCH 4/4] Use `pkg_resources` internally to get the package version --- .pre-commit-config.yaml | 1 + zigpy_znp/api.py | 5 +++-- zigpy_znp/tools/network_backup.py | 5 +++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 93905b89..033bdf89 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -34,6 +34,7 @@ repos: - id: mypy additional_dependencies: - zigpy + - types-setuptools - repo: https://github.com/asottile/pyupgrade rev: v3.3.1 diff --git a/zigpy_znp/api.py b/zigpy_znp/api.py index b82a38f4..bf6f7667 100644 --- a/zigpy_znp/api.py +++ b/zigpy_znp/api.py @@ -12,11 +12,11 @@ import zigpy.state import async_timeout +import pkg_resources import zigpy.zdo.types as zdo_t import zigpy.exceptions from zigpy.exceptions import NetworkNotFormed -import zigpy_znp import zigpy_znp.const as const import zigpy_znp.types as t import zigpy_znp.config as conf @@ -136,9 +136,10 @@ async def _load_network_info(self, *, load_devices=False): ) version = await self.request(c.SYS.Version.Req()) + package_version = pkg_resources.get_distribution("zigpy_znp").version network_info = zigpy.state.NetworkInfo( - source=f"zigpy-znp@{zigpy_znp.__version__}", + source=f"zigpy-znp@{package_version}", extended_pan_id=nib.extendedPANID, pan_id=nib.nwkPanId, nwk_update_id=nib.nwkUpdateId, diff --git a/zigpy_znp/tools/network_backup.py b/zigpy_znp/tools/network_backup.py index f5f9c521..4b499a64 100644 --- a/zigpy_znp/tools/network_backup.py +++ b/zigpy_znp/tools/network_backup.py @@ -7,8 +7,8 @@ import datetime import zigpy.state +import pkg_resources -import zigpy_znp import zigpy_znp.types as t from zigpy_znp.api import ZNP from zigpy_znp.tools.common import ClosableFileType, setup_parser, validate_backup_json @@ -84,7 +84,8 @@ async def backup_network(znp: ZNP) -> t.JSONType: now = datetime.datetime.now().astimezone() - obj["metadata"]["source"] = f"zigpy-znp@{zigpy_znp.__version__}" + package_version = pkg_resources.get_distribution("zigpy_znp").version + obj["metadata"]["source"] = f"zigpy-znp@{package_version}" obj["metadata"]["internal"] = { "creation_time": now.isoformat(timespec="seconds"), "zstack": {