Skip to content

Modern Python packaging #147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
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]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer this file to be added first, so that the meson file is not reformatted in the middle of the series.

indent_style = space
indent_size = 8
43 changes: 26 additions & 17 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,64 @@
# vi: ts=2 sw=2 et:
# SPDX-License-Identifier: LGPL-2.1-or-later
#
name: Build test
name: Build
on:
pull_request:
push:
branches:
- main
- feature/meson-build
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

??

Copy link
Author

@hongquan hongquan Jun 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just to make GH Action run on my fork repo when I push the code.
The line will be deleted when the PR is approved.


permissions:
contents: read

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"
- os: "ubuntu-24.04"
python: "3.7"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3.7 is very old at this point. I guess we could drop that. But OTOH, the code will work fine with those old versions, so it should be fine to keep testing and supporting those old versions until there's some particular reason to raise the minimum.

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

- name: Install uv
uses: astral-sh/setup-uv@v5

- name: Install dependencies
run: |
sudo apt -y update
sudo apt -y install gcc libsystemd-dev
python -m pip install pytest sphinx
sudo apt -y install gcc libsystemd-dev universal-ctags

- name: Build (Python ${{ matrix.python }})
run: |
set -x
make -j
make doc SPHINXOPTS="-W -v"

- name: Test (Python ${{ matrix.python }})
run: |
make check
uv build
uv sync --no-editable
cd _build
uv run --no-editable --group docs -m sphinx -b html -W -v ../docs html
16 changes: 10 additions & 6 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
push:
branches:
- main
- feature/meson-build
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

??

pull_request:
branches:
- main
Expand All @@ -18,7 +19,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,21 +34,24 @@ 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

- name: Install dependencies
run: |
sudo apt -y update
sudo apt -y install gcc libsystemd-dev
sudo apt -y install gcc libsystemd-dev universal-ctags

- name: Install uv
uses: astral-sh/setup-uv@v5

- 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
35 changes: 24 additions & 11 deletions .github/workflows/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
# 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:
branches:
- main
- feature/meson-build
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

??


permissions:
contents: read
Expand All @@ -24,16 +25,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 +50,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,13 +69,23 @@ jobs:
exit 1
esac

python3 -m pip install pytest sphinx
python3 -m pip install --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 .
git --version
python3 -m build
python3 -m pip install --break-system-packages .
# Avoid importing the systemd module from the git repository
cd /
python3 -c 'from systemd import journal; print(journal.__version__)'
Expand Down
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
__pycache__/
*.py[co]
/journald/*.so
/TAGS
TAGS

# Packages
*.egg
*.egg-info
dist
_build
build
Comment on lines +10 to 11
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see both build and _build here. We normally use build for the build directory. I'd prefer not to introduce _build.

eggs
parts
Expand All @@ -16,6 +17,7 @@ sdist
develop-eggs
.installed.cfg
MANIFEST
.venv

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

#Mr Developer
.mr.developer.cfg

# Zed
.zed
8 changes: 0 additions & 8 deletions MANIFEST.in

This file was deleted.

78 changes: 0 additions & 78 deletions Makefile

This file was deleted.

19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ Show kernel ring buffer (`journalctl -k`):
print(entry['MESSAGE'])

Read entries in reverse (`journalctl _EXE=/usr/bin/vim -r`):

from systemd import journal
class ReverseReader(journal.Reader):
def __next__(self):
Expand Down Expand Up @@ -199,8 +199,23 @@ Quick way to view output with all fields as it comes in:
Test Builds (for Development)
=============================

python setup.py build_ext -i
Create a virtual environment:

python3 -m venv .venv
source .venv/bin/activate
python -m pip install build
python -m pip install .
python
>>> import systemd.journal
>>> systemd.journal.send("Test")

You can also build with [`uv`](https://docs.astral.sh/uv/).

uv build
uv sync --no-editable
# `--no-editable` is required, because `uv` seems not to work well with meson-python and cause
# "python not found" with editable mode.
uv run --no-editable python
>>> from systemd import journal
>>> journal.send("Test")

Expand Down
Loading