1
0
mirror of https://git.savannah.gnu.org/git/guix.git synced 2026-05-06 17:25:56 +02:00

build-system: pyproject: Add pytest-guix-options.

* guix/build/pyproject-build-system.scm (check):
Pass pytest-guix-options to python through a hidden json file.
* guix/build-system/pyproject.scm
(%default-pytest-guix-options): Add variable.
(pyproject-build): Use it.
* gnu/packages/aux-files/python/pytest_guix.py:
Import pytest-guix-options from guile through a hidden json file.

Change-Id: Ice2ea72452c335b900bc354a04bd9657dc03d7d4
Signed-off-by: Sharlatan Hellseher <sharlatanus@gmail.com>
This commit is contained in:
Nicolas Graves
2026-03-17 01:24:59 +01:00
committed by Sharlatan Hellseher
parent 94925eaa9a
commit 16342836d1
3 changed files with 45 additions and 33 deletions
+12 -31
View File
@@ -17,6 +17,7 @@
# along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
import importlib.util
import json
def pytest_addoption(parser):
@@ -34,35 +35,15 @@ def pytest_addoption(parser):
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"],
}
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"
)
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="?")
# 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="?")
+28
View File
@@ -97,6 +97,28 @@
build-system level.")
(license license:gpl3+))))
(define %default-pytest-guix-options
#~'(("cov"
"--cov"
"--cov-reset"
"--cov-report"
"--cov-config"
"--no-cov-on-fail"
"--no-cov"
"--cov-fail-under"
"--cov-append"
"--cov-branch"
"--cov-context")
("html"
"--html" "--self-contained-html" "--css")
("mypy"
"--mypy" "--mypy-config-file" "--mypy-ignore-missing-imports")
("isort" "isort")
("flake8" "flake8")
("black" "black")
("flakes" "flakes")
("pep8" "pep8")))
;; TODO: On the next iteration of python-team, migrate the sanity-check to
;; importlib_metadata instead of setuptools.
(define (default-sanity-check.py)
@@ -153,6 +175,7 @@ build-system level.")
(build-backend #f)
(test-backend #f)
(test-flags ''())
(pytest-guix-options %default-pytest-guix-options)
(phases '%standard-phases)
(outputs '("out" "wheel"))
(search-paths '())
@@ -182,6 +205,11 @@ build-system level.")
#:test-backend #$test-backend
#:test-flags #$test-flags
#:tests? #$tests?
#$@(let ((labels (map car inputs)))
(if (or (member "python-pytest-bootstrap" labels)
(member "python-pytest" labels))
#~(#:pytest-guix-options #$pytest-guix-options)
#~()))
#:phases #$(if (pair? phases)
(sexp->gexp phases)
phases)
+5 -2
View File
@@ -21,7 +21,7 @@
;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
(define-module (guix build pyproject-build-system)
#:autoload (json builder) (scm->json-string)
#:autoload (json builder) (scm->json scm->json-string)
#:use-module ((guix build gnu-build-system) #:prefix gnu:)
#:use-module (guix build utils)
#:use-module (guix build toml)
@@ -314,7 +314,8 @@ without errors."
(with-directory-excursion "/tmp"
(invoke "python" sanity-check.py (site-packages inputs outputs)))))
(define* (check #:key inputs tests? test-backend test-flags #:allow-other-keys)
(define* (check #:key inputs tests? test-backend test-flags pytest-guix-options
#:allow-other-keys)
"Run the test suite of a given Python package."
(if tests?
;; Unfortunately with PEP 517 there is no common method to specify test
@@ -347,6 +348,8 @@ without errors."
(format #t "Using ~a~%" use-test-backend)
(match use-test-backend
('pytest-with-guix-plugin
(call-with-output-file ".pytest_guix_options.json"
(cut scm->json pytest-guix-options <>))
(apply invoke pytest "-vv" "-p" "pytest_guix" test-flags))
('pytest
(apply invoke pytest "-vv" test-flags))