From patchwork Sat Apr 27 16:54:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nicolas Graves X-Patchwork-Id: 63517 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id D9A8B27BBEA; Sat, 27 Apr 2024 17:56:23 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, SPF_HELO_PASS autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id E616227BBE2 for ; Sat, 27 Apr 2024 17:56:22 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s0lL1-0000Dt-5p; Sat, 27 Apr 2024 12:55:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s0lKy-0000CJ-BP for guix-patches@gnu.org; Sat, 27 Apr 2024 12:55:44 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s0lKy-0006V4-3o for guix-patches@gnu.org; Sat, 27 Apr 2024 12:55:44 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1s0lLG-0000dh-Tv for guix-patches@gnu.org; Sat, 27 Apr 2024 12:56:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#70570] [PATCH v2 2/2] guix: pyproject-build-system: Ignore unwanted pytest flags. Resent-From: Nicolas Graves Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 27 Apr 2024 16:56:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 70570 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 70570@debbugs.gnu.org Cc: ngraves@ngraves.fr Received: via spool by 70570-submit@debbugs.gnu.org id=B70570.17142369322416 (code B ref 70570); Sat, 27 Apr 2024 16:56:02 +0000 Received: (at 70570) by debbugs.gnu.org; 27 Apr 2024 16:55:32 +0000 Received: from localhost ([127.0.0.1]:49582 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s0lKl-0000cj-7I for submit@debbugs.gnu.org; Sat, 27 Apr 2024 12:55:31 -0400 Received: from 17.mo584.mail-out.ovh.net ([46.105.41.16]:54531) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s0lKi-0000cU-Nj for 70570@debbugs.gnu.org; Sat, 27 Apr 2024 12:55:29 -0400 Received: from director8.ghost.mail-out.ovh.net (unknown [10.108.25.12]) by mo584.mail-out.ovh.net (Postfix) with ESMTP id 4VRbLN3Vdqz1JQ9 for <70570@debbugs.gnu.org>; Sat, 27 Apr 2024 16:55:08 +0000 (UTC) Received: from ghost-submission-6684bf9d7b-7r8zz (unknown [10.111.174.145]) by director8.ghost.mail-out.ovh.net (Postfix) with ESMTPS id 378071FD79; Sat, 27 Apr 2024 16:55:08 +0000 (UTC) Received: from ngraves.fr ([37.59.142.101]) by ghost-submission-6684bf9d7b-7r8zz with ESMTPSA id JMHFA+wtLWbhSwEAww0/Lg (envelope-from ); Sat, 27 Apr 2024 16:55:08 +0000 Authentication-Results: garm.ovh; auth=pass (GARM-101G0041ee1e413-50e6-4903-b0b4-d8a84a73cd64, A35C6C2D854BD2823198681D90DB7DB46B6540F1) smtp.auth=ngraves@ngraves.fr X-OVh-ClientIp: 81.67.146.208 Date: Sat, 27 Apr 2024 18:54:53 +0200 Message-ID: <20240427165504.8843-2-ngraves@ngraves.fr> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240427165504.8843-1-ngraves@ngraves.fr> References: <20240427165504.8843-1-ngraves@ngraves.fr> MIME-Version: 1.0 X-Ovh-Tracer-Id: 3309019830495339234 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvledrvddtuddguddtiecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemucehtddtnecunecujfgurhephffvvefufffkofgjfhggtgfgsehtkeertdertdejnecuhfhrohhmpefpihgtohhlrghsucfirhgrvhgvshcuoehnghhrrghvvghssehnghhrrghvvghsrdhfrheqnecuggftrfgrthhtvghrnhepvdelleegfeefteelkeeugedvhfetvdeuffeihfektdeljeekudevlefgudefudelnecukfhppeduvdejrddtrddtrddupdekuddrieejrddugeeirddvtdekpdefjedrheelrddugedvrddutddunecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepuddvjedrtddrtddruddpmhgrihhlfhhrohhmpehnghhrrghvvghssehnghhrrghvvghsrdhfrhdpnhgspghrtghpthhtohepuddprhgtphhtthhopeejtdehjedtseguvggssghughhsrdhgnhhurdhorhhgpdfovfetjfhoshhtpehmohehkeegpdhmohguvgepshhmthhpohhuth X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Nicolas Graves X-ACL-Warn: , Nicolas Graves via Guix-patches X-Patchwork-Original-From: Nicolas Graves via Guix-patches via From: Nicolas Graves Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * guix/build/pyproject-build-system.scm : Ignore unwanted pytest flags. Change-Id: Ib9f1602e5af11227e5b7ce124f0f9be4fa2b78e4 --- guix/build/pyproject-build-system.scm | 91 ++++++++++++++++++++++++++- 1 file changed, 89 insertions(+), 2 deletions(-) diff --git a/guix/build/pyproject-build-system.scm b/guix/build/pyproject-build-system.scm index 947d240114..ebe4e1941d 100644 --- a/guix/build/pyproject-build-system.scm +++ b/guix/build/pyproject-build-system.scm @@ -1,6 +1,7 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2021 Lars-Dominik Braun ;;; Copyright © 2022 Marius Bakke +;;; Copyright © 2024 Nicolas Graves ;;; ;;; This file is part of GNU Guix. ;;; @@ -142,7 +143,89 @@ (define* (build #:key outputs build-backend backend-path configure-flags #:allow wheel-dir config-settings))) -(define* (check #:key tests? test-backend test-flags #:allow-other-keys) +(define pytest-default-ignore-alist + '(("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")))) + +(define (pytest-ignore-flags-plugin flags) + "This function converts an list of flags into a string that can + be instantiated as a python pytest plugin." + (format #f "\ +import pytest + +def pytest_addoption(parser): + group = parser.getgroup('guix','Guix ignored options') + options = [~{~s, ~}] + for option in options: + group.addoption(option, action='append', nargs='?')" + flags)) + +(define (call-with-guix-pytest-plugin inputs thunk) + "This function emulates command line options provided by pytest plugins in +the absence of the plugins defining these options. + +This is done by selecting absent plugins, gettings their flags defined in +PYTEST-DEFAULT-IGNORE-ALIST, and generating the plugin from there with +PYTEST-IGNORE-FLAGS-PLUGIN." + (let* ((former-path (getenv "PYTHONPATH")) + (input-names + (filter (match-lambda + (((name . _) ...) + (if (string-prefix? "python-pytest-" name) + name + #f)) + ( _ #f)) + inputs)) + (filtered-flags + (filter identity + (append-map + (match-lambda + ((group . flags) + (if (member (string-append "python-pytest-" group) + input-names) + (list #f) + flags)) + (_ (list #f))) + pytest-default-ignore-alist)))) + (dynamic-wind + (lambda () + (setenv "PYTHONPATH" + (string-append + (if former-path + (string-append former-path ":") + "") + ".guix-pytest")) + (setenv "PYTEST_PLUGINS" + (string-append + (if (getenv "PYTEST_PLUGINS") + (string-append former-path ",") + "") + "pytest_guix_plugin")) + (mkdir-p ".guix-pytest") + (with-output-to-file ".guix-pytest/__init__.py" + (lambda _ (display ""))) + (with-output-to-file ".guix-pytest/pytest_guix_plugin.py" + (lambda _ + (display (pytest-ignore-flags-plugin filtered-flags))))) + thunk + (lambda () + (setenv "PYTHONPATH" former-path) + (unsetenv "PYTEST_PLUGINS") + (when (file-exists? ".guix-pytest") + (delete-file-recursively ".guix-pytest")))))) + +(define-syntax-rule (with-guix-pytest-plugin inputs exp ...) + "Evaluate EXP in a context where the Guix pytest plugin is added." + (call-with-guix-pytest-plugin inputs (lambda () exp ...))) + +(define* (check #:key inputs tests? test-backend test-flags #: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 @@ -165,7 +248,8 @@ (define* (check #:key tests? test-backend test-flags #:allow-other-keys) (format #t "Using ~a~%" use-test-backend) (match use-test-backend ('pytest - (apply invoke pytest "-vv" test-flags)) + (with-guix-pytest-plugin inputs + (apply invoke pytest "-vv" test-flags))) ('nose (apply invoke nosetests "-v" test-flags)) ('nose2 @@ -386,3 +470,6 @@ (define* (pyproject-build #:key inputs (phases %standard-phases) (apply python:python-build #:inputs inputs #:phases phases args)) ;;; pyproject-build-system.scm ends here +;;; Local Variables: +;;; eval: (put 'with-guix-pytest-plugin 'scheme-indent-function 1) +;;; End: