Skip to content

Commit 1605b3c

Browse files
committed
Adopt pyproject.toml and Meson to build Python extension
1 parent 9031424 commit 1605b3c

34 files changed

+232
-168
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[meson.build]
2+
indent_style = space
3+
indent_size = 8

.github/workflows/build.yml

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
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:
@@ -14,27 +14,35 @@ permissions:
1414

1515
jobs:
1616
build:
17-
runs-on: ubuntu-20.04
18-
concurrency:
19-
group: ${{ github.workflow }}-${{ matrix.python }}-${{ github.ref }}
20-
cancel-in-progress: true
2117
strategy:
2218
fail-fast: false
2319
matrix:
20+
os: ["ubuntu-22.04", "ubuntu-24.04"]
2421
python: [
2522
"3.7",
2623
"3.8",
2724
"3.9",
2825
"3.10",
29-
"3.11.0-rc.1",
26+
"3.11",
27+
"3.12",
28+
"3.13",
3029
]
31-
name: Python ${{ matrix.python }}
30+
exclude:
31+
- os: "ubuntu-22.04"
32+
python: "3.13"
33+
- os: "ubuntu-24.04"
34+
python: "3.7"
35+
runs-on: ${{ matrix.os }}
36+
concurrency:
37+
group: ${{ github.workflow }}-${{ matrix.python }}-${{ matrix.os }}-${{ github.ref }}
38+
cancel-in-progress: true
39+
name: Python ${{ matrix.python }} on ${{ matrix.os }}
3240
steps:
3341
- name: Repository checkout
34-
uses: actions/checkout@v2
42+
uses: actions/checkout@v4
3543

3644
- name: Configure Python ${{ matrix.python }}
37-
uses: actions/setup-python@v2
45+
uses: actions/setup-python@v5
3846
with:
3947
python-version: ${{ matrix.python }}
4048
architecture: x64
@@ -43,14 +51,21 @@ jobs:
4351
run: |
4452
sudo apt -y update
4553
sudo apt -y install gcc libsystemd-dev
46-
python -m pip install pytest sphinx
54+
python -m pip install -U --break-system-packages pip build
4755
56+
- name: Install Sphinx (old pip)
57+
if: ${{ matrix.python == '3.7' || matrix.python == '3.8' }}
58+
run: python -m pip install sphinx
59+
60+
- name: Install Sphinx (new pip)
61+
if: ${{ matrix.python != '3.7' && matrix.python != '3.8' }}
62+
run: python -m pip install --group docs
63+
64+
# Note: The `pip install --group` is available on pip v25+
4865
- name: Build (Python ${{ matrix.python }})
4966
run: |
5067
set -x
51-
make -j
52-
make doc SPHINXOPTS="-W -v"
53-
54-
- name: Test (Python ${{ matrix.python }})
55-
run: |
56-
make check
68+
python -m build -Cbuild-dir=build
69+
python -m pip install .
70+
cd build
71+
python -m sphinx -b html -W -v ../docs html

.github/workflows/codeql.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ permissions:
1818
jobs:
1919
analyze:
2020
name: Analyze
21-
runs-on: ubuntu-22.04
21+
runs-on: ubuntu-24.04
2222
concurrency:
2323
group: ${{ github.workflow }}-${{ matrix.language }}-${{ github.ref }}
2424
cancel-in-progress: true
@@ -33,10 +33,10 @@ jobs:
3333

3434
steps:
3535
- name: Checkout repository
36-
uses: actions/checkout@v3
36+
uses: actions/checkout@v4
3737

3838
- name: Initialize CodeQL
39-
uses: github/codeql-action/init@v2
39+
uses: github/codeql-action/init@v3
4040
with:
4141
languages: ${{ matrix.language }}
4242
queries: +security-extended,security-and-quality
@@ -47,7 +47,7 @@ jobs:
4747
sudo apt -y install gcc libsystemd-dev
4848
4949
- name: Autobuild
50-
uses: github/codeql-action/autobuild@v2
50+
uses: github/codeql-action/autobuild@v3
5151

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

.github/workflows/install.yml

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
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:
@@ -24,16 +24,14 @@ jobs:
2424
container: [
2525
"archlinux:latest",
2626
"debian:testing",
27-
"quay.io/centos/centos:stream8",
27+
"quay.io/centos/centos:stream10",
2828
"quay.io/fedora/fedora:rawhide",
29-
"ubuntu:focal",
29+
"ubuntu:noble",
3030
]
3131
container:
3232
image: ${{ matrix.container }}
3333
name: ${{ matrix.container }}
3434
steps:
35-
- name: Repository checkout
36-
uses: actions/checkout@v2
3735

3836
- name: Install dependencies
3937
shell: bash
@@ -51,10 +49,14 @@ jobs:
5149
5250
case "$DIST_ID" in
5351
arch)
54-
pacman --noconfirm -Sy "${DEPS_COMMON[@]}" systemd-libs
55-
python3 -m ensurepip
52+
pacman --noconfirm -Sy -u "${DEPS_COMMON[@]}" systemd-libs python-pip
53+
;;
54+
centos)
55+
dnf config-manager --set-enabled crb
56+
dnf install -y epel-release
57+
dnf -y install "${DEPS_COMMON[@]}" systemd-devel python3-devel python3-pip
5658
;;
57-
centos|fedora)
59+
fedora)
5860
dnf -y install "${DEPS_COMMON[@]}" systemd-devel python3-devel python3-pip
5961
;;
6062
ubuntu|debian)
@@ -66,14 +68,22 @@ jobs:
6668
exit 1
6769
esac
6870
69-
python3 -m pip install pytest sphinx
71+
python3 -m pip install -U --break-system-packages build pytest
72+
73+
- name: Fix Git config to satisfy Meson
74+
run: git config --global safe.directory "*"
75+
76+
# Checkout repo after installing Git, or the "checkout" GH Action will download our source as non-Git repo, making Meson fail
77+
# to build Python source dist.
78+
- name: Repository checkout
79+
uses: actions/checkout@v4
7080

71-
- name: Build & install
81+
- name: Install & test
7282
shell: bash
7383
run: |
7484
set -x
75-
python3 -m pip install -I -v .
76-
# Avoid importing the systemd module from the git repository
77-
cd /
85+
git --version
86+
python3 -m build
87+
python3 -m pip install --break-system-packages .
7888
python3 -c 'from systemd import journal; print(journal.__version__)'
7989
pytest -v --pyargs systemd

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ sdist
1616
develop-eggs
1717
.installed.cfg
1818
MANIFEST
19+
.venv
1920

2021
# Installer logs
2122
pip-log.txt
@@ -30,3 +31,6 @@ pip-log.txt
3031

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

Makefile

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,67 +3,57 @@ SED = sed
33
ETAGS = etags
44
INCLUDE_DIR := $(shell pkg-config --variable=includedir libsystemd)
55
INCLUDE_FLAGS := $(shell pkg-config --cflags libsystemd)
6-
VERSION := $(shell $(PYTHON) setup.py --version)
6+
VERSION := $(shell meson introspect --projectinfo build | jq -r .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

2012
.PHONY: update-constants
2113
update-constants: update-constants.py $(INCLUDE_DIR)/systemd/sd-messages.h
22-
$(PYTHON) $+ systemd/id128-defines.h | \
14+
$(PYTHON) $+ src/systemd/id128-defines.h | \
2315
sort -u | \
24-
tee systemd/id128-defines.h.tmp | \
16+
tee src/systemd/id128-defines.h.tmp | \
2517
$(SED) -n -r 's/,//g; s/#define (SD_MESSAGE_[A-Z0-9_]+)\s.*/add_id(m, "\1", \1) JOINER/p' | \
26-
sort -u >systemd/id128-constants.h.tmp
27-
mv systemd/id128-defines.h{.tmp,}
28-
mv systemd/id128-constants.h{.tmp,}
18+
sort -u > src/systemd/id128-constants.h.tmp
19+
mv src/systemd/id128-defines.h{.tmp,}
20+
mv src/systemd/id128-constants.h{.tmp,}
2921
($(SED) 9q <docs/id128.rst && \
3022
sed -n -r 's/#define (SD_MESSAGE_[A-Z0-9_]+) .*/ .. autoattribute:: systemd.id128.\1/p' \
31-
systemd/id128-defines.h) >docs/id128.rst.tmp
23+
src/systemd/id128-defines.h) >docs/id128.rst.tmp
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_DIR) 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+
mkdir $(BUILD_DIR) && cd $(BUILD_DIR) && $(PYTHON) -m sphinx -b $* $(SPHINXOPTS) ../docs $*
47+
@echo Output has been generated in $(BUILD_DIR)/$*
5848

5949
doc: sphinx-html
6050

61-
check: build
62-
(cd $(builddir) && $(PYTHON) -m pytest . ../../docs $(TESTFLAGS))
51+
check: build install
52+
($(PYTHON) -m pytest src/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 $+
@@ -72,7 +62,6 @@ TAGS: $(shell git ls-files systemd/*.[ch])
7262
$(ETAGS) $+
7363

7464
shell:
75-
# we change the directory because python insists on adding $CWD to path
76-
(cd $(builddir) && $(PYTHON))
65+
$(PYTHON)
7766

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

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ Quick way to view output with all fields as it comes in:
199199
Test Builds (for Development)
200200
=============================
201201

202-
python setup.py build_ext -i
202+
python -m build
203+
python -m pip install .
203204
python
204205
>>> from systemd import journal
205206
>>> journal.send("Test")

meson.build

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
meson_version: '>= 1.8.0',
8+
)
9+
10+
# Dependencies
11+
python = import('python').find_installation('python3', pure: false)
12+
python_dep = python.dependency()
13+
14+
libsystemd_dep = dependency('libsystemd')
15+
16+
common_c_args = [
17+
'-DPACKAGE_VERSION="@0@"'.format(meson.project_version()),
18+
'-DLIBSYSTEMD_VERSION=@0@'.format(libsystemd_dep.version()),
19+
]
20+
21+
subdir('src')
22+

pyproject.toml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
[project]
2+
name = "systemd-python"
3+
dynamic = ["version"]
4+
description = "Python interface for libsystemd"
5+
readme = "README.md"
6+
license = { text = "LGPL-2.1-or-later" }
7+
authors = [{ email = "david@davidstrauss.net" }]
8+
maintainers = [
9+
{ name = "systemd developers", email = "systemd-devel@lists.freedesktop.org" },
10+
]
11+
classifiers = [
12+
"Development Status :: 5 - Production/Stable",
13+
"Intended Audience :: Developers",
14+
"License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)",
15+
"Operating System :: POSIX :: Linux",
16+
"Programming Language :: C",
17+
"Programming Language :: Python :: 3",
18+
"Programming Language :: Python :: 3.7",
19+
"Programming Language :: Python :: 3.8",
20+
"Programming Language :: Python :: 3.9",
21+
"Programming Language :: Python :: 3.10",
22+
"Programming Language :: Python :: 3.11",
23+
"Programming Language :: Python :: 3.12",
24+
"Programming Language :: Python :: 3.13",
25+
"Topic :: Software Development :: Libraries :: Python Modules",
26+
"Topic :: System :: Logging",
27+
"Topic :: System :: Systems Administration",
28+
]
29+
keywords = ["systemd", "journal", "logging", "daemon"]
30+
requires-python = ">=3.7"
31+
dependencies = []
32+
33+
[project.urls]
34+
Homepage = "https://github.com/systemd/python-systemd"
35+
Repository = "https://github.com/systemd/python-systemd.git"
36+
Issues = "https://github.com/systemd/python-systemd/issues"
37+
Documentation = "https://www.freedesktop.org/software/systemd/python-systemd/"
38+
39+
[dependency-groups]
40+
test = ["pytest", "pytest-cov"]
41+
docs = ["sphinx"]
42+
build = [
43+
"meson>=1.8.2",
44+
"twine>=4.0.2",
45+
]
46+
47+
[build-system]
48+
requires = ["meson-python", "ninja", "meson"]
49+
build-backend = "mesonpy"
50+
51+
[tool.coverage.run]
52+
source = ["systemd"]
53+
omit = ["systemd/test/*"]
54+
55+
[tool.coverage.report]
56+
exclude_lines = [
57+
"pragma: no cover",
58+
"def __repr__",
59+
"raise AssertionError",
60+
"raise NotImplementedError",
61+
]

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy