]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
python/knot_resolver: use constants.py configured by Meson
authorAleš Mrázek <ales.mrazek@nic.cz>
Tue, 10 Sep 2024 09:07:09 +0000 (11:07 +0200)
committerAleš Mrázek <ales.mrazek@nic.cz>
Mon, 30 Sep 2024 09:16:07 +0000 (11:16 +0200)
python/constants.py.in [new file with mode: 0644]
python/knot_resolver/constants.py
python/knot_resolver_build_options.py.in [deleted file]
python/meson.build
python/setup.py.in [deleted file]
scripts/poe-tasks/configure
scripts/poe-tasks/utils/_env.sh

diff --git a/python/constants.py.in b/python/constants.py.in
new file mode 100644 (file)
index 0000000..4fa71cb
--- /dev/null
@@ -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"
index f63478d4a02a79314ca6293c716354a832596021..fb45c26b68f635f0903ac4fa5e2e2adff4ff1310 100644 (file)
@@ -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 (file)
index e6b2acc..0000000
+++ /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@"
index 4be61235c18a8fda1353dc72b2956b616a32b7a8..f6539e5151c2b96a1e1c62600f90722c04ca23dc 100644 (file)
@@ -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 (file)
index 57f9a68..0000000
+++ /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"],
-)
index c7cfbb2f1cf439ac2914c7d6c9e29e0be32cfd9a..d2b38a46052327cdfd3013b43bb57d753f8ce6db 100755 (executable)
@@ -5,5 +5,3 @@ src_dir="$(dirname "$(realpath "$0")")"
 source $src_dir/utils/_env.sh
 
 kres_meson_configure
-
-kres_meson_build
index 59947fb543538f5c3b59d21f59f4b69fc703cd0d..b5e0f14f6424048caa14b18980227861da43167a 100644 (file)
@@ -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.