Skip to content

Commit 7f4f200

Browse files
committed
feat: add publish-to-test-pypi.yml
Signed-off-by: Milad Makdesi <milad@id8-engineering.io>
1 parent 1a8fcb4 commit 7f4f200

5 files changed

Lines changed: 123 additions & 10 deletions

File tree

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: publish-to-test-pypi
2+
3+
on:
4+
push:
5+
branches: ["test_pypi"]
6+
7+
jobs:
8+
build:
9+
name: Build distribution
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
15+
16+
- name: Set up Python
17+
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c
18+
with:
19+
python-version: "3.x"
20+
21+
- name: Install uv
22+
uses: astral-sh/setup-uv@85856786d1ce8acfbcc2f13a5f3fbd6b938f9f41 # v7.1.2
23+
24+
- name: Install hatch
25+
run: uv tool install hatch
26+
27+
- name: Clean build artifacts
28+
run: |
29+
rm -rf dist/*
30+
rm -rf build/*
31+
rm -f src/em511/_version.py
32+
33+
- name: Build distributions with uv
34+
run: uv build
35+
36+
- name: DEBUG - list installed packages
37+
run: uv pip list
38+
39+
- name: Upload distributions as artifact
40+
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
41+
with:
42+
name: python-package-distributions-${{ github.run_id }}
43+
path: dist/n-package-distributions
44+
45+
publish-to-test-pypi:
46+
name: Publish Python distribution to TestPyPI
47+
needs: [build]
48+
runs-on: ubuntu-latest
49+
50+
environment:
51+
name: testpypi
52+
url: https://test.pypi.org/p/python-em511
53+
54+
permissions:
55+
id-token: write
56+
57+
steps:
58+
- name: Download all build artifacts
59+
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
60+
with:
61+
name: python-package-distributions-${{ github.run_id }}
62+
path: dist/
63+
64+
- name: Publish to TestPyPI
65+
uses: pypa/gh-action-pypi-publish@release/v1
66+
with:
67+
repository-url: https://test.pypi.org/legacy/
68+
verbose: true

pyproject.toml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
[project]
22
name = "python-em511"
3-
version = "0.0.1"
3+
dynamic = ["version"]
44
description = "Driver for Carlo Gavazzi EM511 Series Single Phase Energy Meters using Modbus RTU"
55
readme = "README.md"
66

77
license = "MIT"
8-
license-files = ["LICENSE"]
98

109
authors = [
1110
{ name = "Mirza Krak", email = "mirza@mkrak.org" },
@@ -17,15 +16,16 @@ maintainers = [
1716
{ name = "Bobo Bäck Engström", email = "bobo@id8-engineering.io"},
1817
{ name = "Milad Makdesi", email = "milad@id8-engineering.io"},
1918
]
19+
2020
requires-python = ">=3.10"
21+
2122
dependencies = [
2223
"pymodbus[serial]>=3.11"
2324
]
2425

2526
classifiers = [
2627
"Development Status :: 3 - Alpha",
2728
"Intended Audience :: Developers",
28-
"License :: OSI Approved :: MIT License",
2929
"Operating System :: OS Independent",
3030
"Programming Language :: Python :: 3.10",
3131
"Programming Language :: Python :: 3.11",
@@ -36,11 +36,15 @@ classifiers = [
3636
]
3737

3838
[build-system]
39-
requires = ["hatchling"]
40-
build-backend = "hatchling.build"
39+
requires = ["setuptools>=64", "setuptools-scm"]
40+
build-backend = "setuptools.build_meta"
41+
42+
[tool.setuptools.packages.find]
43+
where = ["src"]
4144

42-
[tool.hatch.build.targets.wheel]
43-
packages = ["src/em511"]
45+
[tool.setuptools_scm]
46+
write_to = "src/em511/_version.py"
47+
local_scheme = "no-local-version"
4448

4549
[dependency-groups]
4650
dev = [
@@ -52,12 +56,13 @@ dev = [
5256

5357
[tool.ruff]
5458
line-length = 120
59+
exclude = ["src/em511/_version.py"]
5560

5661
[tool.ruff.lint]
5762
select = ["ALL"]
5863

5964
ignore = [
60-
"COM812", # in conflict with formatter
65+
"COM812", # in conflict with formatter
6166
]
6267

6368
[tool.ruff.lint.pydocstyle]

src/em511/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
using Carlo Gavazzi EM511 energy meters.
55
"""
66

7+
from importlib.metadata import PackageNotFoundError, version
8+
79
from .em511 import Em511
810

9-
__all__ = ["Em511"]
11+
__all__ = ["Em511", "__version__"]
12+
13+
try:
14+
__version__ = version("python-em511")
15+
except PackageNotFoundError:
16+
__version__ = "0.0.1"

src/em511/_version.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# file generated by setuptools-scm
2+
# don't change, don't track in version control
3+
4+
__all__ = [
5+
"__version__",
6+
"__version_tuple__",
7+
"version",
8+
"version_tuple",
9+
"__commit_id__",
10+
"commit_id",
11+
]
12+
13+
TYPE_CHECKING = False
14+
if TYPE_CHECKING:
15+
from typing import Tuple
16+
from typing import Union
17+
18+
VERSION_TUPLE = Tuple[Union[int, str], ...]
19+
COMMIT_ID = Union[str, None]
20+
else:
21+
VERSION_TUPLE = object
22+
COMMIT_ID = object
23+
24+
version: str
25+
__version__: str
26+
__version_tuple__: VERSION_TUPLE
27+
version_tuple: VERSION_TUPLE
28+
commit_id: COMMIT_ID
29+
__commit_id__: COMMIT_ID
30+
31+
__version__ = version = '0.1.dev85'
32+
__version_tuple__ = version_tuple = (0, 1, 'dev85')
33+
34+
__commit_id__ = commit_id = 'gc2eed89c5'

uv.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)