Subject: Re: bug#61669: 30.0.50; package-vc: assertion failed when installing Org with package-vc-install-selected-packages (cl-assertion-failed ((package-vc-p pkg) nil))
From: Philip Kaludercic <[email-masked]>
To: Yuu Yin <[email-masked]>
Cc: [email-masked]
Date: Fri, 24 Feb 2023 16:13:33 +0000
List-Id: <debbugs-submit.debbugs.gnu.org>

Yuu Yin <[email-masked]> writes:

> Philip Kaludercic <[email-masked]> writes:
>
>> Could you try applying the following two patches:
>>
>> From 64f44c5fa062a3afdcb9dc589e3078211f05e298 Mon Sep 17 00:00:00 2001
>> From: Philip Kaludercic <[email-masked]>
>> Date: Wed, 22 Feb 2023 15:28:44 +0100
>> Subject: [PATCH 2/2] Avoid reusing :lisp-dir twice in 'package-vc--main-file'
>>
>> * lisp/emacs-lisp/package-vc.el (package-vc--main-file): Just use
>> :lisp-dir from 'package-desc-extras', not 'pkg-spec'.
>>
>> This avoid appending the contents of :lisp-dir twice, in case it is
>> specified both in pkg-spec and pkg-desc.
>> ---
>>  lisp/emacs-lisp/package-vc.el | 1 -
>>  1 file changed, 1 deletion(-)
>>
>> diff --git a/lisp/emacs-lisp/package-vc.el b/lisp/emacs-lisp/package-vc.el
>> index b22823fd706..ea2766b8dc4 100644
>> --- a/lisp/emacs-lisp/package-vc.el
>> +++ b/lisp/emacs-lisp/package-vc.el
>> @@ -309,7 +309,6 @@ package-vc--main-file
>>           (directory (file-name-concat
>>                       (or (package-desc-dir pkg-desc)
>>                           (expand-file-name name package-user-dir))
>> -                     (plist-get pkg-spec :lisp-dir)
>>                       (and-let* ((extras (package-desc-extras pkg-desc)))
>>                         (alist-get :lisp-dir extras))))
>>           (file (or (plist-get pkg-spec :main-file)
>> -- 
>> 2.30.2
>>
>> From 6a06b9ac0ec4da9ddacfcb3c1008dc81c32fe0f1 Mon Sep 17 00:00:00 2001
>> From: Philip Kaludercic <[email-masked]>
>> Date: Wed, 22 Feb 2023 15:23:43 +0100
>> Subject: [PATCH 1/2] Ensure right package-desc-type before installing package
>>
>> * lisp/emacs-lisp/package-vc.el (package-vc--unpack): Move copying
>> code from 'package-vc-install'.
>> (package-vc-install): Remove copying.  (Bug#61669)
>> ---
>>  lisp/emacs-lisp/package-vc.el | 8 +++++---
>>  1 file changed, 5 insertions(+), 3 deletions(-)
>>
>> diff --git a/lisp/emacs-lisp/package-vc.el b/lisp/emacs-lisp/package-vc.el
>> index b753adcb8a0..b22823fd706 100644
>> --- a/lisp/emacs-lisp/package-vc.el
>> +++ b/lisp/emacs-lisp/package-vc.el
>> @@ -615,6 +615,10 @@ package-vc--unpack
>>  how to fetch and build the package.  See `package-vc--archive-spec-alist'
>>  for details.  The optional argument REV specifies a specific revision to
>>  checkout.  This overrides the `:branch' attribute in PKG-SPEC."
>> +  (unless (eq (package-desc-kind pkg-desc) 'vc)
>> +    (let ((copy (copy-package-desc pkg-desc)))
>> +      (setf (package-desc-kind copy) 'vc
>> +            pkg-desc copy)))
>>    (pcase-let* (((map :lisp-dir) pkg-spec)
>>                 (name (package-desc-name pkg-desc))
>>                 (dirname (package-desc-full-name pkg-desc))
>> @@ -826,9 +830,7 @@ package-vc-install
>>         rev)))
>>     ((and-let* ((desc (assoc package package-archive-contents #'string=)))
>>        (package-vc--unpack
>> -       (let ((copy (copy-package-desc (cadr desc))))
>> -         (setf (package-desc-kind copy) 'vc)
>> -         copy)
>> +       (cadr desc)
>>         (or (package-vc--desc->spec (cadr desc))
>>             (and-let* ((extras (package-desc-extras (cadr desc)))
>>                        (url (alist-get :url extras))
>> -- 
>> 2.30.2
>>
>>
>> The issue appears to be that, compared to package-vc-install,
>> package-vc-install-selected-packages did not ensure that the package
>> descriptor was of the right type.  The first patch addresses that.  The
>> second one fixes a bug that this also uncovered, but that is not
>> directly related to your issue.
>>
>
> I applied your patches and they worked for installing Org with that
> package description that uses Org from savannah. I tested with
> Tecosaur's dev branch (https://git.tecosaur.net/tec/org-mode), and it
> worked as well. Also, with these patches GNU Emacs automatically loads
> the Org package which package-vc installed instead of built-in Org which
> is very good (I am mentioning this becasue when I installed Org with
> package-vc-install directly it would not load the pacakge-vc installed
> Org and I had to load Org from `early-init.el'). Thank you for the
> patches!

OK, I'll push these to the emacs-29 then.

> It took a while for installing though, which I think would not be such
> an issue in user experience if it did not block GNU Emacs (could it be
> content for another bug report?).

That is true, the current design is to have the packages install
synchronously.  Introducing asynchronicity into configurations seems
like more of a head-ache than an advantage, considering that the
overhead is mostly negligible unless dealing with a repository the size
of org.

>> Yuu Yin <[email-masked]> writes:
>>
>>> HAPPENED
>>>
>>> Trying to install Org from Savannah/Git with
>>> `package-vc-install-selected-packages` errors with failed assertion.
>>>
>>> ```
>>> (cl-assertion-failed ((package-vc-p pkg) nil))
>>> ```
>>>
>>> In my GNU Emacs installation, pacakge-vc works for installing other
>>> packages from Git repositories, but not Org.
>>>
>>> EXPECTED
>>>
>>> package-vc installs Org successfuly.
>>>
>>> REPRODUCE
>>>
>>> On a non-customized GNU Emacs 30.0.50, eval
>>>
>>> ```
>>> (setq-default debug-on-error t)
>>>
>>> (setq package-vc-selected-packages '((org
>>> 				      :url "https://git.savannah.gnu.org/git/emacs/org-mode.git"
>>> 				      :branch "main"
>>> 				      :lisp-dir "lisp"
>>> 				      :vc-backend Git)))
>>>
>>> (package-vc-install-selected-packages)
>>> ```
>>
>> By the way, is there a reason you manually wrote out the package
>> specification (e.g. to test something)?  As the package is on ELPA, you
>> could have also used the information provided by the archive:
>>
>>     (setq package-vc-selected-packages '((org)))
>>
>
> I was not testing. I wanted to explicitly declare the package
> recipe/description (just like in Straight or Elpaca) to have it
> self-contained in my configuration.  I was not fully conscious how/why
> package-vc uses archives, but it has frustrated me that I have seen
> package-vc doing network requests to e.g. MELPA even when I seem to have
> the package description self-contained (I have MELPA on my package
> archives list because it eases the process of searching for external
> packages and get their Git repo URL from within GNU Emacs by using
> `describe-package'). 

Hmm, my go to recommendation would be that you should set
`package-archives' to nil if you know that you are 1. not interested in
installing packages using the package specifications that the ELPAs
provide and 2. if you know that package-vc is sufficient.

Just to be on the safe-side, I should note that this was never the
intent of package-vc.  If it works this way, that is great, but the main
idea is to have package-vc.el live alongside regular package.el.

>                      Also, in the past I have experienced an issue when
> specifying the revision; if I am able to reproduce it, I will report
> another bug.

OK, please do.

>>> BACKTRACE
>>>
>>> For what it is worth, notice package-vc installs Org in `elpa/org-9.6.1` instead of `elpa/org`.
>>
>> Yes, this makes sense considering that the descriptor version did not
>> indicate that the package was a VC package.
>>
>>> ```
>>> Debugger entered--Lisp error: (cl-assertion-failed ((package-vc-p pkg) nil))
>>>   cl--assertion-failed((package-vc-p pkg))
>>>   package-vc--version(#s(package-desc :name org :version (9 6 1) :summary "Outline-based notes management and organizer" :reqs ((emacs (25 1))) :kind tar :archive "gnu" :dir "/home/yuu/.config/emacsen/bug/elpa/org-9.6.1/" :extras ((:lisp-dir . "lisp") (:lisp-dir . "lisp") (:url . "https://orgmode.org") (:keywords "outlines" "hypermedia" "calendar" "wp") (:maintainer "Bastien Guerry" . "[email-masked]") (:authors ("Carsten Dominik" . "[email-masked]")) (:commit . "630f86dfc42472aafd9a4f305e1965cbe92b2891")) :signed nil))
>>>   package-vc--generate-description-file(#s(package-desc :name org :version (9 6 1) :summary "Outline-based notes management and organizer" :reqs ((emacs (25 1))) :kind tar :archive "gnu" :dir "/home/yuu/.config/emacsen/bug/elpa/org-9.6.1/" :extras ((:lisp-dir . "lisp") (:lisp-dir . "lisp") (:url . "https://orgmode.org") (:keywords "outlines" "hypermedia" "calendar" "wp") (:maintainer "Bastien Guerry" . "[email-masked]") (:authors ("Carsten Dominik" . "[email-masked]")) (:commit . "630f86dfc42472aafd9a4f305e1965cbe92b2891")) :signed nil) "/home/yuu/.config/emacsen/bug/elpa/org-9.6.1/org-pkg.el")
>>>   package-vc--unpack-1(#s(package-desc :name org :version (9 6 1) :summary "Outline-based notes management and organizer" :reqs ((emacs (25 1))) :kind tar :archive "gnu" :dir "/home/yuu/.config/emacsen/bug/elpa/org-9.6.1/" :extras ((:lisp-dir . "lisp") (:lisp-dir . "lisp") (:url . "https://orgmode.org") (:keywords "outlines" "hypermedia" "calendar" "wp") (:maintainer "Bastien Guerry" . "[email-masked]") (:authors ("Carsten Dominik" . "[email-masked]")) (:commit . "630f86dfc42472aafd9a4f305e1965cbe92b2891")) :signed nil) "/home/yuu/.config/emacsen/bug/elpa/org-9.6.1/")
>>>   package-vc--unpack(#s(package-desc :name org :version (9 6 1) :summary "Outline-based notes management and organizer" :reqs ((emacs (25 1))) :kind tar :archive "gnu" :dir "/home/yuu/.config/emacsen/bug/elpa/org-9.6.1/" :extras ((:lisp-dir . "lisp") (:lisp-dir . "lisp") (:url . "https://orgmode.org") (:keywords "outlines" "hypermedia" "calendar" "wp") (:maintainer "Bastien Guerry" . "[email-masked]") (:authors ("Carsten Dominik" . "[email-masked]")) (:commit . "630f86dfc42472aafd9a4f305e1965cbe92b2891")) :signed nil) (:url "https://git.savannah.gnu.org/git/emacs/org-mode.git" :branch "main" :lisp-dir "lisp" :vc-backend Git))
>>>   package-vc-install-selected-packages()
>>>   elisp--eval-last-sexp(nil)
>>>   eval-last-sexp(nil)
>>>   funcall-interactively(eval-last-sexp nil)
>>>   command-execute(eval-last-sexp)
>>>   recursive-edit()
>>>   debug(error (cl-assertion-failed ((package-vc-p pkg) nil)))
>>>   cl--assertion-failed((package-vc-p pkg))
>>>   package-vc--version(#s(package-desc :name org :version (9 6 1) :summary "Outline-based notes management and organizer" :reqs ((emacs (25 1))) :kind tar :archive "gnu" :dir "/home/yuu/.config/emacsen/bug/elpa/org-9.6.1/" :extras ((:lisp-dir . "lisp") (:lisp-dir . "lisp") (:url . "https://orgmode.org") (:keywords "outlines" "hypermedia" "calendar" "wp") (:maintainer "Bastien Guerry" . "[email-masked]") (:authors ("Carsten Dominik" . "[email-masked]")) (:commit . "630f86dfc42472aafd9a4f305e1965cbe92b2891")) :signed nil))
>>>   package-vc--generate-description-file(#s(package-desc :name org :version (9 6 1) :summary "Outline-based notes management and organizer" :reqs ((emacs (25 1))) :kind tar :archive "gnu" :dir "/home/yuu/.config/emacsen/bug/elpa/org-9.6.1/" :extras ((:lisp-dir . "lisp") (:lisp-dir . "lisp") (:url . "https://orgmode.org") (:keywords "outlines" "hypermedia" "calendar" "wp") (:maintainer "Bastien Guerry" . "[email-masked]") (:authors ("Carsten Dominik" . "[email-masked]")) (:commit . "630f86dfc42472aafd9a4f305e1965cbe92b2891")) :signed nil) "/home/yuu/.config/emacsen/bug/elpa/org-9.6.1/org-pkg.el")
>>>   package-vc--unpack-1(#s(package-desc :name org :version (9 6 1) :summary "Outline-based notes management and organizer" :reqs ((emacs (25 1))) :kind tar :archive "gnu" :dir "/home/yuu/.config/emacsen/bug/elpa/org-9.6.1/" :extras ((:lisp-dir . "lisp") (:lisp-dir . "lisp") (:url . "https://orgmode.org") (:keywords "outlines" "hypermedia" "calendar" "wp") (:maintainer "Bastien Guerry" . "[email-masked]") (:authors ("Carsten Dominik" . "[email-masked]")) (:commit . "630f86dfc42472aafd9a4f305e1965cbe92b2891")) :signed nil) "/home/yuu/.config/emacsen/bug/elpa/org-9.6.1/")
>>>   package-vc--unpack(#s(package-desc :name org :version (9 6 1) :summary "Outline-based notes management and organizer" :reqs ((emacs (25 1))) :kind tar :archive "gnu" :dir "/home/yuu/.config/emacsen/bug/elpa/org-9.6.1/" :extras ((:lisp-dir . "lisp") (:lisp-dir . "lisp") (:url . "https://orgmode.org") (:keywords "outlines" "hypermedia" "calendar" "wp") (:maintainer "Bastien Guerry" . "[email-masked]") (:authors ("Carsten Dominik" . "[email-masked]")) (:commit . "630f86dfc42472aafd9a4f305e1965cbe92b2891")) :signed nil) (:url "https://git.tecosaur.net/tec/org-mode" :branch "dev" :lisp-dir "lisp" :vc-backend Git))
>>>   package-vc-install-selected-packages()
>>>   elisp--eval-last-sexp(nil)
>>>   eval-last-sexp(nil)
>>>   funcall-interactively(eval-last-sexp nil)
>>>   command-execute(eval-last-sexp)
>>>
>>> SYSTEM INFORMATION
>>>
>>> In GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, X toolkit, cairo
>>> version 1.16.0, Xaw3d scroll bars)
>>> Repository revision: dc843e0a9b3ba3e29bc65bdbd1050cfcc96cad5d
>>> Repository branch: master
>>> Windowing system distributor 'The X.Org Foundation', version 11.0.12014000
>>> System Description: NixOS 23.05 (Stoat)
>>>
>>> Configured using:
>>>  'configure
>>>  --prefix=/nix/store/mpn2g01lmxhsd249p6klvki16g2z5n28-emacs-git-20230215.0
>>>  --disable-build-details --with-modules --with-x-toolkit=lucid
>>>  --with-xft --with-cairo --with-native-compilation'
>>>
>>> Configured features:
>>> CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GSETTINGS HARFBUZZ JPEG JSON
>>> LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES NATIVE_COMP NOTIFY
>>> INOTIFY PDUMPER PNG RSVG SECCOMP SOUND SQLITE3 THREADS TIFF
>>> TOOLKIT_SCROLL_BARS TREE_SITTER WEBP X11 XAW3D XDBE XIM XPM LUCID ZLIB
>>>
>>> Important settings:
>>>   value of $EMACSLOADPATH: 
>>>   value of $EMACSNATIVELOADPATH: /nix/store/3m84mvjv04mg0i5jk4qnmb6sccd64gf3-emacs-packages-deps/share/emacs/native-lisp::
>>>   value of $LC_CTYPE: pt_BR.UTF-8
>>>   value of $LC_TIME: en_DK.UTF-8
>>>   value of $LANG: en_US.UTF-8
>>>   locale-coding-system: utf-8-unix
>>>
>>> Major mode: ELisp/d
>>>
>>> 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
>>>   line-number-mode: t
>>>   indent-tabs-mode: t
>>>   transient-mark-mode: t
>>>   auto-composition-mode: t
>>>   auto-encryption-mode: t
>>>   auto-compression-mode: t
>>>
>>> Load-path shadows:
>>> /etc/profiles/per-user/yuu/share/emacs/site-lisp/site-start hides /nix/store/3m84mvjv04mg0i5jk4qnmb6sccd64gf3-emacs-packages-deps/share/emacs/site-lisp/site-start
>>> /etc/profiles/per-user/yuu/share/emacs/site-lisp/site-start hides /nix/store/mpn2g01lmxhsd249p6klvki16g2z5n28-emacs-git-20230215.0/share/emacs/site-lisp/site-start
>>> /nix/store/3m84mvjv04mg0i5jk4qnmb6sccd64gf3-emacs-packages-deps/share/emacs/site-lisp/elpa/let-alist-1.0.6/let-alist hides /nix/store/mpn2g01lmxhsd249p6klvki16g2z5n28-emacs-git-20230215.0/share/emacs/30.0.50/lisp/emacs-lisp/let-alist
>>>
>>> Features:
>>> (shadow sort mail-extr emacsbug message yank-media puny dired
>>> dired-loaddefs rfc822 mml mml-sec epa derived epg rfc6068 epg-config
>>> gnus-util time-date mm-decode mm-bodies mm-encode mail-parse rfc2231
>>> mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums
>>> mm-util mail-prsvr mail-utils misearch multi-isearch mule-util jka-compr
>>> help-fns cl-print debug backtrace find-func loaddefs-gen radix-tree
>>> vc-git diff-mode easy-mmode finder-inf package-vc vc vc-dispatcher
>>> lisp-mnt format-spec face-remap bookmark text-property-search pp comp
>>> comp-cstr warnings icons rx cl-extra help-mode
>>> visual-fill-column-autoloads writeroom-mode-autoloads vterm-autoloads
>>> pdf-tools-autoloads let-alist-autoloads tablist-autoloads
>>> emojify-logos-autoloads emojify-autoloads ht-autoloads info
>>> dash-autoloads emacsql-sqlite-autoloads emacsql-autoloads package
>>> browse-url url url-proxy url-privacy url-expand url-methods url-history
>>> url-cookie generate-lisp-file url-domsuf url-util mailcap url-handlers
>>> url-parse auth-source cl-seq eieio eieio-core cl-macs password-cache
>>> json subr-x map byte-opt gv bytecomp byte-compile url-vars cl-loaddefs
>>> cl-lib rmc iso-transl tooltip cconv eldoc paren electric uniquify
>>> ediff-hook vc-hooks lisp-float-type elisp-mode mwheel term/x-win x-win
>>> term/common-win x-dnd 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 nadvice seq simple cl-generic indonesian philippine
>>> 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 abbrev obarray oclosure
>>> cl-preloaded button loaddefs theme-loaddefs faces cus-face macroexp
>>> files window text-properties overlay sha1 md5 base64 format env
>>> code-pages mule custom widget keymap hashtable-print-readable backquote
>>> threads dbusbind inotify dynamic-setting system-font-setting
>>> font-render-setting cairo x-toolkit x multi-tty make-network-process
>>> native-compile emacs)
>>>
>>> Memory information:
>>> ((conses 16 162257 13781)
>>>  (symbols 48 14001 0)
>>>  (strings 32 44897 1851)
>>>  (string-bytes 1 1298807)
>>>  (vectors 16 24166)
>>>  (vector-slots 8 463867 19912)
>>>  (floats 8 54 193)
>>>  (intervals 56 1864 261)
>>>  (buffers 984 17))
>>>
>>>
>>>
>>>
>>
>> -- 
>> Philip Kaludercic
>
> --
> Yuu Yin

-- 
Philip Kaludercic