core: package-list-v2 install and orphan detection

Still need to clean the orphan detection though

Packages are not configured for now
This commit is contained in:
syl20bnr 2015-08-08 00:01:36 -04:00
parent e4748ea692
commit aa2669ee9c
2 changed files with 123 additions and 22 deletions

View File

@ -319,6 +319,13 @@ layer directory."
(sort packages (lambda (x y) (string< (symbol-name (oref x :name))
(symbol-name (oref y :name))))))
(defun configuration-layer//filter-packages (packages ffunc)
"Return a filtered PACKAGES list where each element satisfies FFUNC."
(reverse (reduce (lambda (acc x)
(if (funcall ffunc x) (push x acc) acc))
packages
:initial-value nil)))
(defun configuration-layer//get-private-layer-dir (name)
"Return an absolute path the the private configuration layer with name
NAME."
@ -519,17 +526,16 @@ LAYERS is a list of layer symbols."
(let ((file (concat (oref layer :dir) file)))
(if (file-exists-p file) (load file)))))
(defsubst configuration-layer//add-layer-to-hash (pkg layer hash)
"Add LAYER to the list value stored in HASH with key PKG."
(let ((list (ht-get hash pkg)))
(symbol-value `(push ',layer list))
(puthash pkg list hash)))
(defun configuration-layer//install-packages ()
"Install the packages all the packages if there are not currently installed."
(interactive)
(let* ((not-installed (configuration-layer//get-packages-to-install
configuration-layer-all-packages-sorted))
(let* ((candidates (configuration-layer//filter-packages
configuration-layer-packages
(lambda (x) (and (not (null (oref x :owner)))
(not (eq 'local (oref x :location)))
(not (oref x :excluded))))))
(not-installed (configuration-layer//get-packages-to-install
(mapcar 'car (object-assoc-list :name candidates))))
(not-installed-count (length not-installed)))
;; installation
(if not-installed
@ -568,11 +574,7 @@ LAYERS is a list of layer symbols."
(spacemacs-buffer/append "\n")))))
(defun configuration-layer//filter-packages-with-deps (packages filter)
"Filter a PACKAGES list according to a FILTER predicate.
FILTER is a function applied to each element of PACKAGES, if FILTER returns
non nil then element is removed from the list otherwise element is kept in
the list.
"Return a filtered PACKAGES list where each elements satisfies FILTER.
This function also processed recursively the package dependencies."
(when packages
@ -586,17 +588,14 @@ This function also processed recursively the package dependencies."
(mapcar 'car deps) filter))))
(when install-deps
(setq result (append install-deps result))))
(unless (apply filter `(,pkg))
(when (funcall filter pkg)
(add-to-list 'result pkg t)))
(delete-dups result))))
(defun configuration-layer//get-packages-to-install (packages)
"Return a list of packages to install given a list of PACKAGES."
"Return a list of packages to install given a list of PACKAGES symbols."
(configuration-layer//filter-packages-with-deps
packages
(lambda (x)
;; the package is already installed
(package-installed-p x))))
packages (lambda (x) (not (package-installed-p x)))))
(defun configuration-layer//get-packages-to-update (packages)
"Return a list of packages to update given a list of PACKAGES."
@ -827,8 +826,8 @@ in `configuration-layer-packages'"
(let ((imp-pkgs))
(dolist (pkg package-alist)
(let ((pkg-sym (car pkg)))
(if (not (ht-contains? configuration-layer-packages pkg-sym))
(add-to-list 'imp-pkgs pkg-sym))))
(unless (object-assoc pkg-sym :name configuration-layer-packages)
(add-to-list 'imp-pkgs pkg-sym))))
imp-pkgs))
(defun configuration-layer//get-orphan-packages (implicit-pkgs dependencies)
@ -842,7 +841,7 @@ deleted safely."
(defun configuration-layer//is-package-orphan (pkg dependencies)
"Returns not nil if PKG is an orphan package."
(if (ht-contains? configuration-layer-packages pkg)
(if (object-assoc pkg :name configuration-layer-packages)
nil
(if (ht-contains? dependencies pkg)
(let ((parents (ht-get dependencies pkg)))

View File

@ -426,6 +426,108 @@
[object cfgl-package "pkg6" pkg6 nil nil nil elpa nil nil])
(configuration-layer//sort-packages pkgs)))))
;; ---------------------------------------------------------------------------
;; configuration-layer//filter-packages
;; ---------------------------------------------------------------------------
(ert-deftest test-filter-packages--filter-excluded-packages ()
(let* ((pkg1 (configuration-layer/make-package 'pkg1))
(pkg2 (configuration-layer/make-package 'pkg2))
(pkg3 (configuration-layer/make-package 'pkg3))
(pkg4 (configuration-layer/make-package 'pkg4))
(pkg5 (configuration-layer/make-package 'pkg5))
(pkg6 (configuration-layer/make-package 'pkg6))
(pkg7 (configuration-layer/make-package 'pkg7))
(pkg8 (configuration-layer/make-package 'pkg8))
(pkgs (list pkg1 pkg2 pkg3 pkg4 pkg5 pkg6 pkg7 pkg8)))
(oset pkg1 :excluded t)
(oset pkg3 :excluded t)
(oset pkg5 :excluded t)
(oset pkg6 :excluded t)
(should (equal '([object cfgl-package "pkg2" pkg2 nil nil nil elpa nil nil]
[object cfgl-package "pkg4" pkg4 nil nil nil elpa nil nil]
[object cfgl-package "pkg7" pkg7 nil nil nil elpa nil nil]
[object cfgl-package "pkg8" pkg8 nil nil nil elpa nil nil])
(configuration-layer//filter-packages
pkgs (lambda (x)
(not (oref x :excluded))))))))
(ert-deftest test-filter-packages--filter-local-packages ()
(let* ((pkg1 (configuration-layer/make-package 'pkg1))
(pkg2 (configuration-layer/make-package 'pkg2))
(pkg3 (configuration-layer/make-package 'pkg3))
(pkg4 (configuration-layer/make-package 'pkg4))
(pkg5 (configuration-layer/make-package 'pkg5))
(pkg6 (configuration-layer/make-package 'pkg6))
(pkg7 (configuration-layer/make-package 'pkg7))
(pkg8 (configuration-layer/make-package 'pkg8))
(pkgs (list pkg1 pkg2 pkg3 pkg4 pkg5 pkg6 pkg7 pkg8)))
(oset pkg1 :location 'local)
(oset pkg3 :location 'local)
(oset pkg5 :location 'local)
(oset pkg6 :location 'local)
(should (equal '([object cfgl-package "pkg2" pkg2 nil nil nil elpa nil nil]
[object cfgl-package "pkg4" pkg4 nil nil nil elpa nil nil]
[object cfgl-package "pkg7" pkg7 nil nil nil elpa nil nil]
[object cfgl-package "pkg8" pkg8 nil nil nil elpa nil nil])
(configuration-layer//filter-packages
pkgs (lambda (x)
(not (eq 'local (oref x :location)))))))))
(ert-deftest test-filter-packages--filter-local-or-excluded-packages ()
(let* ((pkg1 (configuration-layer/make-package 'pkg1))
(pkg2 (configuration-layer/make-package 'pkg2))
(pkg3 (configuration-layer/make-package 'pkg3))
(pkg4 (configuration-layer/make-package 'pkg4))
(pkg5 (configuration-layer/make-package 'pkg5))
(pkg6 (configuration-layer/make-package 'pkg6))
(pkg7 (configuration-layer/make-package 'pkg7))
(pkg8 (configuration-layer/make-package 'pkg8))
(pkgs (list pkg1 pkg2 pkg3 pkg4 pkg5 pkg6 pkg7 pkg8)))
(oset pkg1 :location 'local)
(oset pkg1 :excluded t)
(oset pkg3 :location 'local)
(oset pkg5 :location 'local)
(oset pkg6 :location 'local)
(oset pkg6 :excluded t)
(oset pkg7 :excluded t)
(should (equal '([object cfgl-package "pkg2" pkg2 nil nil nil elpa nil nil]
[object cfgl-package "pkg4" pkg4 nil nil nil elpa nil nil]
[object cfgl-package "pkg8" pkg8 nil nil nil elpa nil nil])
(configuration-layer//filter-packages
pkgs (lambda (x)
(and (not (eq 'local (oref x :location)))
(not (oref x :excluded)))))))))
(ert-deftest test-filter-packages--filter-local-and-excluded-packages ()
(let* ((pkg1 (configuration-layer/make-package 'pkg1))
(pkg2 (configuration-layer/make-package 'pkg2))
(pkg3 (configuration-layer/make-package 'pkg3))
(pkg4 (configuration-layer/make-package 'pkg4))
(pkg5 (configuration-layer/make-package 'pkg5))
(pkg6 (configuration-layer/make-package 'pkg6))
(pkg7 (configuration-layer/make-package 'pkg7))
(pkg8 (configuration-layer/make-package 'pkg8))
(pkgs (list pkg1 pkg2 pkg3 pkg4 pkg5 pkg6 pkg7 pkg8)))
(oset pkg1 :location 'local)
(oset pkg1 :excluded t)
(oset pkg3 :location 'local)
(oset pkg5 :excluded t)
(oset pkg6 :location 'local)
(oset pkg6 :excluded t)
(should (equal '(
[object cfgl-package "pkg2" pkg2 nil nil nil elpa nil nil]
[object cfgl-package "pkg3" pkg3 nil nil nil local nil nil]
[object cfgl-package "pkg4" pkg4 nil nil nil elpa nil nil]
[object cfgl-package "pkg5" pkg5 nil nil nil elpa nil t]
[object cfgl-package "pkg7" pkg7 nil nil nil elpa nil nil]
[object cfgl-package "pkg8" pkg8 nil nil nil elpa nil nil])
(configuration-layer//filter-packages
pkgs (lambda (x)
(or (not (eq 'local (oref x :location)))
(not (oref x :excluded)))))))))
;; ---------------------------------------------------------------------------
;; configuration-layer//directory-type
;; ---------------------------------------------------------------------------