From: Aleš Mrázek Date: Tue, 10 Sep 2024 09:07:09 +0000 (+0200) Subject: python/knot_resolver: use constants.py configured by Meson X-Git-Tag: v6.0.9~9^2~19 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=272f9006a1a44d4dd3cb50b235e5a5e47d5df050;p=thirdparty%2Fknot-resolver.git python/knot_resolver: use constants.py configured by Meson --- diff --git a/python/constants.py.in b/python/constants.py.in new file mode 100644 index 000000000..4fa71cbbc --- /dev/null +++ b/python/constants.py.in @@ -0,0 +1,22 @@ +from pathlib import Path + +VERSION = "@version@" +USER = "@user@" +GROUP = "@group@" + +# dirs paths +RUN_DIR = Path("@run_dir@") +ETC_DIR = Path("@etc_dir@") +SBIN_DIR = Path("@sbin_dir@") + +# files paths +CONFIG_FILE = ETC_DIR / "config.yaml" +API_SOCK_FILE = RUN_DIR / "kres-api.sock" + +# environmental variables +CONFIG_FILE_ENV_VAR = "KRES_CONFIG_FILE" +API_SOCK_FILE_ENV_VAR = "KRES_API_SOCK_FILE" + +# executables paths +KRESD_EXECUTABLE = SBIN_DIR / "kresd" +KRES_CACHE_GC_EXECUTABLE = SBIN_DIR / "kres-cache-gc" diff --git a/python/knot_resolver/constants.py b/python/knot_resolver/constants.py index f63478d4a..fb45c26b6 100644 --- a/python/knot_resolver/constants.py +++ b/python/knot_resolver/constants.py @@ -1,40 +1,22 @@ -import logging -from importlib.metadata import version -from importlib.util import find_spec from pathlib import Path -# Installed Knot Resolver build options from Meson is semi-optional. -# They are needed to run the resolver, but not for its unit tests. -if find_spec("knot_resolver_build_options"): - import knot_resolver_build_options as build_conf # type: ignore[import-not-found] -else: - build_conf = None +VERSION = "6.0.8" +USER = "knot-resolver" +GROUP = "knot-resolver" -VERSION = version("knot_resolver") if find_spec("knot_resolver") else "6" -WORKERS_MAX_DEFAULT = 256 -LOGGING_LEVEL_STARTUP = logging.DEBUG -PID_FILE_NAME = "knot-resolver.pid" +# dirs paths +RUN_DIR = Path("/run/knot-resolver") +ETC_DIR = Path("/etc/knot-resolver") +SBIN_DIR = Path("/usr/bin") -FIX_COUNTER_ATTEMPTS_MAX = 2 -FIX_COUNTER_DECREASE_INTERVAL_SEC = 30 * 60 -WATCHDOG_INTERVAL_SEC: float = 5 +# files paths +CONFIG_FILE = ETC_DIR / "config.yaml" +API_SOCK_FILE = RUN_DIR / "kres-api.sock" -USER_DEFAULT = build_conf.user if build_conf else "knot-resolver" -GROUP_DEFAULT = build_conf.group if build_conf else "knot-resolver" +# environmental variables +CONFIG_FILE_ENV_VAR = "KRES_CONFIG_FILE" +API_SOCK_FILE_ENV_VAR = "KRES_API_SOCK_FILE" -RUN_DIR_DEFAULT: Path = build_conf.run_dir if build_conf else Path("/var/run/knot-resolver") -ETC_DIR_DEFAULT: Path = build_conf.etc_dir if build_conf else Path("/etc/knot-resolver") -CONFIG_FILE_PATH_DEFAULT = ETC_DIR_DEFAULT / "config.yaml" -CONFIG_FILE_PATH_ENV_VAR = "KRES_MANAGER_CONFIG" -API_SOCK_PATH_DEFAULT = RUN_DIR_DEFAULT / "kres-api.sock" -API_SOCK_PATH_ENV_VAR = "KRES_MANAGER_API_SOCK" - - -def kresd_executable() -> Path: - assert build_conf is not None - return build_conf.sbin_dir / "kresd" - - -def kres_cache_gc_executable() -> Path: - assert build_conf is not None - return build_conf.sbin_dir / "kres-cache-gc" +# executables paths +KRESD_EXECUTABLE = SBIN_DIR / "kresd" +KRES_CACHE_GC_EXECUTABLE = SBIN_DIR / "kres-cache-gc" diff --git a/python/knot_resolver_build_options.py.in b/python/knot_resolver_build_options.py.in deleted file mode 100644 index e6b2accbd..000000000 --- a/python/knot_resolver_build_options.py.in +++ /dev/null @@ -1,12 +0,0 @@ -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@") -user = "@user@" -group = "@group@" diff --git a/python/meson.build b/python/meson.build index 4be61235c..f6539e515 100644 --- a/python/meson.build +++ b/python/meson.build @@ -1,25 +1,16 @@ # 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) -python_config.set('user', user) -python_config.set('group', group) +constants_config = configuration_data() +constants_config.set('version', meson.project_version()) +constants_config.set('user', user) +constants_config.set('group', group) +constants_config.set('run_dir', run_dir) +constants_config.set('etc_dir', etc_dir) +constants_config.set('sbin_dir', sbin_dir) configure_file( - input: 'knot_resolver_build_options.py.in', - output: 'knot_resolver_build_options.py', - configuration: python_config, -) - -configure_file( - input: 'setup.py.in', - output: 'setup.py', - configuration: python_config, + input: 'constants.py.in', + output: 'constants.py', + configuration: constants_config, ) diff --git a/python/setup.py.in b/python/setup.py.in deleted file mode 100644 index 57f9a6846..000000000 --- a/python/setup.py.in +++ /dev/null @@ -1,12 +0,0 @@ -from setuptools import setup - -# TODO: Migrate this to a pyproject.toml once Debian 11 support is dropped. -setup( - name="knot_resolver_build_options", - 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_build_options"], -) diff --git a/scripts/poe-tasks/configure b/scripts/poe-tasks/configure index c7cfbb2f1..d2b38a460 100755 --- a/scripts/poe-tasks/configure +++ b/scripts/poe-tasks/configure @@ -5,5 +5,3 @@ src_dir="$(dirname "$(realpath "$0")")" source $src_dir/utils/_env.sh kres_meson_configure - -kres_meson_build diff --git a/scripts/poe-tasks/utils/_env.sh b/scripts/poe-tasks/utils/_env.sh index 59947fb54..b5e0f14f6 100644 --- a/scripts/poe-tasks/utils/_env.sh +++ b/scripts/poe-tasks/utils/_env.sh @@ -66,6 +66,11 @@ function kres_meson_configure { echo -e "${blue}${reset}" echo meson setup $build_dir $reconfigure --prefix=$install_dir -Duser=$USER -Dgroup=$(id -gn) "$@" + echo + echo Copying Knot Resolver constants.py module + echo ----------------------------------------- + cp -v $build_dir/python/constants.py $gitroot/python/knot_resolver/constants.py + echo } function kres_meson_build { @@ -78,6 +83,7 @@ function kres_meson_build { echo ninja -C $build_dir ninja install -C $build_dir + echo else echo echo Knot Resolver is not configured for building.