Refactor doom-get-packages
Adds an INSTALLED-ONLY-P argument to doom-get-packages. Fixes a missing-package error when doom-get-outdated-packages iterates over packages that aren't installed. Plus, updated unit tests.
This commit is contained in:
parent
ea4d0a50cb
commit
59544391f2
2 changed files with 43 additions and 36 deletions
|
@ -80,7 +80,7 @@ list of the package."
|
||||||
(plist-get (cdr (assq name doom-packages)) prop))
|
(plist-get (cdr (assq name doom-packages)) prop))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom-get-packages ()
|
(defun doom-get-packages (&optional installed-only-p)
|
||||||
"Retrieves a list of explicitly installed packages (i.e. non-dependencies).
|
"Retrieves a list of explicitly installed packages (i.e. non-dependencies).
|
||||||
Each element is a cons cell, whose car is the package symbol and whose cdr is
|
Each element is a cons cell, whose car is the package symbol and whose cdr is
|
||||||
the quelpa recipe (if any).
|
the quelpa recipe (if any).
|
||||||
|
@ -89,13 +89,17 @@ BACKEND can be 'quelpa or 'elpa, and will instruct this function to return only
|
||||||
the packages relevant to that backend.
|
the packages relevant to that backend.
|
||||||
|
|
||||||
Warning: this function is expensive; it re-evaluates all of doom's config files.
|
Warning: this function is expensive; it re-evaluates all of doom's config files.
|
||||||
Be careful not to use it in a loop."
|
Be careful not to use it in a loop.
|
||||||
|
|
||||||
|
If INSTALLED-ONLY-P, only return packages that are installed."
|
||||||
(doom-initialize-packages t)
|
(doom-initialize-packages t)
|
||||||
(cl-loop with packages = (append doom-core-packages (mapcar #'car doom-packages))
|
(cl-loop with packages = (append doom-core-packages (mapcar #'car doom-packages))
|
||||||
for sym in (cl-delete-duplicates packages)
|
for sym in (cl-delete-duplicates packages)
|
||||||
if (or (assq sym doom-packages)
|
if (and (or (not installed-only-p)
|
||||||
(and (assq sym package-alist)
|
(package-installed-p sym))
|
||||||
(list sym)))
|
(or (assq sym doom-packages)
|
||||||
|
(and (assq sym package-alist)
|
||||||
|
(list sym))))
|
||||||
collect it))
|
collect it))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
|
@ -121,7 +125,7 @@ If INCLUDE-FROZEN-P is non-nil, check frozen packages as well.
|
||||||
Used by `doom/packages-update'."
|
Used by `doom/packages-update'."
|
||||||
(let (quelpa-pkgs elpa-pkgs)
|
(let (quelpa-pkgs elpa-pkgs)
|
||||||
;; Separate quelpa from elpa packages
|
;; Separate quelpa from elpa packages
|
||||||
(dolist (pkg (doom-get-packages))
|
(dolist (pkg (doom-get-packages t))
|
||||||
(let ((sym (car pkg)))
|
(let ((sym (car pkg)))
|
||||||
(when (and (or (not (doom-package-prop sym :freeze))
|
(when (and (or (not (doom-package-prop sym :freeze))
|
||||||
include-frozen-p)
|
include-frozen-p)
|
||||||
|
|
|
@ -18,6 +18,14 @@ affects your Emacs packages)."
|
||||||
(package-initialize)
|
(package-initialize)
|
||||||
,@forms))
|
,@forms))
|
||||||
|
|
||||||
|
(defmacro -with-packages! (packages package-descs &rest body)
|
||||||
|
`(let ((doom-packages ,packages)
|
||||||
|
(package-alist ,package-descs)
|
||||||
|
doom-core-packages)
|
||||||
|
(cl-letf (((symbol-function 'doom-initialize-packages) (lambda (&rest _)))
|
||||||
|
((symbol-function 'package-installed-p) (lambda (name &rest _) (assq name package-alist))))
|
||||||
|
,@body)))
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
;; Tests
|
;; Tests
|
||||||
|
@ -31,45 +39,40 @@ affects your Emacs packages)."
|
||||||
(should (eq (doom-package-backend 'doom-quelpa-dummy) 'quelpa))))
|
(should (eq (doom-package-backend 'doom-quelpa-dummy) 'quelpa))))
|
||||||
|
|
||||||
(def-test! elpa-outdated-detection
|
(def-test! elpa-outdated-detection
|
||||||
(cl-letf (((symbol-function 'package-refresh-contents) (lambda (&rest _))))
|
(let* ((doom--last-refresh (current-time))
|
||||||
(let* ((doom--last-refresh (current-time))
|
(package-alist
|
||||||
(package-alist
|
`((doom-dummy ,(-new-package 'doom-dummy '(20160405 1234)))))
|
||||||
`((doom-dummy ,(-new-package 'doom-dummy '(20160405 1234)))))
|
(package-archive-contents
|
||||||
(package-archive-contents
|
`((doom-dummy ,(-new-package 'doom-dummy '(20170405 1234))))))
|
||||||
`((doom-dummy ,(-new-package 'doom-dummy '(20170405 1234)))))
|
(cl-letf (((symbol-function 'package-refresh-contents) (lambda (&rest _))))
|
||||||
(outdated (doom-package-outdated-p 'doom-dummy)))
|
(should (equal (doom-package-outdated-p 'doom-dummy)
|
||||||
(should outdated)
|
'(doom-dummy (20160405 1234) (20170405 1234)))))))
|
||||||
(should (equal outdated '(doom-dummy (20160405 1234) (20170405 1234)))))))
|
|
||||||
|
|
||||||
;; TODO quelpa-outdated-detection
|
;; TODO quelpa-outdated-detection
|
||||||
|
|
||||||
(def-test! get-packages
|
(def-test! get-packages
|
||||||
(let ((quelpa-initialized-p t)
|
(let ((quelpa-initialized-p t))
|
||||||
(doom-packages '((doom-dummy)))
|
(-with-packages!
|
||||||
(package-alist
|
'((doom-dummy))
|
||||||
`((doom-dummy nil)
|
'((doom-dummy nil)
|
||||||
(doom-dummy-dep nil)))
|
(doom-dummy-unwanted nil)
|
||||||
doom-core-packages)
|
(doom-dummy-dep nil))
|
||||||
(cl-letf (((symbol-function 'doom-initialize-packages) (lambda (&rest _))))
|
(should (equal (doom-get-packages) '((doom-dummy)))))))
|
||||||
(should (equal (doom-get-packages) '((doom-dummy)))))))
|
|
||||||
|
|
||||||
(def-test! orphaned-packages
|
(def-test! orphaned-packages
|
||||||
"Test `doom-get-orphaned-packages', which gets a list of packages that are
|
"Test `doom-get-orphaned-packages', which gets a list of packages that are
|
||||||
no longer enabled or depended on."
|
no longer enabled or depended on."
|
||||||
(let ((doom-packages '((doom-dummy)))
|
(-with-packages!
|
||||||
(package-alist
|
'((doom-dummy))
|
||||||
`((doom-dummy ,(-new-package 'doom-dummy '(20160405 1234) '((doom-dummy-dep (1 0)))))
|
`((doom-dummy ,(-new-package 'doom-dummy '(20160405 1234) '((doom-dummy-dep (1 0)))))
|
||||||
(doom-dummy-unwanted ,(-new-package 'doom-dummy-unwanted '(20160601 1234)))
|
(doom-dummy-unwanted ,(-new-package 'doom-dummy-unwanted '(20160601 1234)))
|
||||||
(doom-dummy-dep ,(-new-package 'doom-dummy-dep '(20160301 1234)))))
|
(doom-dummy-dep ,(-new-package 'doom-dummy-dep '(20160301 1234))))
|
||||||
doom-core-packages)
|
(should (equal (doom-get-orphaned-packages) '(doom-dummy-unwanted)))))
|
||||||
(cl-letf (((symbol-function 'doom-initialize-packages) (lambda (&rest _))))
|
|
||||||
(should (equal (doom-get-orphaned-packages) '(doom-dummy-unwanted))))))
|
|
||||||
|
|
||||||
(def-test! missing-packages
|
(def-test! missing-packages
|
||||||
"Test `doom-get-missing-packages, which gets a list of enabled packages that
|
"Test `doom-get-missing-packages, which gets a list of enabled packages that
|
||||||
aren't installed."
|
aren't installed."
|
||||||
(let ((doom-packages '((doom-dummy) (doom-dummy-installed)))
|
(-with-packages!
|
||||||
(package-alist `((doom-dummy-installed ,(-new-package 'doom-dummy-installed '(20160405 1234)))))
|
'((doom-dummy) (doom-dummy-installed))
|
||||||
doom-core-packages)
|
`((doom-dummy-installed ,(-new-package 'doom-dummy-installed '(20160405 1234))))
|
||||||
(cl-letf (((symbol-function 'doom-initialize-packages) (lambda (&rest _))))
|
(should (equal (doom-get-missing-packages) '((doom-dummy))))))
|
||||||
(should (equal (doom-get-missing-packages) '((doom-dummy)))))))
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue