--- /dev/null
+from .constants import VERSION
+
+__version__ = VERSION
--- /dev/null
+from .main import main
+
+if __name__ == "__main__":
+ main()
--- /dev/null
+from .main import main
+
+if __name__ == "__main__":
+ main()
--- /dev/null
+def main() -> None:
+ pass
--- /dev/null
+import importlib.util
+import platform
+import re
+from pathlib import Path
+
+VERSION = "6.4.0"
+USER = "knot-resolver"
+GROUP = "knot-resolver"
+
+# dirs paths
+RUN_DIR = Path("/run/knot-resolver")
+ETC_DIR = Path("/etc/knot-resolver")
+BIN_DIR = Path("/usr/bin")
+SBIN_DIR = Path("/usr/sbin")
+CACHE_DIR = Path("/var/cache/knot-resolver")
+
+# files paths
+CONFIG_FILE = ETC_DIR / "config.yaml"
+API_SOCK_FILE = RUN_DIR / "kres-api.sock"
+
+# executables paths
+KRESD_EXECUTABLE = SBIN_DIR / "kresd"
+KRES_CACHE_GC_EXECUTABLE = SBIN_DIR / "kres-cache-gc"
+KRES_MANAGER_EXECUTABLE = BIN_DIR / "kres-manager"
+
+LINUX_SYS = platform.system() == "Linux"
+FREEBSD_SYS = platform.system() == "FreeBSD"
+
+WATCHDOG_LIB = bool(importlib.util.find_spec("watchdog"))
+PROMETHEUS_LIB = bool(importlib.util.find_spec("prometheus_client"))
+
+
+def _freebsd_workers_support() -> bool:
+ if FREEBSD_SYS:
+ release = platform.release()
+ match = re.match(r"(\d+)", release)
+ if match:
+ freebsd_min_version = 12
+ return int(match.group(1)) >= freebsd_min_version
+ return False
+
+
+# It is possible to configure multiple kresd workers on Linux systems due to the SO_REUSEPORT socket option.
+# FreeBSD version >=12 supports it specifically due to the additional SO_REUSEPORT_LB socket option.
+WORKERS_SUPPORT = LINUX_SYS or _freebsd_workers_support()
+
+# default maximum number of workers
+WORKERS_MAX = 256
+
+# Systemd-like NOTIFY message is supported only on Linux systems
+NOTIFY_SUPPORT = LINUX_SYS
--- /dev/null
+import importlib.util
+import platform
+import re
+from pathlib import Path
+
+VERSION = "@version@"
+USER = "@user@"
+GROUP = "@group@"
+
+# dirs paths
+RUN_DIR = Path("@run_dir@")
+ETC_DIR = Path("@etc_dir@")
+BIN_DIR = Path("@bin_dir@")
+SBIN_DIR = Path("@sbin_dir@")
+CACHE_DIR = Path("@cache_dir@")
+
+# files paths
+CONFIG_FILE = ETC_DIR / "config.yaml"
+API_SOCK_FILE = RUN_DIR / "kres-api.sock"
+
+# executables paths
+KRESD_EXECUTABLE = SBIN_DIR / "kresd"
+KRES_CACHE_GC_EXECUTABLE = SBIN_DIR / "kres-cache-gc"
+KRES_MANAGER_EXECUTABLE = BIN_DIR / "kres-manager"
+
+LINUX_SYS = platform.system() == "Linux"
+FREEBSD_SYS = platform.system() == "FreeBSD"
+
+WATCHDOG_LIB = bool(importlib.util.find_spec("watchdog"))
+PROMETHEUS_LIB = bool(importlib.util.find_spec("prometheus_client"))
+
+
+def _freebsd_workers_support() -> bool:
+ if FREEBSD_SYS:
+ release = platform.release()
+ match = re.match(r"(\d+)", release)
+ if match:
+ freebsd_min_version = 12
+ return int(match.group(1)) >= freebsd_min_version
+ return False
+
+
+# It is possible to configure multiple kresd workers on Linux systems due to the SO_REUSEPORT socket option.
+# FreeBSD version >=12 supports it specifically due to the additional SO_REUSEPORT_LB socket option.
+WORKERS_SUPPORT = LINUX_SYS or _freebsd_workers_support()
+
+# default maximum number of workers
+WORKERS_MAX = 256
+
+# Systemd-like NOTIFY message is supported only on Linux systems
+NOTIFY_SUPPORT = LINUX_SYS
--- /dev/null
+class BaseKresError(Exception):
+ """Base class for all errors used in Knot Resolver modules."""
--- /dev/null
+from __future__ import annotations
+
+
+def main() -> None:
+ pass
--- /dev/null
+from .main import main
+
+if __name__ == "__main__":
+ main()
--- /dev/null
+from knot_resolver.errors import BaseKresError
+
+
+class KresManagerError(BaseKresError):
+ """Class for all errors used in manager submodules."""
--- /dev/null
+def main() -> None:
+ pass
--- /dev/null
+# python
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+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('bin_dir', bin_dir)
+constants_config.set('sbin_dir', sbin_dir)
+constants_config.set('cache_dir', systemd_cache_dir)
+
+configure_file(
+ input: 'constants.py.in',
+ output: 'constants.py',
+ configuration: constants_config,
+)
set +e
# dirs to check
-dirs="python/knot_resolver/ tests/manager"
+dirs="python/knot_resolver/ tests/python/knot_resolver"
# check imports
echo -e "${yellow}Checking Python imports using Ruff...${reset}"
src_dir="$(dirname "$(realpath "$0")")"
source $src_dir/utils/_env.sh
-dirs="python/knot_resolver/ tests/manager"
+dirs="python/knot_resolver/ tests/python/knot_resolver"
# sort python import
echo -e "${yellow}Sorting Python imports using ruff...${reset}"
source $src_dir/utils/_env.sh
# run pytest
-env PYTHONPATH=. pytest --junitxml=unit.junit.xml --cov=python/knot_resolver --show-capture=all tests/manager
+env PYTHONPATH=. pytest --junitxml=unit.junit.xml --cov=python/knot_resolver --show-capture=all tests/python/knot_resolver
--- /dev/null
+from knot_resolver import __version__
+
+
+def test_version() -> None:
+ with open("VERSION", "r") as version_file:
+ version = version_file.read().strip()
+
+ assert __version__ == version