Skip to content

Commit 36c5d09

Browse files
authored
Remove package versioning from Git repo and migrate to pyproject.toml (#202)
* Migrate to `pyproject.toml` and remove package versioning from Git repo * Remove version from `__init__.py` * Remove tox * Use `pkg_resources` internally to get the package version
1 parent 5d3c904 commit 36c5d09

File tree

7 files changed

+55
-81
lines changed

7 files changed

+55
-81
lines changed

.github/workflows/publish-to-pypi.yml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
11
name: Publish distributions to PyPI and TestPyPI
22
on:
3-
push:
4-
tags:
5-
- "*"
3+
release:
4+
types:
5+
- published
66

77
jobs:
88
build-and-publish:
99
name: Build and publish distributions to PyPI and TestPyPI
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@master
12+
- uses: actions/checkout@v3
1313
- name: Set up Python 3.8
14-
uses: actions/setup-python@v1
14+
uses: actions/setup-python@v4
1515
with:
1616
python-version: 3.8
17+
- name: Set package version
18+
run: |
19+
version="${{ github.event.release.tag_name }}"
20+
version="${version,,}" # lowercase it
21+
version="${version#v}" # remove `v`
22+
sed -i "s/version = \"0\.0\.0\"/version = \"${version}\"/" pyproject.toml
1723
- name: Install wheel
1824
run: >-
19-
pip install wheel
25+
pip install wheel build
2026
- name: Build
2127
run: >-
22-
python3 setup.py sdist bdist_wheel
28+
python3 -m build
2329
- name: Publish distribution to PyPI
24-
uses: pypa/gh-action-pypi-publish@master
30+
uses: pypa/gh-action-pypi-publish@release/v1
2531
with:
2632
password: ${{ secrets.PYPI_TOKEN }}

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ repos:
3434
- id: mypy
3535
additional_dependencies:
3636
- zigpy
37+
- types-setuptools
3738

3839
- repo: https://github.com/asottile/pyupgrade
3940
rev: v3.3.1

pyproject.toml

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,40 @@
11
[build-system]
2-
requires = ["setuptools>=34.4.0", "wheel"]
2+
requires = ["setuptools>=61.0.0"]
33
build-backend = "setuptools.build_meta"
44

5+
[project]
6+
name = "zigpy-znp"
7+
version = "0.0.0"
8+
description = "A library for zigpy which communicates with TI ZNP radios"
9+
urls = {repository = "https://github.com/zigpy/zigpy-znp"}
10+
authors = [
11+
{name = "Alexei Chetroi", email = "[email protected]"}
12+
]
13+
readme = "README.md"
14+
license = {text = "GPL-3.0"}
15+
requires-python = ">=3.8"
16+
dependencies = [
17+
"zigpy>=0.52.0",
18+
"async_timeout",
19+
"voluptuous",
20+
"coloredlogs",
21+
"jsonschema",
22+
]
23+
24+
[tool.setuptools.packages.find]
25+
exclude = ["tests", "tests.*"]
26+
27+
[project.optional-dependencies]
28+
testing = [
29+
"pytest>=7.1.2",
30+
"pytest-asyncio>=0.19.0",
31+
"pytest-timeout>=2.1.0",
32+
"pytest-mock>=3.8.2",
33+
"pytest-cov>=3.0.0",
34+
"coveralls",
35+
]
36+
37+
538
[tool.black]
639
safe = true
740
quiet = true
@@ -56,29 +89,3 @@ source = ["zigpy_znp"]
5689

5790
[tool.pyupgrade]
5891
py37plus = true
59-
60-
[tool.tox]
61-
legacy_tox_ini = """
62-
[tox]
63-
envlist = py37, py38, py39, lint, black
64-
skip_missing_interpreters = True
65-
66-
[testenv]
67-
setenv = PYTHONPATH = {toxinidir}
68-
extras = testing
69-
commands = py.test --cov --cov-report=html
70-
71-
[testenv:lint]
72-
basepython = python3
73-
deps = flake8
74-
commands = flake8
75-
76-
[testenv:black]
77-
deps =
78-
black==20.8.b1
79-
setenv =
80-
LC_ALL=C.UTF-8
81-
LANG=C.UTF-8
82-
commands=
83-
black --check --fast {toxinidir}/zigpy_znp {toxinidir}/tests {toxinidir}/setup.py
84-
"""

setup.cfg

Lines changed: 0 additions & 36 deletions
This file was deleted.

zigpy_znp/__init__.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +0,0 @@
1-
MAJOR_VERSION = 0
2-
MINOR_VERSION = 9
3-
PATCH_VERSION = 2
4-
5-
__short_version__ = f"{MAJOR_VERSION}.{MINOR_VERSION}"
6-
__version__ = f"{__short_version__}.{PATCH_VERSION}"

zigpy_znp/api.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212

1313
import zigpy.state
1414
import async_timeout
15+
import pkg_resources
1516
import zigpy.zdo.types as zdo_t
1617
import zigpy.exceptions
1718
from zigpy.exceptions import NetworkNotFormed
1819

19-
import zigpy_znp
2020
import zigpy_znp.const as const
2121
import zigpy_znp.types as t
2222
import zigpy_znp.config as conf
@@ -136,9 +136,10 @@ async def _load_network_info(self, *, load_devices=False):
136136
)
137137

138138
version = await self.request(c.SYS.Version.Req())
139+
package_version = pkg_resources.get_distribution("zigpy_znp").version
139140

140141
network_info = zigpy.state.NetworkInfo(
141-
source=f"zigpy-znp@{zigpy_znp.__version__}",
142+
source=f"zigpy-znp@{package_version}",
142143
extended_pan_id=nib.extendedPANID,
143144
pan_id=nib.nwkPanId,
144145
nwk_update_id=nib.nwkUpdateId,

zigpy_znp/tools/network_backup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
import datetime
88

99
import zigpy.state
10+
import pkg_resources
1011

11-
import zigpy_znp
1212
import zigpy_znp.types as t
1313
from zigpy_znp.api import ZNP
1414
from zigpy_znp.tools.common import ClosableFileType, setup_parser, validate_backup_json
@@ -84,7 +84,8 @@ async def backup_network(znp: ZNP) -> t.JSONType:
8484

8585
now = datetime.datetime.now().astimezone()
8686

87-
obj["metadata"]["source"] = f"zigpy-znp@{zigpy_znp.__version__}"
87+
package_version = pkg_resources.get_distribution("zigpy_znp").version
88+
obj["metadata"]["source"] = f"zigpy-znp@{package_version}"
8889
obj["metadata"]["internal"] = {
8990
"creation_time": now.isoformat(timespec="seconds"),
9091
"zstack": {

0 commit comments

Comments
 (0)