mirror of
https://git.savannah.gnu.org/git/guix.git
synced 2026-04-08 14:10:38 +02:00
* guix/build/pyproject-build-system.scm (keywords->alist, guile->python-keywords): Add procedures. (check): Convert keyword alist before writing it. * guix/build-system/pyproject.scm (%default-pytest-guix-options): Add some python kwargs in a guile format. * gnu/packages/aux-files/python/pytest_guix.py (pytest_addoption): Handle python kwargs when some are provided. Change-Id: Ie35e9b300acda830f35b6b754e8ccc07ad730faa Signed-off-by: Sharlatan Hellseher <sharlatanus@gmail.com>
59 lines
2.4 KiB
Python
59 lines
2.4 KiB
Python
# GNU Guix --- Functional package management for GNU
|
|
# Copyright © 2025 Nicolas Graves <ngraves@ngraves.fr>
|
|
#
|
|
# This file is part of GNU Guix.
|
|
#
|
|
# GNU Guix 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.
|
|
#
|
|
# GNU Guix 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 GNU Guix. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
import importlib.util
|
|
import json
|
|
|
|
|
|
def pytest_addoption(parser):
|
|
"""Add stub options to be ignored by pytest.
|
|
|
|
More precisely, inject all options provided in .pytest_guix_options.json,
|
|
except options whose plugin is indeed installed.
|
|
|
|
For example, if the json file records --cov:
|
|
if the pytest_cov module is installed, its --cov will be used.
|
|
otherwise, --cov is ignored (read by this parser, but nothing is done
|
|
with it).
|
|
|
|
Flags can be given with additional keyword arguments in a json object.
|
|
If the json object is not given, fallback to the default
|
|
{"action": "append", "nargs": "?"}. In practice, these arguments are only
|
|
mandatory for the store_true and store_const actions to avoid eating other
|
|
arguments.
|
|
|
|
This allows to remove development packages, which are not required at build
|
|
time while at the same time avoiding the need to adjust test options in
|
|
pyproject.toml or other configuration files.
|
|
"""
|
|
with open(".pytest_guix_options.json", "r") as options_file:
|
|
plugin_options = json.load(options_file)
|
|
group = parser.getgroup(
|
|
"guix", "Options ignored by the Guix pyproject-build-system"
|
|
)
|
|
|
|
# Only add options for plugins that are not present.
|
|
for key, options in plugin_options.items():
|
|
if importlib.util.find_spec(f"pytest_{key}") is None:
|
|
# Plugin not found, add stub options
|
|
for option, kwargs in options.items():
|
|
if kwargs:
|
|
group.addoption(option, **kwargs)
|
|
else:
|
|
group.addoption(option, action="append", nargs="?")
|