emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: feature/package+vc 04c4c578c7 3/4: Allow for packages to be installe


From: Stefan Monnier
Subject: Re: feature/package+vc 04c4c578c7 3/4: Allow for packages to be installed directly from VCS
Date: Mon, 14 Feb 2022 11:20:32 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

>     Allow for packages to be installed directly from VCS

Yay!

> +(defcustom package-devel-dir (expand-file-name "devel" package-user-dir)
> +  "Directory containing the user's Emacs Lisp package checkouts.
> +The directory name should be absolute.
> +Apart from this directory, Emacs also looks for system-wide
> +packages in `package-directory-list'."
> +  :type 'directory
> +  :initialize #'custom-initialize-delay
> +  :set-after '(package-user-dir)
> +  :risky t
> +  :version "29.1")

Since this is not autoloaded, it should not need (nor want) 
`custom-initialize-delay`.

> @@ -560,7 +571,9 @@ This is, approximately, the inverse of `version-to-list'.
>  This is the name of the package with its version appended."
>    (format "%s-%s"
>            (package-desc-name pkg-desc)
> -          (package-version-join (package-desc-version pkg-desc))))
> +          (if (eq (package-desc-kind pkg-desc) 'source)
> +              "devel"
> +            (package-version-join (package-desc-version pkg-desc)))))

Currently the way `package.el` handles the use of Git-installed packages
is that it allows a package's directory to be just `<pkg>` instead of
`<pkg>-<vers>`.

So maybe we could do the same here.

> +(declare-function vc-working-revision "vc" (file &optional backend))
> +(defun package-devel-commit (pkg)
> +  "Extract the commit of a development package PKG."
> +  (cl-assert (eq (package-desc-kind pkg) 'source))
> +  (require 'vc)
> +  (cl-loop with dir = (package-desc-dir pkg)
> +           for file in (directory-files dir t "\\.el\\'" t)
> +           when (vc-working-revision file) return it
> +           finally return "unknown"))

Any chance we could use `vc-working-revision` on the package's root
directory to avoid this loop?

> @@ -681,6 +704,14 @@ return it."
>                               (read (current-buffer)))
>                              (error "Can't find define-package in %s" 
> pkg-file))))
>            (setf (package-desc-dir pkg-desc) pkg-dir)
> +          (when (file-exists-p (expand-file-name
> +                                (symbol-name (package-desc-name pkg-desc))
> +                                package-devel-dir))
> +            ;; XXX: This check seems dirty, there should be a better
> +            ;; way to deduce if a package is in the devel directory.
> +            (setf (package-desc-kind pkg-desc) 'source)
> +            (push (cons :commit (package-devel-commit pkg-desc))
> +                  (package-desc-extras pkg-desc)))
>            (if (file-exists-p signed-file)
>                (setf (package-desc-signed pkg-desc) t))
>            pkg-desc)))))

Hmm... why do we need to know if a package is in the devel directory?

> +         ;; In case the package was installed directly from source, the
> +         ;; dependency list wasn't know beforehand, and they might have
> +         ;; to be installed explicitly.
> +         (let (deps)
> +           (dolist (file (directory-files pkg-dir t "\\.el\\'" t))
> +             (with-temp-buffer
> +               (insert-file-contents file)
> +               (when-let* ((require-lines (lm-header-multiline 
> "package-requires")))
> +                 (thread-last
> +                   (mapconcat #'identity require-lines " ")
> +                   package-read-from-string
> +                   package--prepare-dependencies
> +                   (nconc deps)
> +                   (setq deps)))))

Hmm... I expected here we'd open the `<pkg>.el` file and call 
`package-buffer-info`.

Also, I'm wondering if `package-unpack` is the right place to put this
code.  Maybe it should be in a completely separate function:
`package-unpack` takes a buffer containing the package, whereas for
those VCS-packages we start from something quite different, and the
equivalent to the `pkg-desc` we pass for installation should be fairly
different as well (should more similar to the "package specs" used in
`elpa-admin.el`).  So I think it'll want a completely separate code path.

IOW, I'm not sure `package-fetch` should call `package-install`.
I suspect it would work as well or better if it did most of the
installation with its own fresh new code, and only hooks into the rest
of the code once the files are extracted and a `<pkg>-pkg.el`
was generated.

Also, unless the new code is small, it should likely live in another
file.  `package.el` tends to get loaded at startup in all sessions
(unless you use `package-quickstart`), so we should try and trim it down
rather than grow it.  Most of its code (`package-install`,
`list-packages`, ...) should be in a separate file from the one that
provides `package-activate-all`, I think.

Admittedly, maybe the better way is not to move `package-install` out
into a `package-extra.el` but rather to move `package-activate-all` to
a preloaded `package-hooks.el`.

> +    ((when-let* ((desc (cadr (assoc name-or-url package-archive-contents
> +                                    #'string=)))
> +                 (spec (or (alist-get :vc (package-desc-extras desc))
> +                           (user-error "Package has no VC header"))))

Hmmm... so IIUC you intend to change `elpa-admin.el` to include a `:vc`
extra info in the `archive-contents` file for every package?
Any reason to make that a plain string (that we then need to parse back
into a list) rather than a list?


        Stefan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]