unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Obtaining the version of an installed package
@ 2021-08-09  8:28 Bozhidar Batsov
  2021-08-09 12:58 ` Stefan Monnier
  0 siblings, 1 reply; 7+ messages in thread
From: Bozhidar Batsov @ 2021-08-09  8:28 UTC (permalink / raw)
  To: Emacs Devel

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

Hey everyone, 

I'm wondering if there's an API for obtaining metadata about installed packages, in particular the version information.
For years I was using this function from pkg-info https://github.com/emacsorphanage/pkg-info/blob/master/pkg-info.el#L65, but I'm wondering if it'd be easy to strip one dependency from my packages. 

I've skimmed over package.el, but I didn't notice anything that does this, that's why I decided to ask on the mailing list as well.
I see there's the function `package-get-descriptor`, but it seems it was added only 7 months ago, so it can't be used in packages that need to support several Emacs versions. Copying it and related functions might work, but I'm hoping to find a more elegant solution. Thanks in advance for your help! 

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Obtaining the version of an installed package
  2021-08-09  8:28 Obtaining the version of an installed package Bozhidar Batsov
@ 2021-08-09 12:58 ` Stefan Monnier
  2021-08-09 14:03   ` Bozhidar Batsov
  0 siblings, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2021-08-09 12:58 UTC (permalink / raw)
  To: Bozhidar Batsov; +Cc: Emacs Devel

> I'm wondering if there's an API for obtaining metadata about installed
> packages, in particular the version information.
> For years I was using this function from pkg-info
> https://github.com/emacsorphanage/pkg-info/blob/master/pkg-info.el#L65, but
> I'm wondering if it'd be easy to strip one dependency from my packages. 

Are you looking for `package-get-version`?


        Stefan




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Obtaining the version of an installed package
  2021-08-09 12:58 ` Stefan Monnier
@ 2021-08-09 14:03   ` Bozhidar Batsov
  2021-08-09 15:35     ` Philip Kaludercic
  2021-08-09 15:39     ` Stefan Monnier
  0 siblings, 2 replies; 7+ messages in thread
From: Bozhidar Batsov @ 2021-08-09 14:03 UTC (permalink / raw)
  To: Emacs Devel

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

I guess that could work, although from what I gathered it operates only on the current package. I was hoping to find something like an API like `(package-get-version 'package-name)`. 

On Mon, Aug 9, 2021, at 3:58 PM, Stefan Monnier wrote:
> > I'm wondering if there's an API for obtaining metadata about installed
> > packages, in particular the version information.
> > For years I was using this function from pkg-info
> > https://github.com/emacsorphanage/pkg-info/blob/master/pkg-info.el#L65, but
> > I'm wondering if it'd be easy to strip one dependency from my packages. 
> 
> Are you looking for `package-get-version`?
> 
> 
>         Stefan
> 
> 
> 

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Obtaining the version of an installed package
  2021-08-09 14:03   ` Bozhidar Batsov
@ 2021-08-09 15:35     ` Philip Kaludercic
  2021-08-09 15:39     ` Stefan Monnier
  1 sibling, 0 replies; 7+ messages in thread
From: Philip Kaludercic @ 2021-08-09 15:35 UTC (permalink / raw)
  To: Bozhidar Batsov; +Cc: Emacs Devel

"Bozhidar Batsov" <bozhidar@batsov.dev> writes:

> I guess that could work, although from what I gathered it operates
> only on the current package. I was hoping to find something like an
> API like `(package-get-version 'package-name)`.

Extracting the code from package-get-version, I would get something
like

        (require 'find-func)
        (require 'lisp-mnt)

        (defun get-library-version (library)
          "Return a version string for LIBRARY."
          (with-temp-buffer
            (insert-file-contents (find-library-name library))
            (or (lm-header "package-version")
                        (lm-header "version"))))

and it seems to work

    (get-library-version "auctex") ;=> "13.0.12"

> On Mon, Aug 9, 2021, at 3:58 PM, Stefan Monnier wrote:
>> > I'm wondering if there's an API for obtaining metadata about installed
>> > packages, in particular the version information.
>> > For years I was using this function from pkg-info
>> > https://github.com/emacsorphanage/pkg-info/blob/master/pkg-info.el#L65, but
>> > I'm wondering if it'd be easy to strip one dependency from my packages. 
>> 
>> Are you looking for `package-get-version`?
>> 
>> 
>>         Stefan
>> 
>> 
>> 

-- 
	Philip Kaludercic



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Obtaining the version of an installed package
  2021-08-09 14:03   ` Bozhidar Batsov
  2021-08-09 15:35     ` Philip Kaludercic
@ 2021-08-09 15:39     ` Stefan Monnier
  2021-08-11  7:15       ` Bozhidar Batsov
  1 sibling, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2021-08-09 15:39 UTC (permalink / raw)
  To: Bozhidar Batsov; +Cc: Emacs Devel

Bozhidar Batsov [2021-08-09 17:03:21] wrote:
> I guess that could work, although from what I gathered it operates only on
> the current package. I was hoping to find something like an API like
> `(package-get-version 'package-name)`.

Ah, no, we don't have such an abstraction.

Currently, you'd have to use the `package--alist` function (whose first
call will take a bit of time to real all the <FOO>-pkg.el files) and
then look inside its return value with `package-desc-<foo>`.

[ That's assuming you're interested in the packages currently installed.
  If you're interested in the packages currently activated, then you
  have that list in `package-activated-list` but that fails to record
  which version has been activated :-(  ]

Patches welcome to add more friendly accessors.

I'm also curious to know the specific context in which you need that
info.  Is it to test at runtime whether some dependency includes
a particular bugfix/feature ?


        Stefan




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Obtaining the version of an installed package
  2021-08-09 15:39     ` Stefan Monnier
@ 2021-08-11  7:15       ` Bozhidar Batsov
  2021-08-11 13:28         ` Stefan Monnier
  0 siblings, 1 reply; 7+ messages in thread
From: Bozhidar Batsov @ 2021-08-11  7:15 UTC (permalink / raw)
  To: Emacs Devel

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

On Mon, Aug 9, 2021, at 6:39 PM, Stefan Monnier wrote:
> Bozhidar Batsov [2021-08-09 17:03:21] wrote:
> > I guess that could work, although from what I gathered it operates only on
> > the current package. I was hoping to find something like an API like
> > `(package-get-version 'package-name)`.
> 
> Ah, no, we don't have such an abstraction.
> 
> Currently, you'd have to use the `package--alist` function (whose first
> call will take a bit of time to real all the <FOO>-pkg.el files) and
> then look inside its return value with `package-desc-<foo>`.

Got it, thanks!

> 
> [ That's assuming you're interested in the packages currently installed.
>   If you're interested in the packages currently activated, then you
>   have that list in `package-activated-list` but that fails to record
>   which version has been activated :-(  ]
> 
> Patches welcome to add more friendly accessors.

Will keep this in mind!

> 
> I'm also curious to know the specific context in which you need that
> info.  Is it to test at runtime whether some dependency includes
> a particular bugfix/feature ?

Yeah, something like this. Probably an overkill and it's not something I really need right now.
What I mostly needed was to extract the installed version of a snapshot package for debug purposes (useful for packages on MELPA to understand how old is the snapshot someone installed there). E.g. I print this in CIDER's REPL:

`;; CIDER 1.2.0snapshot (package: 20210729.521)`

In this case the "real" version 1.2.0-snapshot, but there's also the MELPA package version, that's basically the date the package was built.
The function you mentioned might help with this, probably in combination with lm-version. 

> 
> 
>         Stefan
> 
> 
> 

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Obtaining the version of an installed package
  2021-08-11  7:15       ` Bozhidar Batsov
@ 2021-08-11 13:28         ` Stefan Monnier
  0 siblings, 0 replies; 7+ messages in thread
From: Stefan Monnier @ 2021-08-11 13:28 UTC (permalink / raw)
  To: Bozhidar Batsov; +Cc: Emacs Devel

> Yeah, something like this. Probably an overkill and it's not something I really need right now.
> What I mostly needed was to extract the installed version of a snapshot
> package for debug purposes (useful for packages on MELPA to understand how
> old is the snapshot someone installed there). E.g. I print this in CIDER's
> REPL:
>
> `;; CIDER 1.2.0snapshot (package: 20210729.521)`

This sounds like `package-get-version` would be sufficient since it's an
info printed by CIDER about CIDER rather than about some other package.
Or am I missing something?


        Stefan




^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-08-11 13:28 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-09  8:28 Obtaining the version of an installed package Bozhidar Batsov
2021-08-09 12:58 ` Stefan Monnier
2021-08-09 14:03   ` Bozhidar Batsov
2021-08-09 15:35     ` Philip Kaludercic
2021-08-09 15:39     ` Stefan Monnier
2021-08-11  7:15       ` Bozhidar Batsov
2021-08-11 13:28         ` Stefan Monnier

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).