unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#53885: Autoload package-installed-p
@ 2022-02-08 23:55 Corwin Brust
  2022-02-09  0:05 ` bug#53885: 28.0.51 [PATCH] " Corwin Brust
  2022-02-09  5:39 ` bug#53885: " Corwin Brust
  0 siblings, 2 replies; 24+ messages in thread
From: Corwin Brust @ 2022-02-08 23:55 UTC (permalink / raw)
  To: 53885

Commentary:

If the change is accpted, please consider fixing this for emacs-28.
The reproducer represents a common use-case, e.g. see bug #31397.
Moverover, it is a one-line change unlikely to affect anything aside
this and similar use-cases.

I will submit a patch as soon as I have a BugID from the tracker.
Although this change is rather trivial I need to practice this
process.

Reproducer:

NOTE: Make sure you have a folder beneth your home directory called
"elpa" and that it is empty.

Launch emacs -Q
Insert and evaluate:

(progn
  (setq package-user-dir "~/elpa")
  (setq package-archives
'(("MELPA" .
   "https://melpa.org/packages/")))
  (require 'package)
  (unless (package-installed-p 'use-package)
    (package-install 'use-package)))

Expected result:

 Packages are installed under ~/elpa

Actual Result:

Debugger entered--Lisp error: (void-function package-installed-p)
  (package-installed-p 'use-package)
  (if (package-installed-p 'use-package) nil (package-install 'use-package))
  (progn (if (package-installed-p 'use-package) nil (package-install
'use-package)))
  elisp--eval-last-sexp(nil)
  eval-last-sexp(nil)
  funcall-interactively(eval-last-sexp nil)
  command-execute(eval-last-sexp)

Work-around:

(progn
  (setq package-user-dir "~/elpa")
  (setq package-archives
'(("MELPA" .
   "https://melpa.org/packages/")))
  (require 'package) ;; workaround
  (unless (package-installed-p 'use-package)
    (package-install 'use-package)))

--

In GNU Emacs 28.0.91 (build 6, x86_64-w64-mingw32)
 of 2022-02-05 built on AVALON
Repository revision: 821c240075e3b850a61207d18d520126292421ce
Repository branch: emacs-28-nt-dist-build
Windowing system distributor 'Microsoft Corp.', version 10.0.19043
System Description: Microsoft Windows 10 Home (v10.0.2009.19043.1503)

Configured using:
 'configure --with-json --without-dbus --with-native-compilation
 --without-compress-install CFLAGS=-O2'

Configured features:
ACL GIF GMP GNUTLS HARFBUZZ JPEG JSON LCMS2 LIBXML2 MODULES NATIVE_COMP
NOTIFY W32NOTIFY PDUMPER PNG RSVG SOUND THREADS TIFF TOOLKIT_SCROLL_BARS
XPM ZLIB

Important settings:
  value of $LANG: ENU
  locale-coding-system: cp1252

Major mode: Lisp Interaction

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message rmc puny dired dired-loaddefs
rfc822 mml mml-sec epa derived epg rfc6068 epg-config gnus-util rmail
rmail-loaddefs auth-source cl-seq eieio eieio-core cl-macs
eieio-loaddefs password-cache json map text-property-search seq byte-opt
gv bytecomp byte-compile cconv mm-decode mm-bodies mm-encode mail-parse
rfc2231 mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045
ietf-drums mm-util mail-prsvr mail-utils help-fns radix-tree cl-print
debug backtrace help-mode find-func time-date subr-x cl-loaddefs cl-lib
iso-transl tooltip eldoc paren electric uniquify ediff-hook vc-hooks
lisp-float-type elisp-mode mwheel dos-w32 ls-lisp disp-table
term/w32-win w32-win w32-vars term/common-win tool-bar dnd fontset image
regexp-opt fringe tabulated-list replace newcomment text-mode lisp-mode
prog-mode register page tab-bar menu-bar rfn-eshadow isearch easymenu
timer select scroll-bar mouse jit-lock font-lock syntax font-core
term/tty-colors frame minibuffer cl-generic cham georgian utf-8-lang
misc-lang vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms
cp51932 hebrew greek romanian slovak czech european ethiopic indian
cyrillic chinese composite emoji-zwj charscript charprop case-table
epa-hook jka-cmpr-hook help simple abbrev obarray cl-preloaded nadvice
button loaddefs faces cus-face macroexp files window text-properties
overlay sha1 md5 base64 format env code-pages mule custom widget
hashtable-print-readable backquote threads w32notify w32 lcms2 multi-tty
make-network-process native-compile emacs)

Memory information:
((conses 16 78996 5653)
 (symbols 48 7157 0)
 (strings 32 22876 2110)
 (string-bytes 1 755191)
 (vectors 16 14673)
 (vector-slots 8 308167 12600)
 (floats 8 30 232)
 (intervals 56 376 0)
 (buffers 992 11))





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

* bug#53885: 28.0.51 [PATCH] Autoload package-installed-p
  2022-02-08 23:55 bug#53885: Autoload package-installed-p Corwin Brust
@ 2022-02-09  0:05 ` Corwin Brust
  2022-02-09 13:37   ` Eli Zaretskii
  2022-02-09  5:39 ` bug#53885: " Corwin Brust
  1 sibling, 1 reply; 24+ messages in thread
From: Corwin Brust @ 2022-02-09  0:05 UTC (permalink / raw)
  To: 53885, Eli Zaretskii

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

On Tue, Feb 8, 2022 at 5:56 PM Corwin Brust <corwin@bru.st> wrote:
>
> Commentary:
>
> If the change is accpted, please consider fixing this for emacs-28.
> The reproducer represents a common use-case, e.g. see bug #31397.
> Moverover, it is a one-line change unlikely to affect anything aside
> this and similar use-cases.
>

Eli,

Would this be okay for the release branch or should I check if changes
are needed to rebase against master?  Also, hould this receive a NEWS
entry?

> I will submit a patch as soon as I have a BugID from the tracker.
> Although this change is rather trivial I need to practice this
> process.
>

Now attached. TIA for tips and corrections.

[-- Attachment #2: autoload_package-installed-p.patch --]
[-- Type: application/octet-stream, Size: 832 bytes --]

commit 8317de586b6dc02cd7a82d4469dda4b3cedba7a3
Author: Corwin Brust <corwin@bru.st>
Date:   Tue Feb 8 17:48:14 2022 -0600

    Autoload package-installed-p
    
    * lisp/emacs-lisp/package.el (package-installed-p): Add autoload
    cookie. (bug#53885)

diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index 7679ba2fae..4aad58ed6f 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -2072,6 +2072,7 @@ package-install-from-archive
                                                  package-alist))))
                  (setf (package-desc-signed (car pkg-descs)) t))))))))))
 
+;;;###autoload
 (defun package-installed-p (package &optional min-version)
   "Return non-nil if PACKAGE, of MIN-VERSION or newer, is installed.
 If PACKAGE is a symbol, it is the package name and MIN-VERSION

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

* bug#53885: Autoload package-installed-p
  2022-02-08 23:55 bug#53885: Autoload package-installed-p Corwin Brust
  2022-02-09  0:05 ` bug#53885: 28.0.51 [PATCH] " Corwin Brust
@ 2022-02-09  5:39 ` Corwin Brust
  2022-02-09 14:39   ` Augusto Stoffel
  1 sibling, 1 reply; 24+ messages in thread
From: Corwin Brust @ 2022-02-09  5:39 UTC (permalink / raw)
  To: 53885

retitle 53885 28.0.91 [PATCH] Autoload package-installed-p
thanks

I inadvertently included an explicit call to `require' in the
reproducer, which functions as a work-around for this (IMO) missing
autoload. Sorry for any confusion caused.

>
> Reproducer:
>
> NOTE: Make sure you have a folder beneth your home directory called
> "elpa" and that it is empty.
>
> Launch emacs -Q
> Insert and evaluate:

Corrected reproducer:

(progn
  (setq package-user-dir "~/elpa")
  (setq package-archives
    '(("MELPA" .
    "https://melpa.org/packages/")))
  (unless (package-installed-p 'use-package)
    (package-install 'use-package)))





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

* bug#53885: 28.0.51 [PATCH] Autoload package-installed-p
  2022-02-09  0:05 ` bug#53885: 28.0.51 [PATCH] " Corwin Brust
@ 2022-02-09 13:37   ` Eli Zaretskii
  2022-02-09 20:16     ` Lars Ingebrigtsen
  0 siblings, 1 reply; 24+ messages in thread
From: Eli Zaretskii @ 2022-02-09 13:37 UTC (permalink / raw)
  To: Corwin Brust, Lars Ingebrigtsen; +Cc: 53885

> From: Corwin Brust <corwin@bru.st>
> Date: Tue, 8 Feb 2022 18:05:45 -0600
> 
> > Commentary:
> >
> > If the change is accpted, please consider fixing this for emacs-28.
> > The reproducer represents a common use-case, e.g. see bug #31397.
> > Moverover, it is a one-line change unlikely to affect anything aside
> > this and similar use-cases.
> >
> 
> Eli,
> 
> Would this be okay for the release branch or should I check if changes
> are needed to rebase against master?  Also, hould this receive a NEWS
> entry?
> 
> > I will submit a patch as soon as I have a BugID from the tracker.
> > Although this change is rather trivial I need to practice this
> > process.
> >
> 
> Now attached. TIA for tips and corrections.

It's not really a bugfix, it's an enhancement.  Not sure if it's
important enough for the release branch.  But it's quite simple and
probably safe.  Lars, WDYT?

(No need for a NEWS entry.)





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

* bug#53885: Autoload package-installed-p
  2022-02-09  5:39 ` bug#53885: " Corwin Brust
@ 2022-02-09 14:39   ` Augusto Stoffel
  2022-02-09 15:39     ` Corwin Brust
  0 siblings, 1 reply; 24+ messages in thread
From: Augusto Stoffel @ 2022-02-09 14:39 UTC (permalink / raw)
  To: Corwin Brust; +Cc: Lars Ingebrigtsen, 53885

On Tue,  8 Feb 2022 at 23:39, Corwin Brust <corwin@bru.st> wrote:

> Corrected reproducer:
>
> (progn
>   (setq package-user-dir "~/elpa")
>   (setq package-archives
>     '(("MELPA" .
>     "https://melpa.org/packages/")))
>   (unless (package-installed-p 'use-package)
>     (package-install 'use-package)))

By the way, there are two issues with this code snippet.  First, you
should call '(package-refresh-contents)' to make sure you have the
package list from MELPA.

Second, and more subtly, calling package install during init time
doesn't add the package to the list of selected packages, so
'use-package' would be subject to removal by 'package-autoremove'.  To
fix this, something like

    (add-hook 'after-init-hook
              (lambda () (package--update-selected-packages '(use-package) nil)))

is needed.

I think a more user-friendly 'package-ensure-installed' function is in
order here.  I believe the use-package package provides some
functionality for this, but there is no good built-in equivalent (which
is needed even by use-package users).





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

* bug#53885: Autoload package-installed-p
  2022-02-09 14:39   ` Augusto Stoffel
@ 2022-02-09 15:39     ` Corwin Brust
  2022-02-10  8:42       ` Augusto Stoffel
  0 siblings, 1 reply; 24+ messages in thread
From: Corwin Brust @ 2022-02-09 15:39 UTC (permalink / raw)
  To: Augusto Stoffel; +Cc: Lars Ingebrigtsen, 53885

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

Hi Augusto!

On Wed, Feb 9, 2022, 08:39 Augusto Stoffel <arstoffel@gmail.com> wrote:

>
> By the way, there are two issues with this code snippet.  First, you
> should call '(package-refresh-contents)' to make sure you have the
> package list from MELPA.
>

I believe this was changed with the implementation of "early-init".  We
don't need to expressly call `package-refresh-contents' since Emacs 27, see:
https://github.com/emacs-mirror/emacs/blob/master/etc/NEWS.27#L227



> 'use-package' would be subject to removal by 'package-autoremove'.  To
> fix this, something like
>
>     (add-hook 'after-init-hook
>               (lambda () (package--update-selected-packages '(use-package)
> nil)))
>
> is needed.
>

I wasn't aware of this idiosyncrasy. I will look at package.el further
FTR, in my own configuration I expressly set-up package-selected-packages.

In any case, this bug report stems from a Reddit user's perception of
breakage with the Emacs 28 pre-release binaries recently added to alpha.  I
simply created a minimal reproducer from that person's use/expectations.

Do you agree the (corrected) reproducer given should be sufficient to
demonstrate the change provided by adding the autoload, if the patch is
applied?

As things stand presently, I'm having trouble thinking of use-cases for
package-installed-p that would not start with (require 'package).


> I think a more user-friendly 'package-ensure-installed' function is in
> order here.  I believe the use-package package provides some
> functionality for this, but there is no good built-in equivalent (which
> is needed even by use-package users).
>

I love this idea.  Would you be interested to open a new bug report for
this feature request, perhaps offering a patch if you are so inclined?

FWIW, I agree that ,if/when something more robust is added expressly to
support the batch installation of packages, the need for this autoload (and
perhaps all user-facing use-cases for package-installed-p) may be greatly
reduced.

That said, it's not clear to me whether general consensus will be to
support a "default automation" function (or functions) for this, or that
what we have is "enough" for each of us to do things as we wish.  It might
make sense to open a discussion on the development list to discuss this
potential improvement.

Finally, in case it may help, here is a formula I have often used to
'bootstrap' a batch install of packages:

(setq package-selected-packages '(foo bar baz))
(mapc (lambda(pkg) (when (not (require pkg nil t) (package-install pkg))
package-selected-packages)

For myself, I'm not using `package-autoremove'.  I typically remove
(actually rename, usually) my ELPA folder and then relaunch Emacs.  My
configuration (just like the user on behalf of whom I reported this "bug"),
will then install the features I'm (still) using. I'm glad you are watching
out for people who do use the auto-remove package feature.

Regards,
Corwin

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

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

* bug#53885: 28.0.51 [PATCH] Autoload package-installed-p
  2022-02-09 13:37   ` Eli Zaretskii
@ 2022-02-09 20:16     ` Lars Ingebrigtsen
  2022-02-09 23:58       ` Corwin Brust
  0 siblings, 1 reply; 24+ messages in thread
From: Lars Ingebrigtsen @ 2022-02-09 20:16 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Corwin Brust, 53885

Eli Zaretskii <eliz@gnu.org> writes:

> It's not really a bugfix, it's an enhancement.  Not sure if it's
> important enough for the release branch.  But it's quite simple and
> probably safe.  Lars, WDYT?

It should be safe for the release branch, so installing it is fine by
me, but I didn't really understand the use case.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





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

* bug#53885: 28.0.51 [PATCH] Autoload package-installed-p
  2022-02-09 20:16     ` Lars Ingebrigtsen
@ 2022-02-09 23:58       ` Corwin Brust
  2022-02-10  6:10         ` Eli Zaretskii
  0 siblings, 1 reply; 24+ messages in thread
From: Corwin Brust @ 2022-02-09 23:58 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 53885

On Wed, Feb 9, 2022 at 2:16 PM Lars Ingebrigtsen <larsi@gnus.org> wrote:
>
> It should be safe for the release branch, so installing it is fine by
> me, but I didn't really understand the use case.

Sorry I failed in making the case for users clear.

The primary use-case here is "repeatable configuration", especially
bootstrapping `use-package'.

By "repeatable configuration" we mean, we get the same setup each time
we start Emacs, even when launching for the first time on a new host.

The use package feature provides an "ensure" capability that is well
suited to this job.

  (use-package 'foo :ensure t)

This appears widely used, especially to create literate Emacs configurations.

For this to work, however, "bootstrapping" (installing use-package via
Emacs core features) is needed.  The reproducer I gave shows one way
of bootstrapping use-package. Considering the similarity of my
reproducer to the recipe in #31397, I think it is a fairly common
approach and has been for some years.





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

* bug#53885: 28.0.51 [PATCH] Autoload package-installed-p
  2022-02-09 23:58       ` Corwin Brust
@ 2022-02-10  6:10         ` Eli Zaretskii
  2022-02-10  6:45           ` Lars Ingebrigtsen
  0 siblings, 1 reply; 24+ messages in thread
From: Eli Zaretskii @ 2022-02-10  6:10 UTC (permalink / raw)
  To: Corwin Brust; +Cc: larsi, 53885

> From: Corwin Brust <corwin@bru.st>
> Date: Wed, 9 Feb 2022 17:58:25 -0600
> Cc: Eli Zaretskii <eliz@gnu.org>, 53885@debbugs.gnu.org
> 
> On Wed, Feb 9, 2022 at 2:16 PM Lars Ingebrigtsen <larsi@gnus.org> wrote:
> >
> > It should be safe for the release branch, so installing it is fine by
> > me, but I didn't really understand the use case.
> 
> Sorry I failed in making the case for users clear.
> 
> The primary use-case here is "repeatable configuration", especially
> bootstrapping `use-package'.
> 
> By "repeatable configuration" we mean, we get the same setup each time
> we start Emacs, even when launching for the first time on a new host.
> 
> The use package feature provides an "ensure" capability that is well
> suited to this job.
> 
>   (use-package 'foo :ensure t)
> 
> This appears widely used, especially to create literate Emacs configurations.
> 
> For this to work, however, "bootstrapping" (installing use-package via
> Emacs core features) is needed.  The reproducer I gave shows one way
> of bootstrapping use-package. Considering the similarity of my
> reproducer to the recipe in #31397, I think it is a fairly common
> approach and has been for some years.

Thanks, but I don't think I understand the relevance, probably because
I don't use use-package.  Why do you need package-installed-p to be
autoloaded in this scenario, and why cannot use-package do that by
itself?





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

* bug#53885: 28.0.51 [PATCH] Autoload package-installed-p
  2022-02-10  6:10         ` Eli Zaretskii
@ 2022-02-10  6:45           ` Lars Ingebrigtsen
  2022-02-10  7:21             ` Corwin Brust
  0 siblings, 1 reply; 24+ messages in thread
From: Lars Ingebrigtsen @ 2022-02-10  6:45 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Corwin Brust, 53885

Eli Zaretskii <eliz@gnu.org> writes:

> Thanks, but I don't think I understand the relevance, probably because
> I don't use use-package.  Why do you need package-installed-p to be
> autoloaded in this scenario, and why cannot use-package do that by
> itself?

Yes, that's the puzzling thing.  But I've never used use-package
myself -- I assumed that it was a framework built around package.el, but
perhaps it's not related to package.el at all?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





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

* bug#53885: 28.0.51 [PATCH] Autoload package-installed-p
  2022-02-10  6:45           ` Lars Ingebrigtsen
@ 2022-02-10  7:21             ` Corwin Brust
  2022-02-10  7:57               ` Eli Zaretskii
  2022-02-10  8:41               ` Lars Ingebrigtsen
  0 siblings, 2 replies; 24+ messages in thread
From: Corwin Brust @ 2022-02-10  7:21 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 53885

On Thu, Feb 10, 2022 at 12:45 AM Lars Ingebrigtsen <larsi@gnus.org> wrote:
>
> Eli Zaretskii <eliz@gnu.org> writes:
>
> > Thanks, but I don't think I understand the relevance, probably because
> > I don't use use-package.  Why do you need package-installed-p to be
> > autoloaded in this scenario, and why cannot use-package do that by
> > itself?
>
> Yes, that's the puzzling thing.  But I've never used use-package
> myself -- I assumed that it was a framework built around package.el, but
> perhaps it's not related to package.el at all?
>

I'm sure I follow the logic here.  If use-package isn't installed, how
does it matter what relationship it may have to package.el?

That said, one can replace `use-package' with any feature not present
in Emacs as shipped.

Perhaps the use-case is more generally expressed as such:

I would like to have my init scripts automatically install a package
that isn't available "out of the box", but only if that feature hasn't
already been installed.

As things presently stand, `package-installed-p' is nearly perfect for
this, however one must take care to ensure package.el has been
manually loaded before calling it, in order to avoid Emacs raising the
error shown in the original report.





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

* bug#53885: 28.0.51 [PATCH] Autoload package-installed-p
  2022-02-10  7:21             ` Corwin Brust
@ 2022-02-10  7:57               ` Eli Zaretskii
  2022-02-10  8:09                 ` Corwin Brust
  2022-02-10  8:41               ` Lars Ingebrigtsen
  1 sibling, 1 reply; 24+ messages in thread
From: Eli Zaretskii @ 2022-02-10  7:57 UTC (permalink / raw)
  To: Corwin Brust; +Cc: larsi, 53885

> From: Corwin Brust <corwin@bru.st>
> Date: Thu, 10 Feb 2022 01:21:59 -0600
> Cc: Eli Zaretskii <eliz@gnu.org>, 53885@debbugs.gnu.org
> 
> On Thu, Feb 10, 2022 at 12:45 AM Lars Ingebrigtsen <larsi@gnus.org> wrote:
> >
> > Eli Zaretskii <eliz@gnu.org> writes:
> >
> > > Thanks, but I don't think I understand the relevance, probably because
> > > I don't use use-package.  Why do you need package-installed-p to be
> > > autoloaded in this scenario, and why cannot use-package do that by
> > > itself?
> >
> > Yes, that's the puzzling thing.  But I've never used use-package
> > myself -- I assumed that it was a framework built around package.el, but
> > perhaps it's not related to package.el at all?
> >
> 
> I'm sure I follow the logic here.  If use-package isn't installed, how
> does it matter what relationship it may have to package.el?
> 
> That said, one can replace `use-package' with any feature not present
> in Emacs as shipped.
> 
> Perhaps the use-case is more generally expressed as such:
> 
> I would like to have my init scripts automatically install a package
> that isn't available "out of the box", but only if that feature hasn't
> already been installed.
> 
> As things presently stand, `package-installed-p' is nearly perfect for
> this, however one must take care to ensure package.el has been
> manually loaded before calling it, in order to avoid Emacs raising the
> error shown in the original report.

Now I'm confused: which code calls package-installed-p in the
scenarios you have in mind?  I thought it was use-package, but you
seem to say that's not the case?





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

* bug#53885: 28.0.51 [PATCH] Autoload package-installed-p
  2022-02-10  7:57               ` Eli Zaretskii
@ 2022-02-10  8:09                 ` Corwin Brust
  2022-02-10  8:18                   ` Eli Zaretskii
  0 siblings, 1 reply; 24+ messages in thread
From: Corwin Brust @ 2022-02-10  8:09 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Lars Ingebrigtsen, 53885

On Thu, Feb 10, 2022 at 1:57 AM Eli Zaretskii <eliz@gnu.org> wrote:
>
> Now I'm confused: which code calls package-installed-p in the
> scenarios you have in mind?  I thought it was use-package, but you
> seem to say that's not the case?

The user's Emacs configuration, e.g. init.el





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

* bug#53885: 28.0.51 [PATCH] Autoload package-installed-p
  2022-02-10  8:09                 ` Corwin Brust
@ 2022-02-10  8:18                   ` Eli Zaretskii
  0 siblings, 0 replies; 24+ messages in thread
From: Eli Zaretskii @ 2022-02-10  8:18 UTC (permalink / raw)
  To: Corwin Brust; +Cc: larsi, 53885

> From: Corwin Brust <corwin@bru.st>
> Date: Thu, 10 Feb 2022 02:09:34 -0600
> Cc: Lars Ingebrigtsen <larsi@gnus.org>, 53885@debbugs.gnu.org
> 
> On Thu, Feb 10, 2022 at 1:57 AM Eli Zaretskii <eliz@gnu.org> wrote:
> >
> > Now I'm confused: which code calls package-installed-p in the
> > scenarios you have in mind?  I thought it was use-package, but you
> > seem to say that's not the case?
> 
> The user's Emacs configuration, e.g. init.el

Why do users do that without making sure the relevant feature is
loaded?  And what makes package-installed-p special in this case?





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

* bug#53885: 28.0.51 [PATCH] Autoload package-installed-p
  2022-02-10  7:21             ` Corwin Brust
  2022-02-10  7:57               ` Eli Zaretskii
@ 2022-02-10  8:41               ` Lars Ingebrigtsen
  2022-02-10  8:49                 ` Corwin Brust
  2022-02-10 12:04                 ` Eli Zaretskii
  1 sibling, 2 replies; 24+ messages in thread
From: Lars Ingebrigtsen @ 2022-02-10  8:41 UTC (permalink / raw)
  To: Corwin Brust; +Cc: 53885

Corwin Brust <corwin@bru.st> writes:

> I would like to have my init scripts automatically install a package
> that isn't available "out of the box", but only if that feature hasn't
> already been installed.
>
> As things presently stand, `package-installed-p' is nearly perfect for
> this, however one must take care to ensure package.el has been
> manually loaded before calling it, in order to avoid Emacs raising the
> error shown in the original report.

Oh, I see -- this has nothing to do with use-package, and you could have
used some other package manager.  You just want to be able to check
whether a package is installed in .emacs (without saying `require
'package') which seems reasonable to me.

However, this comes firmly under "new functionality" and not "bug fix",
so I'm not sure we should put it in emacs-28 at this point, no matter
how innocuous it looks like.  But if Eli thinks otherwise, I won't
object.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





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

* bug#53885: Autoload package-installed-p
  2022-02-09 15:39     ` Corwin Brust
@ 2022-02-10  8:42       ` Augusto Stoffel
  2022-02-10  8:59         ` Philip Kaludercic
  2022-02-10  9:23         ` Corwin Brust
  0 siblings, 2 replies; 24+ messages in thread
From: Augusto Stoffel @ 2022-02-10  8:42 UTC (permalink / raw)
  To: Corwin Brust, Philip Kaludercic; +Cc: Lars Ingebrigtsen, 53885

Hi Corwin,

On Wed,  9 Feb 2022 at 09:39, Corwin Brust <corwin@bru.st> wrote:

> Hi Augusto!
>
> On Wed, Feb 9, 2022, 08:39 Augusto Stoffel <arstoffel@gmail.com> wrote:
>
>  By the way, there are two issues with this code snippet.  First, you
>  should call '(package-refresh-contents)' to make sure you have the
>  package list from MELPA.
>
> I believe this was changed with the implementation of "early-init".  We don't need to expressly call
> `package-refresh-contents' since Emacs 27, see:
> https://github.com/emacs-mirror/emacs/blob/master/etc/NEWS.27#L227

This is a different matter.  What I was saying is, you need to download
the package list from MELPA before trying to install a missing package.

If you delete ~/.emacs.d/elpa, your configuration as you showed it won't
be able to bootstrap.

>  'use-package' would be subject to removal by 'package-autoremove'.  To
>  fix this, something like
>
>      (add-hook 'after-init-hook
>                (lambda () (package--update-selected-packages '(use-package) nil)))
>
>  is needed.
>
> I wasn't aware of this idiosyncrasy. I will look at package.el further  FTR, in my own configuration I
> expressly set-up package-selected-packages.
>
> In any case, this bug report stems from a Reddit user's perception of breakage with the Emacs 28
> pre-release binaries recently added to alpha.  I simply created a minimal reproducer from that
> person's use/expectations.
>
> Do you agree the (corrected) reproducer given should be sufficient to demonstrate the change
> provided by adding the autoload, if the patch is applied?
>
> As things stand presently, I'm having trouble thinking of use-cases for package-installed-p that
> would not start with (require 'package).
>
>  I think a more user-friendly 'package-ensure-installed' function is in
>  order here.  I believe the use-package package provides some
>  functionality for this, but there is no good built-in equivalent (which
>  is needed even by use-package users).
>
> I love this idea.  Would you be interested to open a new bug report for this feature request, perhaps
> offering a patch if you are so inclined?

I recall Philip giving a similar suggestion on the mailing list but I
can't find that thread anymore.  So I added him to this message.

> FWIW, I agree that ,if/when something more robust is added expressly to support the batch
> installation of packages, the need for this autoload (and perhaps all user-facing use-cases for
> package-installed-p) may be greatly reduced.

Autoloading 'package-installed-p' wouldn't cause any harm, but it also
doesn't solve any problems, so why bother?

> That said, it's not clear to me whether general consensus will be to support a "default automation"
> function (or functions) for this, or that what we have is "enough" for each of us to do things as we
> wish.  It might make sense to open a discussion on the development list to discuss this potential
> improvement.
>
> Finally, in case it may help, here is a formula I have often used to 'bootstrap' a batch install of
> packages:
>
> (setq package-selected-packages '(foo bar baz))
> (mapc (lambda(pkg) (when (not (require pkg nil t) (package-install pkg))
> package-selected-packages)
>
> For myself, I'm not using `package-autoremove'.  I typically remove (actually rename, usually) my
> ELPA folder and then relaunch Emacs.  My configuration (just like the user on behalf of whom I
> reported this "bug"), will then install the features I'm (still) using. I'm glad you are watching out for
> people who do use the auto-remove package feature.
>
> Regards,
> Corwin





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

* bug#53885: 28.0.51 [PATCH] Autoload package-installed-p
  2022-02-10  8:41               ` Lars Ingebrigtsen
@ 2022-02-10  8:49                 ` Corwin Brust
  2022-02-10 12:04                 ` Eli Zaretskii
  1 sibling, 0 replies; 24+ messages in thread
From: Corwin Brust @ 2022-02-10  8:49 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 53885

On Thu, Feb 10, 2022 at 2:41 AM Lars Ingebrigtsen <larsi@gnus.org> wrote:
>
> Corwin Brust <corwin@bru.st> writes:
>
> > I would like to have my init scripts automatically install a package
> > that isn't available "out of the box", but only if that feature hasn't
> > already been installed.
> >
> > As things presently stand, `package-installed-p' is nearly perfect for
> > this, however one must take care to ensure package.el has been
> > manually loaded before calling it, in order to avoid Emacs raising the
> > error shown in the original report.
>
> Oh, I see -- this has nothing to do with use-package, and you could have
> used some other package manager.  You just want to be able to check
> whether a package is installed in .emacs (without saying `require
> 'package') which seems reasonable to me.

Thanks much.

I've been struggling to reply to Ell's last succinctly, but maybe your
response has helped clarify and thus saved me from that.

Eli, please let me know if you have further what/why questions, otherwise

>
> However, this comes firmly under "new functionality" and not "bug fix",
> so I'm not sure we should put it in emacs-28 at this point, no matter
> how innocuous it looks like.  But if Eli thinks otherwise, I won't
> object.

Fine by me either way.





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

* bug#53885: Autoload package-installed-p
  2022-02-10  8:42       ` Augusto Stoffel
@ 2022-02-10  8:59         ` Philip Kaludercic
  2022-02-10  9:28           ` Augusto Stoffel
  2022-02-10  9:23         ` Corwin Brust
  1 sibling, 1 reply; 24+ messages in thread
From: Philip Kaludercic @ 2022-02-10  8:59 UTC (permalink / raw)
  To: Augusto Stoffel; +Cc: Lars Ingebrigtsen, Corwin Brust, 53885

Augusto Stoffel <arstoffel@gmail.com> writes:

>>  I think a more user-friendly 'package-ensure-installed' function is in
>>  order here.  I believe the use-package package provides some
>>  functionality for this, but there is no good built-in equivalent (which
>>  is needed even by use-package users).
>>
>> I love this idea.  Would you be interested to open a new bug report for this feature request, perhaps
>> offering a patch if you are so inclined?
>
> I recall Philip giving a similar suggestion on the mailing list but I
> can't find that thread anymore.  So I added him to this message.

Sadly I don't remember either, nor what the thread was about, but I
agree that such a function would be useful to have.

-- 
	Philip Kaludercic





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

* bug#53885: Autoload package-installed-p
  2022-02-10  8:42       ` Augusto Stoffel
  2022-02-10  8:59         ` Philip Kaludercic
@ 2022-02-10  9:23         ` Corwin Brust
  2022-02-10  9:30           ` Augusto Stoffel
  1 sibling, 1 reply; 24+ messages in thread
From: Corwin Brust @ 2022-02-10  9:23 UTC (permalink / raw)
  To: Augusto Stoffel; +Cc: Philip Kaludercic, Lars Ingebrigtsen, 53885

On Thu, Feb 10, 2022 at 3:06 AM Augusto Stoffel <arstoffel@gmail.com> wrote:
>
> On Wed,  9 Feb 2022 at 09:39, Corwin Brust <corwin@bru.st> wrote:
>
> > On Wed, Feb 9, 2022, 08:39 Augusto Stoffel <arstoffel@gmail.com> wrote:
> >
> >  By the way, there are two issues with this code snippet.  First, you
> >  should call '(package-refresh-contents)' to make sure you have the
> >  package list from MELPA.
> >
> > I believe this was changed with the implementation of "early-init".  We don't need to expressly call
> > `package-refresh-contents' since Emacs 27, see:
> > https://github.com/emacs-mirror/emacs/blob/master/etc/NEWS.27#L227
>
> This is a different matter.  What I was saying is, you need to download
> the package list from MELPA before trying to install a missing package.

This is taken care of by a call to package-installed-p in the case
where it does not receive a package description as the first argument
and when no min-version is passed, as in my "reproducer".  Or maybe I
still don't understand.

> If you delete ~/.emacs.d/elpa, your configuration as you showed it won't
> be able to bootstrap.

I don't think I called for deleting anything; I just set-up a
non-standard place for the installation of packages.  But I suspect
I'm missing your point.

>
> Autoloading 'package-installed-p' wouldn't cause any harm, but it also
> doesn't solve any problems, so why bother?

Here I don't agree.  Consider:

(when (not (package-installed-p 'foo))
  (package-install-package 'foo))

This seems to DTRT; the package does get installed whereas in the
present world a backtrace is triggered unless we first take care to
load package.el.





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

* bug#53885: Autoload package-installed-p
  2022-02-10  8:59         ` Philip Kaludercic
@ 2022-02-10  9:28           ` Augusto Stoffel
  0 siblings, 0 replies; 24+ messages in thread
From: Augusto Stoffel @ 2022-02-10  9:28 UTC (permalink / raw)
  To: Philip Kaludercic; +Cc: Lars Ingebrigtsen, Corwin Brust, 53885

On Thu, 10 Feb 2022 at 08:59, Philip Kaludercic <philipk@posteo.net> wrote:

> Sadly I don't remember either, nor what the thread was about, but I
> agree that such a function would be useful to have.

IIRC, you suggested adding a file called site-lisp.el which included
some stuff useful in this context.  In general I thought that little
library was a very good idea.





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

* bug#53885: Autoload package-installed-p
  2022-02-10  9:23         ` Corwin Brust
@ 2022-02-10  9:30           ` Augusto Stoffel
  0 siblings, 0 replies; 24+ messages in thread
From: Augusto Stoffel @ 2022-02-10  9:30 UTC (permalink / raw)
  To: Corwin Brust; +Cc: Philip Kaludercic, Lars Ingebrigtsen, 53885

On Thu, 10 Feb 2022 at 03:23, Corwin Brust <corwin@bru.st> wrote:

>> If you delete ~/.emacs.d/elpa, your configuration as you showed it won't
>> be able to bootstrap.
>
> I don't think I called for deleting anything; I just set-up a
> non-standard place for the installation of packages.  But I suspect
> I'm missing your point.

I thought your goal was to have Emacs download all the packages you need
if you copy your configuration files to a new computer.  Maybe I
misunderstood.

>> Autoloading 'package-installed-p' wouldn't cause any harm, but it also
>> doesn't solve any problems, so why bother?
>
> Here I don't agree.  Consider:
>
> (when (not (package-installed-p 'foo))
>   (package-install-package 'foo))
>
> This seems to DTRT; the package does get installed whereas in the
> present world a backtrace is triggered unless we first take care to
> load package.el.

The first time you start Emacs, it doesn't have a list of packages from
ELPA et al (and even if you do, it may be out of date), so
'package-install-pakcage' will fail.





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

* bug#53885: 28.0.51 [PATCH] Autoload package-installed-p
  2022-02-10  8:41               ` Lars Ingebrigtsen
  2022-02-10  8:49                 ` Corwin Brust
@ 2022-02-10 12:04                 ` Eli Zaretskii
  2022-02-10 14:54                   ` Corwin Brust
  1 sibling, 1 reply; 24+ messages in thread
From: Eli Zaretskii @ 2022-02-10 12:04 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: corwin, 53885

> From: Lars Ingebrigtsen <larsi@gnus.org>
> Cc: Eli Zaretskii <eliz@gnu.org>,  53885@debbugs.gnu.org
> Date: Thu, 10 Feb 2022 09:41:40 +0100
> 
> Oh, I see -- this has nothing to do with use-package, and you could have
> used some other package manager.  You just want to be able to check
> whether a package is installed in .emacs (without saying `require
> 'package') which seems reasonable to me.
> 
> However, this comes firmly under "new functionality" and not "bug fix",
> so I'm not sure we should put it in emacs-28 at this point, no matter
> how innocuous it looks like.  But if Eli thinks otherwise, I won't
> object.

Those were my thoughts as well, so we agree here.





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

* bug#53885: 28.0.51 [PATCH] Autoload package-installed-p
  2022-02-10 12:04                 ` Eli Zaretskii
@ 2022-02-10 14:54                   ` Corwin Brust
  2022-02-10 17:29                     ` Eli Zaretskii
  0 siblings, 1 reply; 24+ messages in thread
From: Corwin Brust @ 2022-02-10 14:54 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Lars Ingebrigtsen, 53885

On Thu, Feb 10, 2022 at 6:04 AM Eli Zaretskii <eliz@gnu.org> wrote:
>
> > From: Lars Ingebrigtsen <larsi@gnus.org>
> >
> > However, this comes firmly under "new functionality" and not "bug fix",
> > so I'm not sure we should put it in emacs-28 at this point, no matter
> > how innocuous it looks like.  But if Eli thinks otherwise, I won't
> > object.
>
> Those were my thoughts as well, so we agree here.

In that case..

I've confirmed my patch applies cleanly to master.
May I ask one of you to push it and then close this bug report (which
was actually a feature request)?

Thank you.





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

* bug#53885: 28.0.51 [PATCH] Autoload package-installed-p
  2022-02-10 14:54                   ` Corwin Brust
@ 2022-02-10 17:29                     ` Eli Zaretskii
  0 siblings, 0 replies; 24+ messages in thread
From: Eli Zaretskii @ 2022-02-10 17:29 UTC (permalink / raw)
  To: Corwin Brust; +Cc: larsi, 53885-done

> From: Corwin Brust <corwin@bru.st>
> Date: Thu, 10 Feb 2022 08:54:28 -0600
> Cc: Lars Ingebrigtsen <larsi@gnus.org>, 53885@debbugs.gnu.org
> 
> I've confirmed my patch applies cleanly to master.
> May I ask one of you to push it and then close this bug report (which
> was actually a feature request)?

Done, thanks.





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

end of thread, other threads:[~2022-02-10 17:29 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-08 23:55 bug#53885: Autoload package-installed-p Corwin Brust
2022-02-09  0:05 ` bug#53885: 28.0.51 [PATCH] " Corwin Brust
2022-02-09 13:37   ` Eli Zaretskii
2022-02-09 20:16     ` Lars Ingebrigtsen
2022-02-09 23:58       ` Corwin Brust
2022-02-10  6:10         ` Eli Zaretskii
2022-02-10  6:45           ` Lars Ingebrigtsen
2022-02-10  7:21             ` Corwin Brust
2022-02-10  7:57               ` Eli Zaretskii
2022-02-10  8:09                 ` Corwin Brust
2022-02-10  8:18                   ` Eli Zaretskii
2022-02-10  8:41               ` Lars Ingebrigtsen
2022-02-10  8:49                 ` Corwin Brust
2022-02-10 12:04                 ` Eli Zaretskii
2022-02-10 14:54                   ` Corwin Brust
2022-02-10 17:29                     ` Eli Zaretskii
2022-02-09  5:39 ` bug#53885: " Corwin Brust
2022-02-09 14:39   ` Augusto Stoffel
2022-02-09 15:39     ` Corwin Brust
2022-02-10  8:42       ` Augusto Stoffel
2022-02-10  8:59         ` Philip Kaludercic
2022-02-10  9:28           ` Augusto Stoffel
2022-02-10  9:23         ` Corwin Brust
2022-02-10  9:30           ` Augusto Stoffel

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