From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms1.migadu.com with LMTPS id EI8dG53TPWYdHwEAe85BDQ:P1 (envelope-from ) for ; Fri, 10 May 2024 09:58:21 +0200 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id EI8dG53TPWYdHwEAe85BDQ (envelope-from ) for ; Fri, 10 May 2024 09:58:21 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1715327901; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post; bh=KDuyJUbaCfhXjuKLze9DCgWCxi+81EItw1mCcRFWYd4=; b=RZ/AddbCkMNTFWRmntQFQoPXnU4B4OHN/If4wZL56yYpna1tEt7zmsHtR8l/jgyehSAgls huMWesjziDmA3wqfRQBVicXoqgRB69mJhH11wstC/pHU0aHr2Jw+1pImd7trfCADfsO7xD ipWKa8eznHhQb8VhnUtd5luZ5pSFxEiuXsLvN/M+BfHl+9RuIVo9S1YbNSS2QyjXv8mIBe CbMVethPp6VwHftgPQehK8IjdFt9eHt/9w7HYp+CRaWecnK1dtPxrVHaTbEVBc4GOfa6cA k3nPc9gvzJfBcsXzyJJLHAnWcb/G9LAdHUl3WcE/yJ/VTGCQ2BNZd13HG8b2aA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1715327901; a=rsa-sha256; cv=none; b=rnRDNmLuXBOaohft36qAV5057RqKO6L75GbZ+WiuK8lp/RPZ+Xa8JKXe0Q5i664SOcgvSA A1wzh7XqgVqAVpIYri8aFO2EksFdTNRSPG6XvsHRPakRIpgFWVKXXrPZkQHCppJqhGF7Dr x01LY1omeerfRLsrfajJe6c51j5/Uke5e9HVV5KDk6r1xHwfuPB/RyP4fGWVicTX4RQtqN FlOaXJo0Ywz+JiICOVgrUzLmgXc8N+b/somxnsDewK/DjvqNq62UQYcnEkcyYesexjSj+d mQcqF4VOlBkr9x8FBZYVwO+yDUl+wRogvLGAMGehoifhVbjhcCfdkonKO5SfZg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 2D77742F2 for ; Fri, 10 May 2024 09:58:21 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s5L8O-00024k-Pe; Fri, 10 May 2024 03:57:40 -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 1s5L7p-0001sY-9g for guix-patches@gnu.org; Fri, 10 May 2024 03:57:05 -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 1s5L7n-0005TZ-Vm for guix-patches@gnu.org; Fri, 10 May 2024 03:57:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1s5L7m-0000Sy-9V for guix-patches@gnu.org; Fri, 10 May 2024 03:57:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#70858] [PATCH 02/32] build-system/pyproject: Ignore unwanted pytest flags. Resent-From: Nicolas Graves Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 10 May 2024 07:57:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 70858 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 70858@debbugs.gnu.org Cc: ngraves@ngraves.fr Received: via spool by 70858-submit@debbugs.gnu.org id=B70858.17153277771473 (code B ref 70858); Fri, 10 May 2024 07:57:02 +0000 Received: (at 70858) by debbugs.gnu.org; 10 May 2024 07:56:17 +0000 Received: from localhost ([127.0.0.1]:41696 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s5L72-0000NZ-7z for submit@debbugs.gnu.org; Fri, 10 May 2024 03:56:17 -0400 Received: from 11.mo550.mail-out.ovh.net ([188.165.48.29]:50567) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s5L6w-0000NC-Ci for 70858@debbugs.gnu.org; Fri, 10 May 2024 03:56:13 -0400 Received: from director7.ghost.mail-out.ovh.net (unknown [10.108.25.35]) by mo550.mail-out.ovh.net (Postfix) with ESMTP id 4VbLmV347Bz1Q7t for <70858@debbugs.gnu.org>; Fri, 10 May 2024 07:56:10 +0000 (UTC) Received: from ghost-submission-6684bf9d7b-m8g5t (unknown [10.110.168.153]) by director7.ghost.mail-out.ovh.net (Postfix) with ESMTPS id 27E6F1FEC3; Fri, 10 May 2024 07:56:10 +0000 (UTC) Received: from ngraves.fr ([37.59.142.107]) by ghost-submission-6684bf9d7b-m8g5t with ESMTPSA id Vx//BhrTPWaZCQAAD20Pwg (envelope-from ); Fri, 10 May 2024 07:56:10 +0000 X-OVh-ClientIp: 81.67.146.208 Date: Fri, 10 May 2024 09:55:06 +0200 Message-ID: <20240510075605.6303-2-ngraves@ngraves.fr> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240510075605.6303-1-ngraves@ngraves.fr> References: <20240510075605.6303-1-ngraves@ngraves.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Ovh-Tracer-Id: 15211470695153001186 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvledrvdefjedgvdduucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucenucfjughrpefhvfevufffkffojghfgggtgfesthekredtredtjeenucfhrhhomheppfhitgholhgrshcuifhrrghvvghsuceonhhgrhgrvhgvshesnhhgrhgrvhgvshdrfhhrqeenucggtffrrghtthgvrhhnpedvleelgeeffeetleekueegvdfhtedvueffiefhkedtleejkeduveelgfdufeduleenucfkphepuddvjedrtddrtddruddpkedurdeijedrudegiedrvddtkedpfeejrdehledrudegvddruddtjeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduvdejrddtrddtrddupdhmrghilhhfrhhomhepnhhgrhgrvhgvshesnhhgrhgrvhgvshdrfhhrpdhnsggprhgtphhtthhopedupdhrtghpthhtohepjedtkeehkeesuggvsggsuhhgshdrghhnuhdrohhrghdpoffvtefjohhsthepmhhoheehtddpmhhouggvpehsmhhtphhouhht 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 From: Nicolas Graves via Guix-patches via Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -3.88 X-Spam-Score: -3.88 X-Migadu-Queue-Id: 2D77742F2 X-Migadu-Scanner: mx11.migadu.com X-TUID: QauSpEiondfj * guix/build/pyproject-build-system.scm : Ignore unwanted pytest flags. Change-Id: Ib9f1602e5af11227e5b7ce124f0f9be4fa2b78e4 --- guix/build/pyproject-build-system.scm | 99 ++++++++++++++++++++++++++- 1 file changed, 96 insertions(+), 3 deletions(-) diff --git a/guix/build/pyproject-build-system.scm b/guix/build/pyproject-build-system.scm index 947d240114a..2df9f2f4798 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. ;;; @@ -35,7 +36,8 @@ (define-module (guix build pyproject-build-system) add-installed-pythonpath site-packages python-version - pyproject-build)) + pyproject-build + with-guix-pytest-plugin)) ;;; Commentary: ;;; @@ -142,7 +144,94 @@ (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 + (map car + (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))) + (dir (string-append + (if (access? (dirname (getcwd)) W_OK) + (dirname (getcwd)) + ;; fallback if we're already out-of-source + (getcwd)) + "/.guix-pytest"))) + (dynamic-wind + (lambda () + (setenv "PYTHONPATH" + (string-append + (if former-path + (string-append former-path ":") + "") + dir)) + (setenv "PYTEST_PLUGINS" + (string-append + (if (getenv "PYTEST_PLUGINS") + (string-append former-path ",") + "") + "pytest_guix_plugin")) + (mkdir-p dir) + (with-output-to-file (string-append dir "/__init__.py") + (lambda _ (display ""))) + (with-output-to-file (string-append dir "/pytest_guix_plugin.py") + (lambda _ + (display (pytest-ignore-flags-plugin filtered-flags))))) + thunk + (lambda () + (setenv "PYTHONPATH" former-path) + (unsetenv "PYTEST_PLUGINS"))))) + +(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 +254,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 +476,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: -- 2.41.0