From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: "Bozhidar Batsov" Newsgroups: gmane.emacs.devel Subject: Re: What's the right way to extract a package's version from the header metadata? Date: Wed, 29 Dec 2021 09:54:14 +0200 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=1c2a152edb104abdb6ad325aa3be12c8 Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="8315"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Cyrus-JMAP/3.5.0-alpha0-4525-g8883000b21-fm-20211221.001-g8883000b Cc: Emacs Devel To: "Stefan Monnier" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Dec 29 08:56:25 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1n2Tos-0001w8-T7 for ged-emacs-devel@m.gmane-mx.org; Wed, 29 Dec 2021 08:56:23 +0100 Original-Received: from localhost ([::1]:43272 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n2Toq-0002R2-VS for ged-emacs-devel@m.gmane-mx.org; Wed, 29 Dec 2021 02:56:20 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:48334) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n2TnH-0001Tn-IB for emacs-devel@gnu.org; Wed, 29 Dec 2021 02:54:43 -0500 Original-Received: from out3-smtp.messagingengine.com ([66.111.4.27]:49443) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n2TnF-00008H-85 for emacs-devel@gnu.org; Wed, 29 Dec 2021 02:54:42 -0500 Original-Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 3CD465C009F; Wed, 29 Dec 2021 02:54:37 -0500 (EST) Original-Received: from imap43 ([10.202.2.93]) by compute5.internal (MEProxy); Wed, 29 Dec 2021 02:54:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=batsov.dev; h= mime-version:message-id:in-reply-to:references:date:from:to:cc :subject:content-type; s=fm2; bh=la0yv0yOLibZk736ypLBYj4qU1rBDvP A5TrrE7Ex6BM=; b=nyPanmHTrj/U37D861eHMi6pY2yNGWEGTrldi9Z2b85d6aw A1Vm0AXJsCJIxWjcLSKS0N2f44NiDxwyEXpjyCjD81N7eDOGOHgpQZGBm62c8W6G /4iX7EVK+DBxyeUJbFN7F8cFsi8QxR1P8iQmTJ2owtQHM04WHhM9L0ay8V5lTkqL jYM0JwrKgw1eC472Z5PQjsGEHUY45NSOhWGYbggw17YqElzr118I6LjyqP01sPPh Pk91cnSpXeGUSs9V7rz9aI8BIPagWGVkotS9XsEOeLdegh95p9/MdQijyqIMtgnT BAwuZaKWrfClV8GAt76OO/Zn3rjeY60CaaGFULA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=la0yv0 yOLibZk736ypLBYj4qU1rBDvPA5TrrE7Ex6BM=; b=QCDenZxby8Y+sYmJcX8A4U u52EzqwfXy2kpArWjQzQgObkjeJhcfYAhVOQb626S/pDWb+RG7bTPSbC+50c8Rzt +JQ00E4COE58qKg/FdpTrackvCfsxWSnbme4SBnRSjlzB2lv+G3q1T801NgoNF6P bdV+RMctqs7qPFJ+cX/NMfIkx5aTQiGToFyQYoZdwBTQnIvgQbDaN5Z8BcpzpcZR qpx+lT+Gj/kGrPHykklBHC4yKZN9uQGzK3pnccqU2fSSKO1JaeSbLLKMvbV9XuXg N5s1TxgsvAObGwa4NXY57SruoghAlFBQhqvmsp9UML8K8ReZqWFYSP0ggDmIjxmw == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvuddruddvtddguddugecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvufgtsegrtderreerredtnecuhfhrohhmpedfueho iihhihgurghruceurghtshhovhdfuceosghoiihhihgurghrsegsrghtshhovhdruggvvh eqnecuggftrfgrthhtvghrnhepgedvteefkeekteeilefftdekuddthffffeegtdevhfet feevjefhgfdtkeejieeunecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepsghoiihhihgurghrsegsrghtshhovhdruggvvh X-ME-Proxy: Original-Received: by mailuser.nyi.internal (Postfix, from userid 501) id 05120AC0E90; Wed, 29 Dec 2021 02:54:37 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface In-Reply-To: Received-SPF: pass client-ip=66.111.4.27; envelope-from=bozhidar@batsov.dev; helo=out3-smtp.messagingengine.com X-Spam_score_int: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:283541 Archived-At: --1c2a152edb104abdb6ad325aa3be12c8 Content-Type: text/plain Thanks for the quick response! It would be great indeed if `package-get-version` worked in more cases and we could just consider it the canonical solution the version extraction problem. On Wed, Dec 29, 2021, at 9:42 AM, Stefan Monnier wrote: > > Basically I want to extract the package version from the *Version:* > > header instead of having to duplicate it. I know of > > package-get-package-version, but I assume it won't work for people > > who didn't install my packages via package.el. > > `package-get-version` should work but only if they had the foresight to > put it in a directory whose name ends in "-" or whose name is > just `cider` (i.e. the name of your package) :-( > > The patch below (which I plan to push to `master` soon) should make it > work in other cases as well if the call is in the same file where the > `Version:` can be found. > > > Stefan > > > diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el > index 9b6b5d4dc0d..d477266a7ef 100644 > --- a/lisp/emacs-lisp/package.el > +++ b/lisp/emacs-lisp/package.el > @@ -4077,7 +4077,9 @@ package-get-version > "Return the version number of the package in which this is used. > Assumes it is used from an Elisp file placed inside the top-level directory > of an installed ELPA package. > -The return value is a string (or nil in case we can't find it)." > +The return value is a string (or nil in case we can't find it). > +It works in more cases if the call is in the file which contains > +the `Version:' header." > ;; In a sense, this is a lie, but it does just what we want: precompute > ;; the version at compile time and hardcodes it into the .elc file! > (declare (pure t)) > @@ -4096,6 +4098,7 @@ package-get-version > (let* ((pkgdir (file-name-directory file)) > (pkgname (file-name-nondirectory (directory-file-name pkgdir))) > (mainfile (expand-file-name (concat pkgname ".el") pkgdir))) > + (unless (file-readable-p mainfile) (setq mainfile file)) > (when (file-readable-p mainfile) > (require 'lisp-mnt) > (with-temp-buffer > > --1c2a152edb104abdb6ad325aa3be12c8 Content-Type: text/html Content-Transfer-Encoding: quoted-printable
Thanks for the = quick response! It would be great indeed if  `package-get-version` = worked in more cases and we could just consider it the canonical solutio= n the version extraction problem.

On Wed, = Dec 29, 2021, at 9:42 AM, Stefan Monnier wrote:
> Basically I want to extract th= e package version from the *Version:*
>  header in= stead of having to duplicate it. I know of
>  pack= age-get-package-version, but I assume it won't work for people
=
>  who didn't install my packages via package.el. &nbs= p;

`package-get-version` should work but on= ly if they had the foresight to
put it in a directory whos= e name ends in "-<version>" or whose name is
just `c= ider` (i.e. the name of your package) :-(

T= he patch below (which I plan to push to `master` soon) should make it
work in other cases as well if the call is in the same file = where the
`Version:` can be found.


        Stefan


diff --git a/lisp/emacs-lisp/= package.el b/lisp/emacs-lisp/package.el
index 9b6b5d4dc0d.= .d477266a7ef 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -4077,7 +4077= ,9 @@ package-get-version
   "Return the version= number of the package in which this is used.
Assumes it i= s used from an Elisp file placed inside the top-level directory
of an installed ELPA package.
-The return value is a= string (or nil in case we can't find it)."
+The return va= lue is a string (or nil in case we can't find it).
+It wor= ks in more cases if the call is in the file which contains
+the `Version:' header."
   ;; In a sense, this= is a lie, but it does just what we want: precompute
 = ;  ;; the version at compile time and hardcodes it into the .elc fi= le!
   (declare (pure t))
@@ -4096= ,6 +4098,7 @@ package-get-version
    =    (let* ((pkgdir (file-name-directory file))
&n= bsp;           &n= bsp; (pkgname (file-name-nondirectory (directory-file-name pkgdir)))
=
          &= nbsp;   (mainfile (expand-file-name (concat pkgname ".el") pkg= dir)))
+        (unless= (file-readable-p mainfile) (setq mainfile file))
 &n= bsp;       (when (file-readable-p mainfile= )
         &n= bsp; (require 'lisp-mnt)
     &nb= sp;     (with-temp-buffer



--1c2a152edb104abdb6ad325aa3be12c8--