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: Philip Kaludercic
Subject: Re: feature/package+vc 04c4c578c7 3/4: Allow for packages to be installed directly from VCS
Date: Mon, 14 Feb 2022 20:57:48 +0000

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> +(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`.

Ok.

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

I guess the question here is if you want to make it explicit that
e.g. when removing a package with package-delete, you will be removing a
local checkout that might have modifications.  If not, it would probably
make sense to add warnings where necessary.

>> +(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?

If you pass the backend directly to vc-working-revision, and set the
file to the expanded file name of the current directory, it seems to
work (at least for git and SVN).  Would it make sense to add that as a
first step, then fall back to the 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?

Currently the :kind is not stored, so we have to infer it somehow.  I am
certain this could also be solve some other way, but I would also like
to allow for simply placing a directory into elpa/devel to be handled as
a package, as before with my site-lisp.el proposal.

>> +         ;; 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`.

That was my first thought too, but are we always certain that <pkg>.el
is the main file?

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

I will experiment with how viable this is.

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

Currently, I don't expect it to grow too much beyond the current
proposal.  If it does turn out that the missing features are too large,
pulling it all out into something like package-vc.el/package-extra.el
seems reasonable (and perhaps perhaps even fit for distribution via
ELPA).

> 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?

That would also be possible, I believe I initially assumed that :vc
would contain the contents of the header, and forgot to revise that
assumption later on.

>
>         Stefan
>

-- 
        Philip Kaludercic



reply via email to

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