From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms1.migadu.com with LMTPS id IK+ZCtpAW2YyRwAAe85BDQ:P1 (envelope-from ) for ; Sat, 01 Jun 2024 17:40:10 +0200 Received: from aspmx1.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id IK+ZCtpAW2YyRwAAe85BDQ (envelope-from ) for ; Sat, 01 Jun 2024 17:40:10 +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-Seal: i=1; s=key1; d=yhetil.org; t=1717256410; a=rsa-sha256; cv=none; b=sB6Wq9w7lMDCLvjog260GbRnWpEra7L/LSJNnidyZwBXhf88YkdXRZVQe9YekDqEQTm0Tm 8OH7eMKGHH++7/orcrqlJRiNGRWm2QF5pV1hG7RPZ49peDGmpf88U7LnuZE3/r15aHwkP2 gyReyHkxDk6vhsCaO8t6uBAkXC3102Kcd5qdJr2AIafrzY0cuED5M44iFTrRismiosFNaE n9IgNR6c5nVjF5JivGICaKsVQToNknUtuBSx5R3AIa3VeBUvjjn1fuRPVV4FVsz9QNeWWp CB4DSUM7U+IFMhIH/trsY7nqDg6QcLrvNsFRIyG120/u5DvPU7BvM9SrqRNsfQ== 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" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1717256410; 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=eCUdvmoqazzZVR6OHnGWsC3t2GVvF/JW4bCd7panQBJ9xXWpnq0aX/0Anzwy5Mcc5dNSm/ UVZQuGqdhI0SCP9cMDrbg8wvzISzFYagvyIdno+Vf8Y15v1WzG+gYw5Cc119vN21kPzDxK SvXJVf2I5RgTzRN8lttN+c9I27XpRgtVzObpJMDg/ihH8v9eDsDHMCxm3pIrc+LI2aaLED qov6WnXXVf+miHOiZELEmK/ljrho7bqzOPhV1rGputcqKmj5gjS1La6R6g3GkDFfk1x7o6 t4lu7AUwhWUnW8ycdlpw/9sz8wCitgEH4L4xoexUZEcp+eFq/fmsDURf/VDyLA== 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 F0E3460C6C for ; Sat, 1 Jun 2024 17:40:09 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sDQpk-0000rg-My; Sat, 01 Jun 2024 11:39:52 -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 1sDQpj-0000r8-Oq for guix-patches@gnu.org; Sat, 01 Jun 2024 11:39:51 -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 1sDQpj-0007go-HG for guix-patches@gnu.org; Sat, 01 Jun 2024 11:39:51 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sDQpv-0003eJ-6J for guix-patches@gnu.org; Sat, 01 Jun 2024 11:40:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#70858] [PATCH python-team v2 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: Sat, 01 Jun 2024 15:40:03 +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.171725635813734 (code B ref 70858); Sat, 01 Jun 2024 15:40:03 +0000 Received: (at 70858) by debbugs.gnu.org; 1 Jun 2024 15:39:18 +0000 Received: from localhost ([127.0.0.1]:57128 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sDQpB-0003ZG-CQ for submit@debbugs.gnu.org; Sat, 01 Jun 2024 11:39:17 -0400 Received: from 10.mo575.mail-out.ovh.net ([46.105.79.203]:51249) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sDQp8-0003Yl-JY for 70858@debbugs.gnu.org; Sat, 01 Jun 2024 11:39:15 -0400 Received: from director4.ghost.mail-out.ovh.net (unknown [10.108.2.10]) by mo575.mail-out.ovh.net (Postfix) with ESMTP id 4Vs40P1X9cz1Qhs for <70858@debbugs.gnu.org>; Sat, 1 Jun 2024 15:39:01 +0000 (UTC) Received: from ghost-submission-6684bf9d7b-bm5gz (unknown [10.110.168.242]) by director4.ghost.mail-out.ovh.net (Postfix) with ESMTPS id F060A1FDF7; Sat, 1 Jun 2024 15:39:00 +0000 (UTC) Received: from ngraves.fr ([37.59.142.110]) by ghost-submission-6684bf9d7b-bm5gz with ESMTPSA id aoV0OJRAW2a9VhoAxv7ynA (envelope-from ); Sat, 01 Jun 2024 15:39:00 +0000 X-OVh-ClientIp: 81.67.146.208 Date: Sat, 1 Jun 2024 17:36:34 +0200 Message-ID: <20240601153854.30805-3-ngraves@ngraves.fr> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240601153854.30805-1-ngraves@ngraves.fr> References: <20240601153854.30805-1-ngraves@ngraves.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Ovh-Tracer-Id: 4653625791635120866 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvledrvdekkedgleduucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucenucfjughrpefhvfevufffkffojghfgggtgfesthekredtredtjeenucfhrhhomheppfhitgholhgrshcuifhrrghvvghsuceonhhgrhgrvhgvshesnhhgrhgrvhgvshdrfhhrqeenucggtffrrghtthgvrhhnpedvleelgeeffeetleekueegvdfhtedvueffiefhkedtleejkeduveelgfdufeduleenucfkphepuddvjedrtddrtddruddpkedurdeijedrudegiedrvddtkedpfeejrdehledrudegvddruddutdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduvdejrddtrddtrddupdhmrghilhhfrhhomhepnhhgrhgrvhgvshesnhhgrhgrvhgvshdrfhhrpdhnsggprhgtphhtthhopedupdhrtghpthhtohepjedtkeehkeesuggvsggsuhhgshdrghhnuhdrohhrghdpoffvtefjohhsthepmhhoheejhedpmhhouggvpehsmhhtphhouhht 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-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Queue-Id: F0E3460C6C X-Migadu-Scanner: mx12.migadu.com X-Migadu-Spam-Score: -6.84 X-Spam-Score: -6.84 X-TUID: OyrFflyQbg3h * 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