guix_mirror_bot pushed a commit to branch python-team
in repository guix.
commit f31c94d6275198576764d45142b88b231a4670fb
Author: Nicolas Graves <[email protected]>
AuthorDate: Tue Mar 17 01:24:59 2026 +0100
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 <[email protected]>
---
gnu/packages/aux-files/python/pytest_guix.py | 45 ++++++++--------------------
guix/build-system/pyproject.scm | 28 +++++++++++++++++
guix/build/pyproject-build-system.scm | 7 +++--
3 files changed, 46 insertions(+), 34 deletions(-)
diff --git a/gnu/packages/aux-files/python/pytest_guix.py
b/gnu/packages/aux-files/python/pytest_guix.py
index 750b1e99e9..dbe8dfe136 100644
--- a/gnu/packages/aux-files/python/pytest_guix.py
+++ b/gnu/packages/aux-files/python/pytest_guix.py
@@ -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"],
- }
-
- 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="?")
+ 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 in options:
+ group.addoption(option, action="append", nargs="?")
diff --git a/guix/build-system/pyproject.scm b/guix/build-system/pyproject.scm
index a74e5480bc..5536a8a7d3 100644
--- a/guix/build-system/pyproject.scm
+++ b/guix/build-system/pyproject.scm
@@ -96,6 +96,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)
@@ -152,6 +174,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 '())
@@ -181,6 +204,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)
diff --git a/guix/build/pyproject-build-system.scm
b/guix/build/pyproject-build-system.scm
index 5685ddc033..8cf2d2c599 100644
--- a/guix/build/pyproject-build-system.scm
+++ b/guix/build/pyproject-build-system.scm
@@ -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))