From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id gBnXNJxgaGLVDQAAbAwnHQ (envelope-from ) for ; Tue, 26 Apr 2022 23:14:04 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id YEACNZxgaGKQUgEA9RJhRA (envelope-from ) for ; Tue, 26 Apr 2022 23:14:04 +0200 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 CE3B530DF1 for ; Tue, 26 Apr 2022 23:14:00 +0200 (CEST) Received: from localhost ([::1]:35996 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1njSVT-0006RE-Vd for larch@yhetil.org; Tue, 26 Apr 2022 17:13:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53710) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1njSVE-0006NJ-JV for gwl-devel@gnu.org; Tue, 26 Apr 2022 17:13:45 -0400 Received: from sender4-of-o50.zoho.com ([136.143.188.50]:21099) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1njSVB-0008S8-FO for gwl-devel@gnu.org; Tue, 26 Apr 2022 17:13:43 -0400 ARC-Seal: i=1; a=rsa-sha256; t=1651007617; cv=none; d=zohomail.com; s=zohoarc; b=cxiSQx/2iso2JcBYO7by1BCLt5ca0VjPRxNfnMT2Tb3RCbSUvvO4XvWxQWR9PfxBQP6s7KiqwJziJJeRv4Y9De+73YQZUaEIfCAbNQPI6tsWZn0A0S3INP8Gz/L9dDtmR1PMNIXxyD32QBeVSbRP+F8kcW4BOOQ9LGkrcXwjdk8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1651007617; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=mISd02zPnEWUirwPeUghFRjk3N7vUP7HBXKdR2N3aHY=; b=bWsk2w7PI7Yd/B515L3GqXVXq3DYmnEICK8JN1sFXx0IGL2MRDRAwRF95RRfGs+tqrgFnXv1zvCoNizSqEdfRl1TSX/z1bihkARHxA1qW4P/S4H2uEnI/TZOwIRpegDghAB5OxitQAvq1dDQS/zbOmIkw/7Z8fVryyyXhZTRrgY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=elephly.net; spf=pass smtp.mailfrom=rekado@elephly.net; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1651007617; s=zoho; d=elephly.net; i=rekado@elephly.net; h=References:From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:In-reply-to:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Reply-To; bh=mISd02zPnEWUirwPeUghFRjk3N7vUP7HBXKdR2N3aHY=; b=fOLzIxikHDFwJKIUTwcgJPS9sSYUdkVGYHjtvHfXmBkEm3MpaGJlei4iwIfz/MwJ E60tYb4lzyOoYWFoty2n8xzOXnd6uXiAp4rVleFSpiAYRftI0oF/piPW6JJlWKs5zPz uSpMJP9O50+I8Gde/QeI8uvStQsrcRgv4b+8D24Y= Received: from localhost (56-111-142-46.pool.kielnet.net [46.142.111.56]) by mx.zohomail.com with SMTPS id 1651007614070442.41366776587984; Tue, 26 Apr 2022 14:13:34 -0700 (PDT) References: <20220421195158.22407-1-olivier.dion@polymtl.ca> <20220422184359.7929-1-olivier.dion@polymtl.ca> <20220422184359.7929-2-olivier.dion@polymtl.ca> <87ilqv66yd.fsf@elephly.net> <875ymvhds4.fsf@laura> User-agent: mu4e 1.6.10; emacs 28.0.50 From: Ricardo Wurmus To: Olivier Dion Subject: Re: [PATCH v2 1/2] packages: Support for full Guix specification Date: Tue, 26 Apr 2022 22:30:21 +0200 In-reply-to: <875ymvhds4.fsf@laura> X-URL: https://elephly.net X-PGP-Key: https://elephly.net/rekado.pubkey X-PGP-Fingerprint: BCA6 89B6 3655 3801 C3C6 2150 197A 5888 235F ACAC Message-ID: <875ymv5z0l.fsf@elephly.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External Received-SPF: pass client-ip=136.143.188.50; envelope-from=rekado@elephly.net; helo=sender4-of-o50.zoho.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: gwl-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: gwl-devel@gnu.org Errors-To: gwl-devel-bounces+larch=yhetil.org@gnu.org Sender: "gwl-devel" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1651007644; h=from:from:sender:sender: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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=mISd02zPnEWUirwPeUghFRjk3N7vUP7HBXKdR2N3aHY=; b=S/YXAJ5B/cKaJhqNriYUUA3tX8jDIuizXlHCzoxu0/OGC/wGFkD6TJJR/ElXSiVs1w5GQK KVUU9lB5YB4pf9fqO6TC8wLxWwTlYY3QeRy+cPAne7THv5EK6/elrXMEfuh4rNL8AtrtQI XgK7Xv9TSS4JHHDFcCrsFcFS4PAgfHQhzeEV3tJvDQuZpTXebtNdNMeBH6mDFHXKcXzxwh k1+6CV6xRDF/WMw+5lPzFCADm4XZjA7De8W4oLA5i1dx3Q+V1dT92Gp9iW/F4FPQUjBFkr Z/SAaL6jMb371XZeiUEiNdQx8lVcthW06jOHA4G5NGGpyHURGFKkkvGs5cwJcw== ARC-Seal: i=2; s=key1; d=yhetil.org; t=1651007644; a=rsa-sha256; cv=pass; b=WmpaufqrwMFZMoeVgJf7Nar3sooHUgcceZsFZzF0WiCsrTVwtJpGbMjB9s55rHGt0HrPZZ Wm+IdOGfj2zxKVPkbMuW0TOt5pZdOkWmSabeOcJIEuxabNUyU+YbXSLD1tNn1unsrmIb8K AvDhP80Vfi51ewyxVi+eEowYkZSWjbnmuO39SMLm7zDGzzQzqqORrZGgkYRs+DcuFfZT0Y BxS3z4WYC9KUi+gRQxvYqtu8iuGgxZj7O4DB++fmlrN4ftinlzTiiEJ97rCAYFYgNDT/kq NpfPIxSDNeTS53C/aZsdYd4ojyFYpv4ZeHOC2EduDQSMnjfwsKAfdcGHPtgnXQ== ARC-Authentication-Results: i=2; aspmx1.migadu.com; dkim=pass header.d=elephly.net header.s=zoho header.b=fOLzIxik; arc=pass ("zohomail.com:s=zohoarc:i=1"); dmarc=none; spf=pass (aspmx1.migadu.com: domain of "gwl-devel-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="gwl-devel-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -6.10 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=elephly.net header.s=zoho header.b=fOLzIxik; arc=pass ("zohomail.com:s=zohoarc:i=1"); dmarc=none; spf=pass (aspmx1.migadu.com: domain of "gwl-devel-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="gwl-devel-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: CE3B530DF1 X-Spam-Score: -6.10 X-Migadu-Scanner: scn0.migadu.com X-TUID: cKhT1LJapdot Hi again, Olivier Dion writes: >>> + ((first . rest) first) >>> + (_ (raise (condition >>> + (&gwl-package-error >>> + (package-spec (string-append name+version output= ))))))) >>> + output)) >> >> I=E2=80=99d prefer to have this return multiple values instead of a comp= ound >> value. > > With (values ...)? That's what (gnu packages) does I think. I think I missed how you intended for this to work. IIUC you=E2=80=99re le= tting LOOKUP-PACKAGE return a list of a package and an output because that will end up as an argument to PACKAGES->MANIFEST (in (@ (gwl processes) process->script)). PACKAGES->MANIFEST has this docstring: "Return a list of manifest entries, one for each item listed in PACKAGES. Elements of PACKAGES can be either package objects or package/string tuples denoting a specific output of a package." So that=E2=80=99s why you=E2=80=99re making it return a tuple of package/st= ring tuples =E2=80=93 for compatibility with that procedure. My comment about returning multiple values or a record value totally misses your intent. Sorry! Now I get it. > I do think it would be better to wait for (guix inferior) to support > selecting outputs. However, I do need selection of outputs for my use > case right now! Specificaly, I need to have debug symbols of many > packages. The quick hack above does the work for me but I understand > that it would be preferable if (guix inferior) has support for outputs > instead. I understand. So =E2=80=A6 I think we can figure something out that won=E2=80=99t be far = removed from what you proposed. I=E2=80=99d probably split it into smaller procedures, though, to make it a bit more obvious what=E2=80=99s going on. Let=E2=80=99s see the diff again=E2=80=A6 > -(define (lookup-package specification) > +(define (%lookup-package name+version output) > + (list (match (apply lookup-inferior-packages > + (cons (current-guix) (string-split name+version #\= @))) > + ((first . rest) first) > + (_ (raise (condition > + (&gwl-package-error > + (package-spec (string-append name+version output))= ))))) > + output)) > > +(define* (lookup-package specification #:optional (output "out")) > (log-event 'guix (G_ "Looking up package `~a'~%") specification) > - (match (lookup-inferior-packages (current-guix) specification) > - ((first . rest) first) > - (_ (raise (condition > - (&gwl-package-error > - (package-spec specification))))))) > + (match (string-split specification #\:) > + ((name+version sub-drv) (%lookup-package name+version sub-drv)) > + ((name+version) (simple-package (%lookup-package name+version output= ))))) I=E2=80=99m struggling to figure out a cleaner way to do this=E2=80=A6 Why are we processing the specification *and* accept an optional OUTPUT argument? It seems to me that SUB-DRV and OUTPUT *should* be the same, but it=E2=80=99s possible to call LOOKUP-PACKAGE in a way that they differ, which doesn=E2=80=99t make much sense to me. Another thing that bothers me a bit is all that string splitting; once for version, again for the output. The (guix ui) module has PACKAGE-SPECIFICATION->NAME+VERSION+OUTPUT, which is dedicated for this task. It returns multiple values; let=E2=80=99s use LET* from SRFI-71. Wh= at do you think of this? --8<---------------cut here---------------start------------->8--- (import (srfi srfi-71) (define (lookup-package specification) "Look up SPECIFICATION in an inferior and return a matching package. If = the specification declares a specific output return a tuple consisting of the package value and the output. If no matching package is found, raise a &GWL-PACKAGE-ERROR." (log-event 'guix (G_ "Looking up package `~a'~%") specification) (let* ((name version output (package-specification->name+version+output = specification)) (package (match (lookup-inferior-packages (current-guix) name version) ((first . rest) first) (_ (raise (condition (&gwl-package-error (package-spec specification)))))))) (if output (list package output) package))) --8<---------------cut here---------------end--------------->8--- What do you think of that? > (define (valid-package? val) > - (or (package? val) > - (inferior-package? val))) > + (or > + (and (list? val) > + (valid-package? (car val)) > + (string? (cadr val))) > + (package? val) > + (inferior-package? val))) > + I suggest rewriting this whole thing with MATCH so that the structure of VAL becomes apparent. Perhaps something like this? (match ((maybe-package (? string? output)) (valid-package? maybe-package)) (_ (or (package? val) (inferior-package? val)))) > +(define (simple-package pkg) > + (if (list? pkg) (car pkg) pkg)) I still don=E2=80=99t like this :) Not only the implementation but the fact that it appears to be needed. At least implementation-wise I=E2=80=99d pre= fer something like this: (define (just-package maybe-package+output) (match maybe-package+output (((? package? package) (? string? output)) package) ((? package? package) package) (_ (error "what is this?")))) There are a few places where we need to be careful that we=E2=80=99re deali= ng with the right type and that we handle both cases equally well: when a tuple is encountered and when a plain package value is encountered. Ideally we=E2=80=99d also have tests for this. What do you think of all this? --=20 Ricardo