From e6877e54a4d736d6867e681ae275c86e413b5903 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 15 Oct 2025 16:23:19 +0200 Subject: [PATCH 1/3] meson: drop '-impl' from phony target output I think this was needed as some point in meson, but it isn't anymore and we dropped those in systemd a while ago. --- src/systemd/meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/systemd/meson.build b/src/systemd/meson.build index 8d01cd7..8bda7b4 100644 --- a/src/systemd/meson.build +++ b/src/systemd/meson.build @@ -65,7 +65,7 @@ python.install_sources( include_dir = libsystemd_dep.get_variable(pkgconfig: 'includedir') update_constants = custom_target( - output: 'update-constants-impl', + output: 'update-constants', command: [ update_constants_py, meson.current_source_dir() / 'id128-constants.h', From 17016e1a76dfe0e210a4939160470069738e78b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 15 Oct 2025 10:42:21 +0200 Subject: [PATCH 2/3] meson: copy .py files to build directory This seems to do the trick: $ ninja -C build $ PYTHONPATH=build/src/ python -c 'from systemd import id128; print(id128)' $ PYTHONPATH=build/src/ pytest src/systemd/test ... ============================ test session starts ============================= platform linux -- Python 3.13.4, pytest-8.3.4, pluggy-1.5.0 rootdir: /home/zbyszek/src/python-systemd configfile: pyproject.toml plugins: ... collected 61 items build/src/systemd/test/test_daemon.py ........................ [ 39%] build/src/systemd/test/test_id128.py .... [ 45%] build/src/systemd/test/test_journal.py ............................ [ 91%] build/src/systemd/test/test_login.py ..... [100%] ============================= 61 passed in 0.21s ============================= --- meson.build | 2 ++ src/systemd/meson.build | 11 ++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/meson.build b/meson.build index 4ba4934..af123ac 100644 --- a/meson.build +++ b/meson.build @@ -13,6 +13,8 @@ project( python = import('python').find_installation('python3', pure: false) python_dep = python.dependency() +fs = import('fs') + libsystemd_dep = dependency('libsystemd') add_project_arguments( diff --git a/src/systemd/meson.build b/src/systemd/meson.build index 8bda7b4..b880b01 100644 --- a/src/systemd/meson.build +++ b/src/systemd/meson.build @@ -46,14 +46,18 @@ python.extension_module( ) # Install Python modules -python.install_sources( +py_files = files( '__init__.py', 'journal.py', 'daemon.py', - subdir: 'systemd', ) -# Install test modules +python.install_sources(py_files, subdir: 'systemd') +foreach file: py_files + fs.copyfile(file) +endforeach + +# Test code python.install_sources( 'test/test_daemon.py', 'test/test_journal.py', @@ -62,6 +66,7 @@ python.install_sources( subdir: 'systemd/test', ) +# The 'update-constants' target include_dir = libsystemd_dep.get_variable(pkgconfig: 'includedir') update_constants = custom_target( From f65499816c451a67dc075dd68171345e194057ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 15 Oct 2025 16:33:18 +0200 Subject: [PATCH 3/3] meson: add test to run pytest The python binary that was initially found is used to launch pytest. It turns out to be surprisingly hard to run 'pytest' in test() with the python binary detected using meson's python module. test() does not allow the "program" argument to be a str, which is what python module's .full_path() returns. So let's "find" the program again. This results in one line of noise in meson output, but I don't see a nicer way. 'ninja -C build test' works. 'meson test -C build' is better, because it can be called with '-v' to print details of the test. --- meson.build | 11 +++++++++++ src/systemd/meson.build | 1 + 2 files changed, 12 insertions(+) diff --git a/meson.build b/meson.build index af123ac..2e4c8cb 100644 --- a/meson.build +++ b/meson.build @@ -28,4 +28,15 @@ update_constants_py = files('update-constants.py') subdir('src/systemd') +test( + 'unit', + find_program(python.full_path()), + args: [ + '-m', 'pytest', + '-v', + python_test_dir, + ], + env: { 'PYTHONPATH': meson.current_build_dir() / 'src' }, +) + alias_target('update-constants', update_constants) diff --git a/src/systemd/meson.build b/src/systemd/meson.build index b880b01..842be36 100644 --- a/src/systemd/meson.build +++ b/src/systemd/meson.build @@ -58,6 +58,7 @@ foreach file: py_files endforeach # Test code +python_test_dir = meson.current_source_dir() / 'test' python.install_sources( 'test/test_daemon.py', 'test/test_journal.py',