Function: package-get-descriptor
package-get-descriptor is a byte-compiled function defined in
package.el.gz.
Signature
(package-get-descriptor PKG &optional SOURCES PRED)
Documentation
Return a package-desc object for PKG, or nil if none can be found.
If PKG is a package-desc object it will be returned directly. If PKG
is a symbol or string it designates a package name. The optional argument
SOURCES can be a list consisting of the symbols installed, builtin
or archive, each when present indicating that the function should find
a package-desc object for PKG in the list of installed packages,
built-in packages or packages available in the archives respectively.
If SOURCES is t, then the function will interpret this as a shorthand
for a list consisting of the symbols mentioned in the order given above.
If omitted, the argument falls back to a list consisting of installed
and archive. Any other symbol will be converted to a singleton list.
The order is significant, in that the first hit will be returned. If
specified, PRED is a function that takes a single package-desc argument
and prevents the object from being returned if the predicate returns nil.
Source Code
;; Defined in /usr/src/emacs/lisp/emacs-lisp/package.el.gz
;;;; Introspection
(defun package-get-descriptor (pkg &optional sources pred)
"Return a `package-desc' object for PKG, or nil if none can be found.
If PKG is a `package-desc' object it will be returned directly. If PKG
is a symbol or string it designates a package name. The optional argument
SOURCES can be a list consisting of the symbols `installed', `builtin'
or `archive', each when present indicating that the function should find
a `package-desc' object for PKG in the list of installed packages,
built-in packages or packages available in the archives respectively.
If SOURCES is t, then the function will interpret this as a shorthand
for a list consisting of the symbols mentioned in the order given above.
If omitted, the argument falls back to a list consisting of `installed'
and `archive'. Any other symbol will be converted to a singleton list.
The order is significant, in that the first hit will be returned. If
specified, PRED is a function that takes a single `package-desc' argument
and prevents the object from being returned if the predicate returns nil."
(cond
((package-desc-p pkg)
(and (or (not pred) (funcall pred pkg)) pkg))
((or (and (stringp pkg) (setq pkg (intern pkg)))
(symbolp pkg))
(catch 'found
(dolist (source (cond
((eq sources nil) '(installed archive))
((eq sources t) '(installed builtin archive))
((delete-dups (ensure-list sources)))))
(dolist (desc (alist-get pkg (pcase-exhaustive source
('installed (package--alist))
('builtin (package--builtin-alist))
('archive (package--archive-contents)))))
(when (or (null pred) (funcall pred desc))
(throw 'found desc))))))
((error "Failed to recognize package %S" pkg))))