Skip to content

Commit 5d33ce7

Browse files
psssclaude
andauthored
Convert to hatch build system and enable packit (#35)
Replace `setup.py` with `hatchling` and `hatch-vcs` for build and version management. Add the spec file and packit configuration to enable copr builds for pull requests and automate the Fedora release pipeline. Add a release workflow for publishing to pypi. Fix #31. --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 6edea25 commit 5d33ce7

8 files changed

Lines changed: 283 additions & 77 deletions

File tree

.github/workflows/release.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: release
2+
run-name: Release ${{ inputs.ref || github.ref_name }}
3+
4+
on:
5+
release:
6+
types: [published]
7+
workflow_dispatch:
8+
inputs:
9+
ref:
10+
type: string
11+
description: 'Tag to release'
12+
required: true
13+
14+
permissions: {}
15+
16+
jobs:
17+
build:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
21+
with:
22+
ref: ${{ inputs.ref }}
23+
persist-credentials: false
24+
- uses: hynek/build-and-inspect-python-package@2abe76da66d0a6a4a227101f9348ee855797cfa5 # v3.0.1
25+
26+
deploy:
27+
needs: [build]
28+
runs-on: ubuntu-latest
29+
environment:
30+
name: pypi
31+
url: https://pypi.org/p/testcloud
32+
permissions:
33+
id-token: write
34+
attestations: write
35+
36+
steps:
37+
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
38+
with:
39+
name: Packages
40+
path: dist
41+
42+
- name: Generate artifact attestation for sdist and wheel
43+
uses: actions/attest-build-provenance@0f67c3f4856b2e3261c31976d6725780e5e4c373 # v4.1.1
44+
with:
45+
subject-path: "dist/*"
46+
47+
- name: Publish to PyPI
48+
uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2

.packit.yaml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
3+
specfile_path: packaging/rpm/testcloud.spec
4+
files_to_sync:
5+
- src: packaging/rpm/
6+
dest: ./
7+
delete: true
8+
filters:
9+
- "protect .git*"
10+
- "protect sources"
11+
- "protect changelog"
12+
- .packit.yaml
13+
14+
upstream_package_name: testcloud
15+
downstream_package_name: testcloud
16+
17+
upstream_project_url: https://github.com/teemtee/testcloud
18+
issue_repository: https://github.com/teemtee/testcloud
19+
20+
srpm_build_deps:
21+
- hatch
22+
- python3-hatch-vcs
23+
24+
actions:
25+
create-archive:
26+
- hatch build -t sdist
27+
- bash -c "echo dist/testcloud-$PACKIT_PROJECT_VERSION.tar.gz"
28+
get-current-version:
29+
- hatch version
30+
31+
targets: &all-targets
32+
- fedora-all
33+
- epel-9
34+
- epel-10
35+
36+
jobs:
37+
# Build pull requests
38+
- job: copr_build
39+
trigger: pull_request
40+
41+
# Propose downstream pull requests
42+
- job: propose_downstream
43+
trigger: release
44+
dist_git_branches:
45+
rawhide:
46+
fast_forward_merge_into:
47+
- fedora-branched
48+
- epel-10
49+
- epel-9
50+
51+
# Create koji builds
52+
- job: koji_build
53+
trigger: commit
54+
allowed_pr_authors: ["packit", "all_committers"]
55+
dist_git_branches: *all-targets
56+
57+
# Create bodhi updates
58+
- job: bodhi_update
59+
trigger: commit
60+
dist_git_branches:
61+
- fedora-branched
62+
- epel-10
63+
- epel-9

docs/source/conf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# All configuration values have a default; values that are commented out
1313
# serve to show the default.
1414

15+
import importlib.metadata
1516
import sys
1617
import os
1718

@@ -55,7 +56,7 @@
5556
# built documents.
5657
#
5758
# The short X.Y version.
58-
version = "0.11.8"
59+
version = importlib.metadata.version("testcloud")
5960
# The full version, including alpha/beta/rc tags.
6061
release = version
6162

packaging/rpm/testcloud.spec

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
%if 0%{?rhel} <= 9
2+
%global _sysusersdir /usr/lib/sysusers.d
3+
%endif
4+
5+
Name: testcloud
6+
Version: 0.0.0
7+
Release: %autorelease
8+
Summary: Tool for running cloud images locally
9+
10+
License: GPL-2.0-or-later
11+
URL: https://github.com/teemtee/testcloud
12+
Source0: %{pypi_source testcloud}
13+
Source1: testcloud.sysusers
14+
15+
ExclusiveArch: %{kernel_arches} noarch
16+
BuildArch: noarch
17+
18+
BuildRequires: systemd-rpm-macros
19+
%{?sysusers_requires_compat}
20+
21+
Requires: polkit
22+
23+
Recommends: edk2-ovmf
24+
25+
Requires: python3-%{name} = %{version}-%{release}
26+
27+
%description
28+
testcloud is a relatively simple system which is capable of booting images
29+
designed for cloud systems on a local system with minimal configuration.
30+
testcloud is designed to be (and remain) somewhat simple, trading fancy cloud
31+
system features for ease of use and sanity in development.
32+
33+
%package -n python3-%{name}
34+
Summary: Python 3 interface to testcloud
35+
36+
BuildRequires: bash-completion
37+
BuildRequires: python3-devel
38+
BuildRequires: python3-pytest
39+
40+
Requires: acl
41+
Requires: genisoimage
42+
Requires: libvirt-daemon
43+
Requires: libvirt-daemon-config-network
44+
Requires: libvirt-daemon-driver-qemu
45+
Requires: libvirt-daemon-driver-storage-core
46+
Recommends: butane
47+
Suggests: python3-libguestfs
48+
Suggests: libguestfs-tools-c
49+
50+
%description -n python3-%{name}
51+
Python 3 interface to testcloud.
52+
53+
%pre
54+
%sysusers_create_compat %{SOURCE1}
55+
56+
%prep
57+
%autosetup -n %{name}-%{version} -p1
58+
# Drop coverage testing
59+
sed -i 's/ --cov-report=term-missing --cov testcloud//g' tox.ini
60+
61+
%generate_buildrequires
62+
%pyproject_buildrequires
63+
64+
%build
65+
export SETUPTOOLS_SCM_PRETEND_VERSION=%{version}
66+
%pyproject_wheel
67+
68+
%install
69+
%pyproject_install
70+
%pyproject_save_files testcloud
71+
72+
# man page
73+
mkdir -p %{buildroot}%{_mandir}/man1
74+
install -pm 644 manpages/testcloud.1 %{buildroot}%{_mandir}/man1
75+
76+
# bash completion
77+
mkdir -p %{buildroot}%{_datadir}/bash-completion/completions
78+
install -pm 644 conf/testcloud %{buildroot}%{_datadir}/bash-completion/completions/testcloud
79+
80+
# configuration files
81+
mkdir -p %{buildroot}%{_sysconfdir}/testcloud/
82+
install conf/settings-example.py %{buildroot}%{_sysconfdir}/testcloud/settings.py
83+
84+
# Create running directory for testcloud
85+
install -d %{buildroot}%{_sharedstatedir}/testcloud/
86+
87+
# backingstores dir
88+
install -d %{buildroot}/%{_sharedstatedir}/testcloud/backingstores
89+
90+
# instance dir
91+
install -d %{buildroot}/%{_sharedstatedir}/testcloud/instances
92+
93+
# create polkit rules dir and install polkit rule
94+
mkdir -p %{buildroot}%{_sysconfdir}/polkit-1/rules.d
95+
install conf/99-testcloud-nonroot-libvirt-access.rules %{buildroot}%{_sysconfdir}/polkit-1/rules.d/99-testcloud-nonroot-libvirt-access.rules
96+
97+
# sysusers conf file for creation of testcloud group
98+
install -p -m644 -D %{SOURCE1} %{buildroot}%{_sysusersdir}/%{name}.conf
99+
100+
%check
101+
%pyproject_check_import
102+
%pytest
103+
104+
%files
105+
%doc README.md
106+
%{_mandir}/man1/testcloud.1*
107+
%license LICENSE
108+
109+
%dir %{_sysconfdir}/testcloud
110+
%dir %attr(0775, qemu, testcloud) %{_sharedstatedir}/testcloud
111+
%dir %attr(0775, qemu, testcloud) %{_sharedstatedir}/testcloud/backingstores
112+
%dir %attr(0775, qemu, testcloud) %{_sharedstatedir}/testcloud/instances
113+
114+
%attr(0644, root, root) %{_sysconfdir}/polkit-1/rules.d/99-testcloud-nonroot-libvirt-access.rules
115+
116+
%config(noreplace) %{_sysconfdir}/testcloud/settings.py
117+
%{_bindir}/testcloud
118+
%{_bindir}/t7d
119+
%{_datadir}/bash-completion/completions/testcloud
120+
121+
%{_sysusersdir}/%{name}.conf
122+
123+
%files -n python3-%{name} -f %{pyproject_files}
124+
125+
%changelog
126+
%autochangelog

packaging/rpm/testcloud.sysusers

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
g testcloud -

pyproject.toml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,42 @@
1+
[build-system]
2+
requires = ["hatchling", "hatch-vcs"]
3+
build-backend = "hatchling.build"
4+
5+
[project]
6+
name = "testcloud"
7+
dynamic = ["version"]
8+
description = "A tool to download and boot cloud images locally, with an easy to use API."
9+
readme = "README.md"
10+
license = "GPL-2.0-or-later"
11+
requires-python = ">=3.9"
12+
authors = [
13+
{name = "Mike Ruckman", email = "roshi@fedoraproject.org"},
14+
]
15+
dependencies = [
16+
"libvirt-python",
17+
"peewee",
18+
"requests",
19+
"packaging",
20+
"fedora-distro-aliases>=1.5",
21+
]
22+
23+
[project.optional-dependencies]
24+
image_resolve_caching = ["requests_cache>=1.2"]
25+
26+
[project.scripts]
27+
testcloud = "testcloud.cli:main"
28+
t7d = "testcloud.cli:main"
29+
30+
[project.urls]
31+
Homepage = "https://github.com/teemtee/testcloud"
32+
33+
[tool.hatch.version]
34+
source = "vcs"
35+
raw-options.version_scheme = "release-branch-semver"
36+
raw-options.git_describe_command = [
37+
"git", "describe", "--dirty", "--tags", "--long",
38+
"--abbrev=9", "--match", "*[0-9]*",
39+
]
40+
141
[tool.black]
242
line-length=140

setup.py

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

testcloud/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# NOTE: if you update version, *make sure* to also update `docs/source/conf.py`
2-
__version__ = "0.11.8"
3-
1+
import importlib.metadata
42
import signal
53
import sys
64
import threading
75

6+
__version__ = importlib.metadata.version(__name__)
7+
88

99
def sigterm_handler(_signo, _stack_frame):
1010
# A call to sys.exit() is translated into an exception so that clean-up handlers

0 commit comments

Comments
 (0)