From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms1.migadu.com with LMTPS id 4IA/D+AhLmbJWAAAqHPOHw:P1 (envelope-from ) for ; Sun, 28 Apr 2024 12:16:00 +0200 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id 4IA/D+AhLmbJWAAAqHPOHw (envelope-from ) for ; Sun, 28 Apr 2024 12:16:00 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=none; 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"; dmarc=pass (policy=none) header.from=gnu.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1714299360; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=Kjh3DKgjyczipOjlcoQjqw3tag0lMv/Yt3f+tTNVv0c=; b=fuOpjWrOchX7LNUNJU1bRbiZR8FS2hqStEpS+UK8lBtU6n6k1p/TS0qlQ4RPN44XLn4P0H vAQlBIeb+yKpX5TRKaYklsDxSqCQXMiRkR95WT8qevB/n9z5LOfHYUDurVTuli9538oUeq 38vQ1lmD/vuPORGAVup9x93R81LR5Am4U1TGx6RhlPy/xUzlhSZRnh/7AxJzZLbFCGIxm8 JlbdkgGb9lQbVDIXb+uywZgGKZPvSD87o/RGm/bupqjlOFxjHer82kOugJSYFAvK0F4qEt yPb5Uwz9h0VjHjokibhXPr1+3EfFFVNPRz5yWNkFCc6ET/+L44nrA20By1rW0g== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; 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"; dmarc=pass (policy=none) header.from=gnu.org ARC-Seal: i=1; s=key1; d=yhetil.org; t=1714299360; a=rsa-sha256; cv=none; b=IcaehQLccOPTM1Y0DQoGjmnP2wmU1dlVldyxsnOCeO3orMN9H9YrPN4K+jvv/W8gAN9smz 9C8xcVUcALD6hL9hC6g6J1+uNKmxGJP4gMHNQzoKFVQZhkO1gg0JXFlarKY/RZOtJtVA8Q btTW/j8Lcij1HHLxAWvj2xBxEqOwsvs1rjsydUxdDqKZWjMvo+VsX23f/9haAWSG/MHoy4 NNrZwX1sX86Ym4Gqi3HZM+5eh31thZMpzweN/5YQ447RohgO7kimhM8j0tNJs0qo9upub1 2MhV3aXYI4+3t+gZ9gCFR0LtaOhimutYlbgmnIV440fMmLKiChlGfMJM/PJ3PA== 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 E1D4F17688 for ; Sun, 28 Apr 2024 12:15:59 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s11ZU-0001ym-6i; Sun, 28 Apr 2024 06:15:48 -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 1s11ZQ-0001xy-2j for guix-patches@gnu.org; Sun, 28 Apr 2024 06:15:46 -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 1s11ZP-0007xX-Ar for guix-patches@gnu.org; Sun, 28 Apr 2024 06:15:43 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1s11Zi-0004lf-7w for guix-patches@gnu.org; Sun, 28 Apr 2024 06:16: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: Sun, 28 Apr 2024 10:16: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 Received: via spool by 70570-submit@debbugs.gnu.org id=B70570.171429930918303 (code B ref 70570); Sun, 28 Apr 2024 10:16:02 +0000 Received: (at 70570) by debbugs.gnu.org; 28 Apr 2024 10:15:09 +0000 Received: from localhost ([127.0.0.1]:50127 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s11Yq-0004l9-Or for submit@debbugs.gnu.org; Sun, 28 Apr 2024 06:15:09 -0400 Received: from 7.mo576.mail-out.ovh.net ([46.105.50.32]:44221) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s11Yn-0004l1-5i for 70570@debbugs.gnu.org; Sun, 28 Apr 2024 06:15:08 -0400 Received: from director3.ghost.mail-out.ovh.net (unknown [10.109.139.40]) by mo576.mail-out.ovh.net (Postfix) with ESMTP id 4VS2Pv646Wz1ks5 for <70570@debbugs.gnu.org>; Sun, 28 Apr 2024 10:14:43 +0000 (UTC) Received: from ghost-submission-6684bf9d7b-gnph6 (unknown [10.110.168.164]) by director3.ghost.mail-out.ovh.net (Postfix) with ESMTPS id 7F3DB1FE93 for <70570@debbugs.gnu.org>; Sun, 28 Apr 2024 10:14:43 +0000 (UTC) Received: from ngraves.fr ([37.59.142.110]) by ghost-submission-6684bf9d7b-gnph6 with ESMTPSA id MarBGpMhLmZ6BgAA1cFsrQ (envelope-from ) for <70570@debbugs.gnu.org>; Sun, 28 Apr 2024 10:14:43 +0000 X-OVh-ClientIp: 81.67.146.208 In-Reply-To: <20240427165504.8843-2-ngraves@ngraves.fr> References: <20240427165504.8843-1-ngraves@ngraves.fr> <20240427165504.8843-2-ngraves@ngraves.fr> Date: Sun, 28 Apr 2024 12:14:42 +0200 Message-ID: <874jblvlnx.fsf@ngraves.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Ovh-Tracer-Id: 2419277427244786258 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvledrvddtgedghedvucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucenucfjughrpefhvffujghffffkgggtgfesthhqredttddtjeenucfhrhhomheppfhitgholhgrshcuifhrrghvvghsuceonhhgrhgrvhgvshesnhhgrhgrvhgvshdrfhhrqeenucggtffrrghtthgvrhhnpeeijeeukeekffevuedvhfefvdegheegiedtfefffeeltdefudduudelkeejheetudenucfkphepuddvjedrtddrtddruddpkedurdeijedrudegiedrvddtkedpfeejrdehledrudegvddruddutdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduvdejrddtrddtrddupdhmrghilhhfrhhomhepnhhgrhgrvhgvshesnhhgrhgrvhgvshdrfhhrpdhnsggprhgtphhtthhopedupdhrtghpthhtohepjedtheejtdesuggvsggsuhhgshdrghhnuhdrohhrghdpoffvtefjohhsthepmhhoheejiedpmhhouggvpehsmhhtphhouhht 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: -6.89 X-Spam-Score: -6.89 X-Migadu-Queue-Id: E1D4F17688 X-Migadu-Scanner: mx13.migadu.com X-TUID: XPZ9gYTLHJYU On 2024-04-27 18:54, Nicolas Graves wrote: > * 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 =C2=A9 2021 Lars-Dominik Braun > ;;; Copyright =C2=A9 2022 Marius Bakke > +;;; Copyright =C2=A9 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))) >=20=20 > -(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-impo= rts")) > + ("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 =3D parser.getgroup('guix','Guix ignored options') > + options =3D [~{~s, ~}] > + for option in options: > + group.addoption(option, action=3D'append', nargs=3D'?')" > + flags)) > + > +(define (call-with-guix-pytest-plugin inputs thunk) > + "This function emulates command line options provided by pytest plugin= s 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)) This filter is not working properly as it doesn't output names but pairs. Will be changed in the next revision with a map car. > + (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")) I found that in some edge cases, a hidden directory in the current dir can cause tests to fail. It only happened for one package which was failing on the __init__.py from .guix-pytest, meaning that tests could consider this directory. So it's better to put that out-of-source in ../.guix-pytest. Will be done in the next revision. > + (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-othe= r-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 %stand= ard-phases) > (apply python:python-build #:inputs inputs #:phases phases args)) >=20=20 > ;;; pyproject-build-system.scm ends here > +;;; Local Variables: > +;;; eval: (put 'with-guix-pytest-plugin 'scheme-indent-function 1) > +;;; End: --=20 Best regards, Nicolas Graves