Skip to content

Commit 909e16c

Browse files
committed
Modern Python packaging
1 parent 9031424 commit 909e16c

File tree

8 files changed

+209
-154
lines changed

8 files changed

+209
-154
lines changed

.github/workflows/build.yml

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,48 @@
22
# vi: ts=2 sw=2 et:
33
# SPDX-License-Identifier: LGPL-2.1-or-later
44
#
5-
name: Build test
5+
name: Build
66
on:
77
pull_request:
88
push:
99
branches:
1010
- main
11+
- feature/meson-build
1112

1213
permissions:
1314
contents: read
1415

1516
jobs:
1617
build:
17-
runs-on: ubuntu-20.04
18-
concurrency:
19-
group: ${{ github.workflow }}-${{ matrix.python }}-${{ github.ref }}
20-
cancel-in-progress: true
2118
strategy:
2219
fail-fast: false
2320
matrix:
21+
os: ["ubuntu-22.04", "ubuntu-24.04"]
2422
python: [
2523
"3.7",
2624
"3.8",
2725
"3.9",
2826
"3.10",
29-
"3.11.0-rc.1",
27+
"3.11",
28+
"3.12",
29+
"3.13",
3030
]
31-
name: Python ${{ matrix.python }}
31+
exclude:
32+
- os: "ubuntu-22.04"
33+
python: "3.13"
34+
- os: "ubuntu-24.04"
35+
python: "3.7"
36+
runs-on: ${{ matrix.os }}
37+
concurrency:
38+
group: ${{ github.workflow }}-${{ matrix.python }}-${{ matrix.os }}-${{ github.ref }}
39+
cancel-in-progress: true
40+
name: Python ${{ matrix.python }} on ${{ matrix.os }}
3241
steps:
3342
- name: Repository checkout
34-
uses: actions/checkout@v2
43+
uses: actions/checkout@v4
3544

3645
- name: Configure Python ${{ matrix.python }}
37-
uses: actions/setup-python@v2
46+
uses: actions/setup-python@v5
3847
with:
3948
python-version: ${{ matrix.python }}
4049
architecture: x64
@@ -43,14 +52,11 @@ jobs:
4352
run: |
4453
sudo apt -y update
4554
sudo apt -y install gcc libsystemd-dev
46-
python -m pip install pytest sphinx
55+
python -m pip install --break-system-packages pytest sphinx build
4756
4857
- name: Build (Python ${{ matrix.python }})
4958
run: |
5059
set -x
51-
make -j
52-
make doc SPHINXOPTS="-W -v"
53-
54-
- name: Test (Python ${{ matrix.python }})
55-
run: |
56-
make check
60+
python -m build -Cbuild-dir=_build
61+
python -m pip install .
62+
cd _build && python -m sphinx -b html -W -v ../docs html

.github/workflows/codeql.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88
push:
99
branches:
1010
- main
11+
- feature/meson-build
1112
pull_request:
1213
branches:
1314
- main
@@ -18,7 +19,7 @@ permissions:
1819
jobs:
1920
analyze:
2021
name: Analyze
21-
runs-on: ubuntu-22.04
22+
runs-on: ubuntu-24.04
2223
concurrency:
2324
group: ${{ github.workflow }}-${{ matrix.language }}-${{ github.ref }}
2425
cancel-in-progress: true
@@ -33,10 +34,10 @@ jobs:
3334

3435
steps:
3536
- name: Checkout repository
36-
uses: actions/checkout@v3
37+
uses: actions/checkout@v4
3738

3839
- name: Initialize CodeQL
39-
uses: github/codeql-action/init@v2
40+
uses: github/codeql-action/init@v3
4041
with:
4142
languages: ${{ matrix.language }}
4243
queries: +security-extended,security-and-quality
@@ -47,7 +48,7 @@ jobs:
4748
sudo apt -y install gcc libsystemd-dev
4849
4950
- name: Autobuild
50-
uses: github/codeql-action/autobuild@v2
51+
uses: github/codeql-action/autobuild@v3
5152

5253
- name: Perform CodeQL Analysis
53-
uses: github/codeql-action/analyze@v2
54+
uses: github/codeql-action/analyze@v3

.github/workflows/install.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
# vi: ts=2 sw=2 et:
33
# SPDX-License-Identifier: LGPL-2.1-or-later
44
#
5-
name: Install test
5+
name: Install then test
66
on:
77
pull_request:
88
push:
99
branches:
1010
- main
11+
- feature/meson-build
1112

1213
permissions:
1314
contents: read
@@ -24,16 +25,16 @@ jobs:
2425
container: [
2526
"archlinux:latest",
2627
"debian:testing",
27-
"quay.io/centos/centos:stream8",
28+
"quay.io/centos/centos:stream10",
2829
"quay.io/fedora/fedora:rawhide",
29-
"ubuntu:focal",
30+
"ubuntu:noble",
3031
]
3132
container:
3233
image: ${{ matrix.container }}
3334
name: ${{ matrix.container }}
3435
steps:
3536
- name: Repository checkout
36-
uses: actions/checkout@v2
37+
uses: actions/checkout@v4
3738

3839
- name: Install dependencies
3940
shell: bash
@@ -51,8 +52,7 @@ jobs:
5152
5253
case "$DIST_ID" in
5354
arch)
54-
pacman --noconfirm -Sy "${DEPS_COMMON[@]}" systemd-libs
55-
python3 -m ensurepip
55+
pacman --noconfirm -Sy "${DEPS_COMMON[@]}" systemd-libs python-pip
5656
;;
5757
centos|fedora)
5858
dnf -y install "${DEPS_COMMON[@]}" systemd-devel python3-devel python3-pip
@@ -66,13 +66,13 @@ jobs:
6666
exit 1
6767
esac
6868
69-
python3 -m pip install pytest sphinx
69+
python3 -m pip install --break-system-packages pytest sphinx
7070
71-
- name: Build & install
71+
- name: Install & test
7272
shell: bash
7373
run: |
7474
set -x
75-
python3 -m pip install -I -v .
75+
python3 -m pip install -I -v --break-system-packages .
7676
# Avoid importing the systemd module from the git repository
7777
cd /
7878
python3 -c 'from systemd import journal; print(journal.__version__)'

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ __pycache__/
77
*.egg
88
*.egg-info
99
dist
10+
_build
1011
build
1112
eggs
1213
parts
@@ -30,3 +31,6 @@ pip-log.txt
3031

3132
#Mr Developer
3233
.mr.developer.cfg
34+
35+
# Zed
36+
.zed

Makefile

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,7 @@ INCLUDE_DIR := $(shell pkg-config --variable=includedir libsystemd)
55
INCLUDE_FLAGS := $(shell pkg-config --cflags libsystemd)
66
VERSION := $(shell $(PYTHON) setup.py --version)
77
TESTFLAGS = -v
8-
9-
define buildscript
10-
import sys, sysconfig, setuptools
11-
sversion = int(setuptools.__version__.split(".")[0])
12-
end = sys.implementation.cache_tag if sversion >= 61 else "{}.{}".format(*sys.version_info[:2])
13-
print("build/lib.{}-{}".format(sysconfig.get_platform(), end))
14-
endef
15-
16-
builddir := $(shell $(PYTHON) -c '$(buildscript)')
8+
BUILD_DIR = _build
179

1810
all: build
1911

@@ -32,38 +24,36 @@ update-constants: update-constants.py $(INCLUDE_DIR)/systemd/sd-messages.h
3224
mv docs/id128.rst{.tmp,}
3325

3426
build:
35-
$(PYTHON) setup.py build_ext $(INCLUDE_FLAGS)
36-
$(PYTHON) setup.py build
27+
$(PYTHON) -m build -Cbuild-dir=$(BUILD_DIR)
3728

3829
install:
39-
$(PYTHON) setup.py install --skip-build $(if $(DESTDIR),--root $(DESTDIR))
30+
$(PYTHON) -m pip install .
4031

4132
dist:
42-
$(PYTHON) setup.py sdist
33+
$(PYTHON) -m build --sdist
4334

4435
sign: dist/systemd-python-$(VERSION).tar.gz
4536
gpg --detach-sign -a dist/systemd-python-$(VERSION).tar.gz
4637

4738
clean:
48-
rm -rf build systemd/*.so systemd/*.py[co] *.py[co] systemd/__pycache__
39+
rm -rf _build systemd/*.so systemd/*.py[co] *.py[co] systemd/__pycache__
4940

5041
distclean: clean
5142
rm -rf dist MANIFEST
5243

5344
SPHINXOPTS += -D version=$(VERSION) -D release=$(VERSION)
54-
sphinx-%: build
55-
cd build && \
56-
PYTHONPATH=../$(builddir) $(PYTHON) -m sphinx -b $* $(SPHINXOPTS) ../docs $*
57-
@echo Output has been generated in build/$*
45+
sphinx-%: install
46+
cd $(BUILD_DIR) && $(PYTHON) -m sphinx -b $* $(SPHINXOPTS) ../docs $*
47+
@echo Output has been generated in $(BUILD_DIR)/$*
5848

5949
doc: sphinx-html
6050

6151
check: build
62-
(cd $(builddir) && $(PYTHON) -m pytest . ../../docs $(TESTFLAGS))
52+
(cd $(BUILD_DIR) && $(PYTHON) -m pytest ../systemd/test ../docs $(TESTFLAGS))
6353

6454
www_target = www.freedesktop.org:/srv/www.freedesktop.org/www/software/systemd/python-systemd
6555
doc-sync:
66-
rsync -rlv --delete --omit-dir-times build/html/ $(www_target)/
56+
rsync -rlv --delete --omit-dir-times $(BUILD_DIR)/html/ $(www_target)/
6757

6858
upload: dist/systemd-python-$(VERSION).tar.gz dist/systemd-python-$(VERSION).tar.gz.asc
6959
twine-3 upload $+
@@ -73,6 +63,6 @@ TAGS: $(shell git ls-files systemd/*.[ch])
7363

7464
shell:
7565
# we change the directory because python insists on adding $CWD to path
76-
(cd $(builddir) && $(PYTHON))
66+
(cd $(BUILD_DIR) && $(PYTHON))
7767

7868
.PHONY: build install dist sign upload clean distclean TAGS doc doc-sync shell

meson.build

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
project(
2+
'python-systemd',
3+
'c',
4+
version: '236',
5+
license: 'LGPL-2.1-or-later',
6+
default_options: ['warning_level=2', 'c_std=c99'],
7+
)
8+
9+
# Dependencies
10+
python = import('python').find_installation('python3', pure: false)
11+
python_dep = python.dependency()
12+
13+
# Try to find libsystemd
14+
foreach name : [
15+
'libsystemd',
16+
'libsystemd-journal',
17+
'libsystemd-daemon',
18+
'libsystemd-id128',
19+
'libsystemd-login',
20+
]
21+
libsystemd_dep = dependency(name, required: false)
22+
if libsystemd_dep.found()
23+
break
24+
endif
25+
endforeach
26+
27+
# Common compile arguments matching setup.py
28+
common_c_args = [
29+
'-std=c99',
30+
'-Werror=implicit-function-declaration',
31+
'-DPACKAGE_VERSION="' + meson.project_version() + '"',
32+
'-DLIBSYSTEMD_VERSION=' + libsystemd_dep.version(),
33+
]
34+
35+
# Build _journal extension module
36+
python.extension_module(
37+
'_journal',
38+
['systemd/_journal.c', 'systemd/pyutil.c'],
39+
dependencies: [libsystemd_dep],
40+
c_args: common_c_args,
41+
install: true,
42+
subdir: 'systemd',
43+
)
44+
45+
# Build _reader extension module
46+
python.extension_module(
47+
'_reader',
48+
['systemd/_reader.c', 'systemd/pyutil.c', 'systemd/strv.c'],
49+
dependencies: [libsystemd_dep],
50+
c_args: common_c_args,
51+
install: true,
52+
subdir: 'systemd',
53+
)
54+
55+
# Build _daemon extension module
56+
python.extension_module(
57+
'_daemon',
58+
['systemd/_daemon.c', 'systemd/pyutil.c', 'systemd/util.c'],
59+
dependencies: [libsystemd_dep],
60+
c_args: common_c_args,
61+
install: true,
62+
subdir: 'systemd',
63+
)
64+
65+
# Build id128 extension module
66+
python.extension_module(
67+
'id128',
68+
['systemd/id128.c', 'systemd/pyutil.c'],
69+
dependencies: [libsystemd_dep],
70+
c_args: common_c_args,
71+
install: true,
72+
subdir: 'systemd',
73+
)
74+
75+
# Build login extension module
76+
python.extension_module(
77+
'login',
78+
['systemd/login.c', 'systemd/pyutil.c', 'systemd/strv.c'],
79+
dependencies: [libsystemd_dep],
80+
c_args: common_c_args,
81+
install: true,
82+
subdir: 'systemd',
83+
)
84+
85+
# Install Python modules (matching py_modules in setup.py)
86+
python.install_sources(
87+
'systemd/__init__.py',
88+
'systemd/journal.py',
89+
'systemd/daemon.py',
90+
subdir: 'systemd',
91+
)
92+
93+
# Install test modules
94+
python.install_sources(
95+
'systemd/test/test_daemon.py',
96+
'systemd/test/test_journal.py',
97+
'systemd/test/test_login.py',
98+
'systemd/test/test_id128.py',
99+
subdir: 'systemd/test',
100+
)

0 commit comments

Comments
 (0)