unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "Bozhidar Batsov" <bozhidar@batsov.dev>
To: "Stefan Monnier" <monnier@iro.umontreal.ca>
Cc: Emacs Devel <emacs-devel@gnu.org>
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	[thread overview]
Message-ID: <f966bdd7-897f-4b1a-ab11-47689385f797@beta.fastmail.com> (raw)
In-Reply-To: <jwv5yr77thx.fsf-monnier+emacs@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 2150 bytes --]

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 "-<version>" 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
> 
> 

[-- Attachment #2: Type: text/html, Size: 3359 bytes --]

  reply	other threads:[~2021-12-29  7:54 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-29  6:29 What's the right way to extract a package's version from the header metadata? Bozhidar Batsov
2021-12-29  7:42 ` Stefan Monnier
2021-12-29  7:54   ` Bozhidar Batsov [this message]
2021-12-29 18:22   ` Thierry Volpiatto
2021-12-29 18:42     ` Bozhidar Batsov
2021-12-30  9:04       ` Thierry Volpiatto
2021-12-30  1:13 ` Jonas Bernoulli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f966bdd7-897f-4b1a-ab11-47689385f797@beta.fastmail.com \
    --to=bozhidar@batsov.dev \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).