Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[meson.build]
indent_style = space
indent_size = 8
40 changes: 22 additions & 18 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# vi: ts=2 sw=2 et:
# SPDX-License-Identifier: LGPL-2.1-or-later
#
name: Build test
name: Build
on:
pull_request:
push:
Expand All @@ -14,27 +14,31 @@ permissions:

jobs:
build:
runs-on: ubuntu-20.04
concurrency:
group: ${{ github.workflow }}-${{ matrix.python }}-${{ github.ref }}
cancel-in-progress: true
strategy:
fail-fast: false
matrix:
os: ["ubuntu-22.04", "ubuntu-24.04"]
python: [
"3.7",
"3.8",
"3.9",
"3.10",
"3.11.0-rc.1",
"3.11",
"3.12",
"3.13",
]
name: Python ${{ matrix.python }}
exclude:
- os: "ubuntu-22.04"
python: "3.13"
runs-on: ${{ matrix.os }}
concurrency:
group: ${{ github.workflow }}-${{ matrix.python }}-${{ matrix.os }}-${{ github.ref }}
cancel-in-progress: true
name: Python ${{ matrix.python }} on ${{ matrix.os }}
steps:
- name: Repository checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Configure Python ${{ matrix.python }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
architecture: x64
Expand All @@ -43,14 +47,14 @@ jobs:
run: |
sudo apt -y update
sudo apt -y install gcc libsystemd-dev
python -m pip install pytest sphinx
python -m pip install -U --break-system-packages pip build

# Note: The `pip install --group` is available on pip v25+
- name: Build (Python ${{ matrix.python }})
run: |
set -x
make -j
make doc SPHINXOPTS="-W -v"

- name: Test (Python ${{ matrix.python }})
run: |
make check
python -m build -Cbuild-dir=build
python -m pip install --group docs
python -m pip install .
cd build
python -m sphinx -b html -W -v ../docs html
11 changes: 6 additions & 5 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ permissions:
jobs:
analyze:
name: Analyze
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
concurrency:
group: ${{ github.workflow }}-${{ matrix.language }}-${{ github.ref }}
cancel-in-progress: true
Expand All @@ -33,10 +33,10 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
queries: +security-extended,security-and-quality
Expand All @@ -45,9 +45,10 @@ jobs:
run: |
sudo apt -y update
sudo apt -y install gcc libsystemd-dev
python -m pip install -U --break-system-packages pip build

- name: Autobuild
uses: github/codeql-action/autobuild@v2
uses: github/codeql-action/autobuild@v3

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
36 changes: 23 additions & 13 deletions .github/workflows/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# vi: ts=2 sw=2 et:
# SPDX-License-Identifier: LGPL-2.1-or-later
#
name: Install test
name: Install then test
on:
pull_request:
push:
Expand All @@ -24,16 +24,14 @@ jobs:
container: [
"archlinux:latest",
"debian:testing",
"quay.io/centos/centos:stream8",
"quay.io/centos/centos:stream10",
"quay.io/fedora/fedora:rawhide",
"ubuntu:focal",
"ubuntu:noble",
]
container:
image: ${{ matrix.container }}
name: ${{ matrix.container }}
steps:
- name: Repository checkout
uses: actions/checkout@v2

- name: Install dependencies
shell: bash
Expand All @@ -51,10 +49,14 @@ jobs:

case "$DIST_ID" in
arch)
pacman --noconfirm -Sy "${DEPS_COMMON[@]}" systemd-libs
python3 -m ensurepip
pacman --noconfirm -Sy -u "${DEPS_COMMON[@]}" systemd-libs python-pip
;;
centos)
dnf config-manager --set-enabled crb
dnf install -y epel-release
dnf -y install "${DEPS_COMMON[@]}" systemd-devel python3-devel python3-pip
;;
centos|fedora)
fedora)
dnf -y install "${DEPS_COMMON[@]}" systemd-devel python3-devel python3-pip
;;
ubuntu|debian)
Expand All @@ -66,14 +68,22 @@ jobs:
exit 1
esac

python3 -m pip install pytest sphinx
python3 -m pip install -U --break-system-packages build pytest

- name: Fix Git config to satisfy Meson
run: git config --global safe.directory "*"

# Checkout repo after installing Git, or the "checkout" GH Action will download our source as non-Git repo, making Meson fail
# to build Python source dist.
- name: Repository checkout
uses: actions/checkout@v4

- name: Build & install
- name: Install & test
shell: bash
run: |
set -x
python3 -m pip install -I -v .
# Avoid importing the systemd module from the git repository
cd /
git --version
python3 -m build
python3 -m pip install --break-system-packages .
python3 -c 'from systemd import journal; print(journal.__version__)'
pytest -v --pyargs systemd
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ sdist
develop-eggs
.installed.cfg
MANIFEST
.venv

# Installer logs
pip-log.txt
Expand All @@ -30,3 +31,6 @@ pip-log.txt

#Mr Developer
.mr.developer.cfg

# Zed
.zed
49 changes: 19 additions & 30 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,67 +3,57 @@ SED = sed
ETAGS = etags
INCLUDE_DIR := $(shell pkg-config --variable=includedir libsystemd)
INCLUDE_FLAGS := $(shell pkg-config --cflags libsystemd)
VERSION := $(shell $(PYTHON) setup.py --version)
VERSION := $(shell meson introspect --projectinfo build | jq -r .version)
TESTFLAGS = -v

define buildscript
import sys, sysconfig, setuptools
sversion = int(setuptools.__version__.split(".")[0])
end = sys.implementation.cache_tag if sversion >= 61 else "{}.{}".format(*sys.version_info[:2])
print("build/lib.{}-{}".format(sysconfig.get_platform(), end))
endef

builddir := $(shell $(PYTHON) -c '$(buildscript)')
BUILD_DIR = build

all: build

.PHONY: update-constants
update-constants: update-constants.py $(INCLUDE_DIR)/systemd/sd-messages.h
$(PYTHON) $+ systemd/id128-defines.h | \
$(PYTHON) $+ src/systemd/id128-defines.h | \
sort -u | \
tee systemd/id128-defines.h.tmp | \
tee src/systemd/id128-defines.h.tmp | \
$(SED) -n -r 's/,//g; s/#define (SD_MESSAGE_[A-Z0-9_]+)\s.*/add_id(m, "\1", \1) JOINER/p' | \
sort -u >systemd/id128-constants.h.tmp
mv systemd/id128-defines.h{.tmp,}
mv systemd/id128-constants.h{.tmp,}
sort -u > src/systemd/id128-constants.h.tmp
mv src/systemd/id128-defines.h{.tmp,}
mv src/systemd/id128-constants.h{.tmp,}
($(SED) 9q <docs/id128.rst && \
sed -n -r 's/#define (SD_MESSAGE_[A-Z0-9_]+) .*/ .. autoattribute:: systemd.id128.\1/p' \
systemd/id128-defines.h) >docs/id128.rst.tmp
src/systemd/id128-defines.h) >docs/id128.rst.tmp
mv docs/id128.rst{.tmp,}

build:
$(PYTHON) setup.py build_ext $(INCLUDE_FLAGS)
$(PYTHON) setup.py build
$(PYTHON) -m build -Cbuild-dir=$(BUILD_DIR)

install:
$(PYTHON) setup.py install --skip-build $(if $(DESTDIR),--root $(DESTDIR))
$(PYTHON) -m pip install .

dist:
$(PYTHON) setup.py sdist
$(PYTHON) -m build --sdist

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

clean:
rm -rf build systemd/*.so systemd/*.py[co] *.py[co] systemd/__pycache__
rm -rf $(BUILD_DIR) systemd/*.so systemd/*.py[co] *.py[co] systemd/__pycache__

distclean: clean
rm -rf dist MANIFEST

SPHINXOPTS += -D version=$(VERSION) -D release=$(VERSION)
sphinx-%: build
cd build && \
PYTHONPATH=../$(builddir) $(PYTHON) -m sphinx -b $* $(SPHINXOPTS) ../docs $*
@echo Output has been generated in build/$*
sphinx-%: install
mkdir $(BUILD_DIR) && cd $(BUILD_DIR) && $(PYTHON) -m sphinx -b $* $(SPHINXOPTS) ../docs $*
@echo Output has been generated in $(BUILD_DIR)/$*

doc: sphinx-html

check: build
(cd $(builddir) && $(PYTHON) -m pytest . ../../docs $(TESTFLAGS))
check: build install
($(PYTHON) -m pytest src/systemd/test docs $(TESTFLAGS))

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

upload: dist/systemd-python-$(VERSION).tar.gz dist/systemd-python-$(VERSION).tar.gz.asc
twine-3 upload $+
Expand All @@ -72,7 +62,6 @@ TAGS: $(shell git ls-files systemd/*.[ch])
$(ETAGS) $+

shell:
# we change the directory because python insists on adding $CWD to path
(cd $(builddir) && $(PYTHON))
$(PYTHON)

.PHONY: build install dist sign upload clean distclean TAGS doc doc-sync shell
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ Quick way to view output with all fields as it comes in:
Test Builds (for Development)
=============================

python setup.py build_ext -i
python -m build
python -m pip install .
python
>>> from systemd import journal
>>> journal.send("Test")
Expand Down
22 changes: 22 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
project(
'python-systemd',
'c',
version: '236',
license: 'LGPL-2.1-or-later',
default_options: ['warning_level=2', 'c_std=c99'],
meson_version: '>= 1.8.0',
)

# Dependencies
python = import('python').find_installation('python3', pure: false)
python_dep = python.dependency()

libsystemd_dep = dependency('libsystemd')

common_c_args = [
'-DPACKAGE_VERSION="@0@"'.format(meson.project_version()),
'-DLIBSYSTEMD_VERSION=@0@'.format(libsystemd_dep.version()),
]

subdir('src')

59 changes: 59 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
[project]
name = "systemd-python"
dynamic = ["version"]
description = "Python interface for libsystemd"
readme = "README.md"
license = { text = "LGPL-2.1-or-later" }
authors = [{ email = "[email protected]" }]
maintainers = [
{ name = "systemd developers", email = "[email protected]" },
]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)",
"Operating System :: POSIX :: Linux",
"Programming Language :: C",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: System :: Logging",
"Topic :: System :: Systems Administration",
]
keywords = ["systemd", "journal", "logging", "daemon"]
requires-python = ">=3.9"
dependencies = []

[project.urls]
Homepage = "https://github.com/systemd/python-systemd"
Repository = "https://github.com/systemd/python-systemd.git"
Issues = "https://github.com/systemd/python-systemd/issues"
Documentation = "https://www.freedesktop.org/software/systemd/python-systemd/"

[dependency-groups]
test = ["pytest", "pytest-cov"]
docs = ["sphinx"]
build = [
"meson>=1.8.2",
"twine>=4.0.2",
]

[build-system]
requires = ["meson-python"]
build-backend = "mesonpy"

[tool.coverage.run]
source = ["systemd"]
omit = ["systemd/test/*"]

[tool.coverage.report]
exclude_lines = [
"pragma: no cover",
"def __repr__",
"raise AssertionError",
"raise NotImplementedError",
]
Loading