diff options
author | Oto Šťáva <oto.stava@nic.cz> | 2024-03-01 10:13:08 +0100 |
---|---|---|
committer | Oto Šťáva <oto.stava@nic.cz> | 2024-03-13 09:23:20 +0100 |
commit | 3a96937542b004e6d34a8eaa365fec4b365dcbd8 (patch) | |
tree | 148642085ec9af377a56df35ac399530f46a05a7 | |
parent | Merge !1508: lib/dnssec: dnskey nits (diff) | |
download | knot-resolver-3a96937542b004e6d34a8eaa365fec4b365dcbd8.tar.xz knot-resolver-3a96937542b004e6d34a8eaa365fec4b365dcbd8.zip |
python: expose prefix configuration as a module
-rw-r--r-- | distro/pkg/arch/PKGBUILD | 8 | ||||
-rwxr-xr-x | distro/pkg/deb/rules | 16 | ||||
-rw-r--r-- | distro/pkg/rpm/knot-resolver.spec | 15 | ||||
-rw-r--r-- | manager/knot_resolver_manager/constants.py | 14 | ||||
-rw-r--r-- | manager/scripts/_env.sh | 2 | ||||
-rw-r--r-- | meson.build | 1 | ||||
-rw-r--r-- | python/knot_resolver.py.in | 10 | ||||
-rw-r--r-- | python/meson.build | 23 | ||||
-rw-r--r-- | python/setup.py.in | 12 |
9 files changed, 93 insertions, 8 deletions
diff --git a/distro/pkg/arch/PKGBUILD b/distro/pkg/arch/PKGBUILD index 9d31b59f..5ecc0df5 100644 --- a/distro/pkg/arch/PKGBUILD +++ b/distro/pkg/arch/PKGBUILD @@ -60,6 +60,9 @@ build() { -D malloc=jemalloc \ -D unit_tests=enabled ninja -C build + pushd build/python + python -Pm build --wheel --no-isolation + popd pushd manager python -Pm build --wheel --no-isolation popd @@ -81,6 +84,11 @@ package() { # remove modules with missing dependencies rm "${pkgdir}/usr/lib/knot-resolver/kres_modules/etcd.lua" + # install knot-resolver metadata Python module + pushd build/python + python -Pm installer --destdir="$pkgdir" dist/*.whl + popd + # install knot-resolver-manager pushd manager python -Pm installer --destdir="$pkgdir" dist/*.whl diff --git a/distro/pkg/deb/rules b/distro/pkg/deb/rules index b707c4a3..cc925bf0 100755 --- a/distro/pkg/deb/rules +++ b/distro/pkg/deb/rules @@ -10,8 +10,10 @@ export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic -fno-omit-frame-pointer # package maintainers to append LDFLAGS export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed -export PYBUILD_NAME=knot_resolver_manager -export PYBUILD_DESTDIR=debian/knot-resolver-manager/ +export PYKRES_NAME=knot_resolver +export PYKRES_DEST=debian/knot-resolver-core/ +export KRES_MANAGER_NAME=knot_resolver_manager +export KRES_MANAGER_DEST=debian/knot-resolver-manager/ # see EXAMPLES in dpkg-buildflags(1) and read /usr/share/dpkg/* DPKG_EXPORT_BUILDFLAGS = 1 @@ -37,11 +39,17 @@ override_dh_auto_build: -Dc_args="$${CFLAGS}" \ -Dc_link_args="$${LDFLAGS}" ninja -v -C build_deb - dh_auto_build --buildsystem=pybuild --sourcedirectory manager + PYBUILD_NAME="$${PYKRES_NAME}" PYBUILD_DESTDIR="$${PYKRES_DEST}" \ + dh_auto_build --buildsystem=pybuild --sourcedirectory build_deb/python + PYBUILD_NAME="$${KRES_MANAGER_NAME}" PYBUILD_DESTDIR="$${KRES_MANAGER_DEST}" \ + dh_auto_build --buildsystem=pybuild --sourcedirectory manager override_dh_auto_install: DESTDIR="${PWD}/debian/tmp" ninja -v -C build_deb install - dh_auto_install --buildsystem=pybuild --sourcedirectory manager + PYBUILD_NAME="$${PYKRES_NAME}" PYBUILD_DESTDIR="$${PYKRES_DEST}" \ + dh_auto_install --buildsystem=pybuild --sourcedirectory build_deb/python + PYBUILD_NAME="$${KRES_MANAGER_NAME}" PYBUILD_DESTDIR="$${KRES_MANAGER_DEST}" \ + dh_auto_install --buildsystem=pybuild --sourcedirectory manager install -m 644 -D manager/etc/knot-resolver/config.yaml debian/tmp/etc/knot-resolver/config.yaml install -m 644 -D manager/shell-completion/client.bash debian/tmp/usr/share/bash-completion/completions/kresctl install -m 644 -D manager/shell-completion/client.fish debian/tmp/usr/share/fish/completions/kresctl.fish diff --git a/distro/pkg/rpm/knot-resolver.spec b/distro/pkg/rpm/knot-resolver.spec index 548ae65b..2ba5383a 100644 --- a/distro/pkg/rpm/knot-resolver.spec +++ b/distro/pkg/rpm/knot-resolver.spec @@ -195,6 +195,10 @@ CFLAGS="%{optflags}" LDFLAGS="%{?__global_ldflags}" meson build_rpm \ %{NINJA} -v -C build_rpm +pushd build_rpm/python +%py3_build +popd + pushd manager %py3_build popd @@ -225,6 +229,10 @@ install -m 755 -d %{buildroot}/%{_pkgdocdir} mv %{buildroot}/%{_datadir}/doc/%{name}/* %{buildroot}/%{_pkgdocdir}/ %endif +pushd build_rpm/python +%py3_install +popd + # install knot-resolver-manager pushd manager %py3_install @@ -307,6 +315,13 @@ getent passwd knot-resolver >/dev/null || useradd -r -g knot-resolver -d %{_sysc %{_libdir}/knot-resolver/kres_modules/view.lua %{_libdir}/knot-resolver/kres_modules/watchdog.lua %{_libdir}/knot-resolver/kres_modules/workarounds.lua +%{python3_sitelib}/knot_resolver.py +%{python3_sitelib}/knot_resolver-* +%if 0%{?suse_version} +%pycache_only %{python3_sitelib}/__pycache__/knot_resolver.* +%else +%{python3_sitelib}/__pycache__/knot_resolver.* +%endif %{_mandir}/man8/kresd.8.gz %{_mandir}/man8/kresctl.8.gz diff --git a/manager/knot_resolver_manager/constants.py b/manager/knot_resolver_manager/constants.py index b80774a9..2d9ebd23 100644 --- a/manager/knot_resolver_manager/constants.py +++ b/manager/knot_resolver_manager/constants.py @@ -1,8 +1,14 @@ +import importlib.util import logging from pathlib import Path from typing import TYPE_CHECKING, Optional -from knot_resolver_manager.utils import which +# Install config is semi-optional - only needed to actually run Manager, but not +# for its unit tests. +if importlib.util.find_spec("knot_resolver"): + import knot_resolver # type: ignore[import-not-found] +else: + knot_resolver = None if TYPE_CHECKING: from knot_resolver_manager.config_store import ConfigStore @@ -20,11 +26,13 @@ MAX_WORKERS = 256 def kresd_executable() -> Path: - return which.which("kresd") + assert knot_resolver is not None + return knot_resolver.sbin_dir / "kresd" def kres_gc_executable() -> Path: - return which.which("kres-cache-gc") + assert knot_resolver is not None + return knot_resolver.sbin_dir / "kres-cache-gc" def kresd_cache_dir(config: "KresConfig") -> Path: diff --git a/manager/scripts/_env.sh b/manager/scripts/_env.sh index b1941edf..ddbbcf55 100644 --- a/manager/scripts/_env.sh +++ b/manager/scripts/_env.sh @@ -47,6 +47,6 @@ function build_kresd { meson manager/.build_kresd --prefix=$(realpath manager/.install_kresd) --default-library=static --buildtype=debug ninja -C manager/.build_kresd ninja install -C manager/.build_kresd - export PATH="$(realpath manager/.install_kresd)/sbin:$PATH" + export PYTHONPATH="$(realpath manager/.build_kresd/python):${PYTHONPATH:-}" popd } diff --git a/meson.build b/meson.build index 015d59f9..9ee683d7 100644 --- a/meson.build +++ b/meson.build @@ -231,6 +231,7 @@ subdir('lib') subdir('daemon') subdir('modules') subdir('manager') +subdir('python') subdir('utils') if get_option('bench') == 'enabled' subdir('bench') diff --git a/python/knot_resolver.py.in b/python/knot_resolver.py.in new file mode 100644 index 00000000..262f7a84 --- /dev/null +++ b/python/knot_resolver.py.in @@ -0,0 +1,10 @@ +from pathlib import Path + +__version__ = "@kres_version@" + +sbin_dir = Path("@sbin_dir@") +bin_dir = Path("@bin_dir@") +etc_dir = Path("@etc_dir@") +run_dir = Path("@run_dir@") +lib_dir = Path("@lib_dir@") +modules_dir = Path("@modules_dir@") diff --git a/python/meson.build b/python/meson.build new file mode 100644 index 00000000..e209df54 --- /dev/null +++ b/python/meson.build @@ -0,0 +1,23 @@ +# python +# SPDX-License-Identifier: GPL-3.0-or-later + +python_config = configuration_data() +python_config.set('kres_version', meson.project_version()) +python_config.set('sbin_dir', sbin_dir) +python_config.set('bin_dir', bin_dir) +python_config.set('etc_dir', etc_dir) +python_config.set('run_dir', run_dir) +python_config.set('lib_dir', lib_dir) +python_config.set('modules_dir', modules_dir) + +configure_file( + input: 'knot_resolver.py.in', + output: 'knot_resolver.py', + configuration: python_config, +) + +configure_file( + input: 'setup.py.in', + output: 'setup.py', + configuration: python_config, +) diff --git a/python/setup.py.in b/python/setup.py.in new file mode 100644 index 00000000..07b71454 --- /dev/null +++ b/python/setup.py.in @@ -0,0 +1,12 @@ +from setuptools import setup + +# TODO: Migrate this to a pyproject.toml once Debian 11 support is dropped. +setup( + name="knot_resolver", + version="@kres_version@", + description="Knot Resolver helper data for Python", + author="Oto Šťáva", + author_email="oto.stava@nic.cz", + python_requires=">=3.8,<4.0", + py_modules=["knot_resolver"], +) |