emacs-devel
[Top][All Lists]
Advanced

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

Re: package.el dependencies


From: Artur Malabarba
Subject: Re: package.el dependencies
Date: Fri, 30 Jan 2015 16:43:00 +0000

There are several small style changes I would suggest, but I'll
refrain from mentioning them now as they can be made later.

There are, though, two important issues I see, so I'd like to raise them now.

> +(defun package-used-elsewhere-p (pkg &optional pkg-list)
> +  "Check in PKG-LIST if PKG is used elsewhere as dependency.
> +When not specified, PKG-LIST default to `package-alist' with PKG entry 
> removed.
> +Argument PKG is a symbol.
> +Returns the first package found in PKG-LIST where PKG is used as dependency."
> +  (cl-loop with alist = (or pkg-list
> +                            (remove (assq pkg package-alist)
> +                                    package-alist))
> +           for p in alist thereis
> +           (and (memq pkg (mapcar 'car (package-desc-reqs (cadr p))))
> +                (car p))))

This will prevent deletion of obsolete depencies (packages which are
dependencies but have a more recent version installed). To fix that,
PKG in this function needs to be a package-desc object, and the
function needs to be altered as follows.

(defun package-used-elsewhere-p (pkg &optional pkg-list)
  "Check in PKG-LIST if PKG is used elsewhere as dependency.
When not specified, PKG-LIST default to `package-alist' with PKG entry removed.
Argument PKG is a package-desc.
Returns name of the first package found in PKG-LIST where PKG is
used as dependency."
  (let ((name (package-desc-name pkg))
        (version (package-desc-version pkg))
        (most-recent-version (package-desc-version (assq name package-alist))))
    (unless (version< version most-recent-version)
      (cl-loop with alist = (or pkg-list
                                (remove (assq name package-alist)
                                        package-alist))
               for p in alist thereis
               (and (memq name (mapcar 'car (package-desc-reqs (cadr p))))
                    (car p)))))


> +;;;###autoload
> +(defun package-autoremove ()
> +  "Remove packages that are no more needed.
> +
> +Packages that are no more needed by other packages in
> +`packages-installed-directly' and their dependencies
> +will be deleted."
> +  (interactive)
> +  (let* (old-direct
> +         (needed (cl-loop for p in packages-installed-directly
> +                          if (assq p package-alist)
> +                          append (package--get-deps p) into lst
> +                          else do (push p old-direct)
> +                          finally return lst)))
> +    (cl-loop for p in (mapcar 'car package-alist)
> +             unless (or (memq p needed)
> +                        (memq p packages-installed-directly))
> +             collect p into lst
> +             finally (if lst
> +                         (when (y-or-n-p (format "%s packages will be 
> deleted:\n%s, proceed? "
> +                                                 (length lst)
> +                                                 (mapconcat 'symbol-name lst 
> ", ")))
> +                           (mapc (lambda (p)
> +                                   (package-delete (cadr (assq p 
> package-alist)) t))
> +                                 lst)
> +                           (customize-save-variable
> +                            'packages-installed-directly
> +                            (cl-loop for p in packages-installed-directly
> +                                     unless (memq p old-direct)
> +                                     collect p)))

IIUC, this will remove a package from packages-installed-directly if
it is not currently installed. That seems undesirable, and would be
fixed by simply removing this call to `customize-save-variable'.



reply via email to

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