# # Copyright (c) 2021-2025 ahriman team. # # This file is part of ahriman # (see https://github.com/arcan1s/ahriman). # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # import importlib import sys from tox.config.sets import EnvConfigSet from tox.plugin import impl from tox.session.state import State from tox.tox_env.api import ToxEnv @impl def tox_add_env_config(env_conf: EnvConfigSet, _: State) -> None: """ append plugin options to the configuration keys Args: env_conf(EnvConfigSet): environment configuration set """ env_conf.add_config( keys=["dynamic_version"], of_type=str, default="", desc="import version from", ) @impl def tox_before_run_commands(tox_env: ToxEnv) -> None: """ extract version dynamically and set VERSION environment variable Args: tox_env(ToxEnv): current tox environment """ if not tox_env.conf["dynamic_version"]: return set_env = tox_env.conf["set_env"] if "PYTHONPATH" in set_env: sys.path.append(set_env.load("PYTHONPATH")) module_name, variable_name = tox_env.conf["dynamic_version"].rsplit(".", maxsplit=1) module = importlib.import_module(module_name) set_env.update({"VERSION": getattr(module, variable_name)})