Skip to content

Commit ce71a2d

Browse files
authored
Migrate to pyproject.toml and Git versioning (#568)
* Migrate to `pyproject.toml` * Switch from `setup.py bdist_wheel` to `python -m build`
1 parent a93f8ac commit ce71a2d

9 files changed

+81
-69
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ jobs:
1616
python-version: 3.8
1717
- name: Install wheel
1818
run: >-
19-
pip install wheel
19+
pip install wheel build
2020
- name: Build
2121
run: >-
22-
python3 setup.py sdist bdist_wheel
22+
python3 -m build
2323
- name: Publish distribution to PyPI
2424
uses: pypa/gh-action-pypi-publish@master
2525
with:

.pre-commit-config.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ repos:
2121
rev: 6.0.0
2222
hooks:
2323
- id: flake8
24+
additional_dependencies:
25+
- Flake8-pyproject==1.2.3
2426

2527
- repo: https://github.com/PyCQA/isort
2628
rev: 5.12.0

bellows/__init__.py

-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +0,0 @@
1-
MAJOR_VERSION = 0
2-
MINOR_VERSION = 36
3-
PATCH_VERSION = "0.dev0"
4-
__short_version__ = f"{MAJOR_VERSION}.{MINOR_VERSION}"
5-
__version__ = f"{__short_version__}.{PATCH_VERSION}"

bellows/zigbee/application.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
else:
1212
from asyncio import timeout as asyncio_timeout # pragma: no cover
1313

14+
import importlib.metadata
15+
1416
import zigpy.application
1517
import zigpy.config
1618
import zigpy.device
@@ -264,7 +266,7 @@ async def load_network_info(self, *, load_devices=False) -> None:
264266
can_rewrite_custom_eui64 = await ezsp.can_rewrite_custom_eui64()
265267

266268
self.state.network_info = zigpy.state.NetworkInfo(
267-
source=f"bellows@{bellows.__version__}",
269+
source=f"bellows@{importlib.metadata.version('bellows')}",
268270
extended_pan_id=zigpy.types.ExtendedPanId(nwk_params.extendedPanId),
269271
pan_id=zigpy.types.PanId(nwk_params.panId),
270272
nwk_update_id=zigpy.types.uint8_t(nwk_params.nwkUpdateId),

pyproject.toml

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
[build-system]
2+
requires = ["setuptools>=61.0.0", "wheel", "setuptools-git-versioning<2"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "bellows"
7+
dynamic = ["version"]
8+
description = "Library implementing EZSP"
9+
urls = {repository = "https://github.com/zigpy/bellows"}
10+
authors = [
11+
{name = "Russell Cloran", email = "[email protected]"}
12+
]
13+
readme = "README.md"
14+
license = {text = "GPL-3.0"}
15+
requires-python = ">=3.8"
16+
dependencies = [
17+
"click",
18+
"click-log>=0.2.1",
19+
"pure_pcapy3==1.0.1",
20+
"voluptuous",
21+
"zigpy>=0.54.1",
22+
'async-timeout; python_version<"3.11"',
23+
]
24+
25+
[tool.setuptools.packages.find]
26+
exclude = ["tests", "tests.*"]
27+
28+
[project.optional-dependencies]
29+
testing = [
30+
"pytest>=7.1.2",
31+
"pytest-asyncio>=0.19.0",
32+
"pytest-timeout>=2.1.0",
33+
"pytest-mock>=3.8.2",
34+
"pytest-cov>=3.0.0",
35+
]
36+
37+
[tool.setuptools-git-versioning]
38+
enabled = true
39+
40+
[project.scripts]
41+
bellows = "bellows.cli.main:main"
42+
43+
[tool.isort]
44+
profile = "black"
45+
# will group `import x` and `from x import` of the same module.
46+
force_sort_within_sections = true
47+
known_first_party = ["bellows", "tests"]
48+
forced_separate = "tests"
49+
combine_as_imports = true
50+
51+
[tool.mypy]
52+
ignore_errors = true
53+
54+
[tool.pytest.ini_options]
55+
asyncio_mode = "auto"
56+
57+
[tool.flake8]
58+
exclude = [".venv", ".git", ".tox", "docs", "venv", "bin", "lib", "deps", "build"]
59+
# To work with Black
60+
max-line-length = 88
61+
# W503: Line break occurred before a binary operator
62+
# E203: Whitespace before ':'
63+
# E501: line too long
64+
# D202 No blank lines allowed after function docstring
65+
ignore = ["W503", "E203", "E501", "D202"]
66+
per-file-ignores = ["tests/*:F811,F401,F403"]

requirements_test.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ pytest-timeout
1616
pytest-asyncio>=0.17
1717
pytest>=7.1.3
1818
zigpy>=0.54.1
19-
ruff==0.0.261
19+
ruff==0.0.261
20+
Flake8-pyproject

setup.cfg

-30
This file was deleted.

setup.py

+3-28
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,4 @@
1-
"""Setup module for bellows"""
1+
import setuptools
22

3-
from setuptools import find_packages, setup
4-
5-
import bellows
6-
7-
setup(
8-
name="bellows",
9-
version=bellows.__version__,
10-
description="Library implementing EZSP",
11-
url="http://github.com/zigpy/bellows",
12-
author="Russell Cloran",
13-
author_email="[email protected]",
14-
license="GPL-3.0",
15-
packages=find_packages(exclude=["tests", "tests.*"]),
16-
entry_points={"console_scripts": ["bellows=bellows.cli.main:main"]},
17-
install_requires=[
18-
"click",
19-
"click-log>=0.2.1",
20-
"pure_pcapy3==1.0.1",
21-
"voluptuous",
22-
"zigpy>=0.54.1",
23-
'async-timeout; python_version<"3.11"',
24-
],
25-
dependency_links=[
26-
"https://codeload.github.com/rcloran/pure-pcapy-3/zip/master",
27-
],
28-
tests_require=["asynctest", "pytest", "pytest-asyncio"],
29-
)
3+
if __name__ == "__main__":
4+
setuptools.setup()

tests/test_application_network_state.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import importlib.metadata
2+
13
import pytest
24
import zigpy.state
35
import zigpy.types as zigpy_t
46
import zigpy.zdo.types as zdo_t
57

6-
import bellows
78
from bellows.exception import EzspError
89
import bellows.types as t
910

@@ -70,7 +71,7 @@ def network_info(node_info):
7071
zigpy_t.EUI64.convert("00:0b:57:ff:fe:2b:d4:57"): zigpy_t.NWK(0xC06B),
7172
},
7273
stack_specific={"ezsp": {"hashed_tclk": "abcdabcdabcdabcdabcdabcdabcdabcd"}},
73-
source=f"bellows@{bellows.__version__}",
74+
source=f"bellows@{importlib.metadata.version('bellows')}",
7475
)
7576

7677

0 commit comments

Comments
 (0)