1
0
mirror of https://git.savannah.gnu.org/git/guix.git synced 2026-04-06 21:20:33 +02:00
Files
guix/gnu/packages/aux-files/python/pytest_guix.py
Nicolas Graves 3a96221c79 build-system/pyproject: Ignore selected pytest inputs.
This commit includes squashed changes from
https://codeberg.org/guix/guix/pulls/7220 and
https://codeberg.org/guix/guix/pulls/7338.

* gnu/packages/aux-files/python/pytest_guix.py: New file.
* Makefile.am: Record it.
* guix/build/pyproject-build-system.scm (check): Preload pytest_guix
plugin when available.
* guix/build-system/pyproject.scm (default-pytest-guix-plugin): New
package, generated from pytest_guix.py.
(lower): Add python-pytest-guix argument, and inject it if
python-pytest is in the native-inputs.

Change-Id: I13263b461e9962aad340347657b9c9685db63927
Signed-off-by: Sharlatan Hellseher <sharlatanus@gmail.com>
2026-04-04 22:41:52 +01:00

69 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
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).
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.
"""
plugin_options = {
"cov": [
"--cov",
"--cov-reset",
"--cov-report",
"--cov-config",
"--no-cov-on-fail",
"--no-cov",
"--cov-fail-under",
"--cov-append",
"--cov-branch",
"--cov-context",
],
"mypy": ["--mypy", "--mypy-config-file", "--mypy-ignore-missing-imports"],
"isort": ["--isort"],
"flake8": ["--flake8"],
"black": ["--black"],
"flakes": ["--flakes"],
"pep8": ["--pep8"],
"html": ["--html", "--self-contained-html", "--css"],
}
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 in options:
group.addoption(option, action="append", nargs="?")