Skip to content

Commit

Permalink
feat(core): Lazy install on required packages (#284)
Browse files Browse the repository at this point in the history
* feat(core): Lazy install on required packages

* fix: Emacs 26.x

* docs: Update dev api

* Fix typo
  • Loading branch information
jcs090218 authored Nov 21, 2024
1 parent 40c2d87 commit 6c23af4
Show file tree
Hide file tree
Showing 26 changed files with 93 additions and 57 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
* fix(lint): match behavior of declare linter to checkdoc (#272)
* fix(test): ERT test fails on Emacs 30+ (cc1f4e15b7b40b986ad1a93f6e40d121340598de)
* fix(test): eask options should not be passed to buttercup (#281)
* feat(core): Lazy install on required packages (#284)

## 0.10.x
> Released Jun 13, 2024
Expand Down
19 changes: 17 additions & 2 deletions docs/content/Development-API/_index.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ Initialize packages for use.

Scope that temporary makes archives available.

`ARCHIVES` can either be a string or a list of strings.
The argument `ARCHIVES` can either be a string or a list of strings.

```elisp
(eask-with-archives "melpa"
Expand All @@ -260,6 +260,21 @@ Scope that temporary makes archives available.
💡 This is handy when you need certain packages from certain archives.
{{< /hint >}}

## 🔍 Function: eask-archive-install-packages (`archives` `names`)

Install packages with archives setup.

The arugment `names` can be a symbol or list of symbols.

```elisp
(eask-archive-install-packages '("gnu" "melpa")
'el2org) ; accept list
```

{{< hint info >}}
💡 This only installs packages if they are missing.
{{< /hint >}}

## 🔍 Function: eask-package-desc (`name` &optional `current`)

Build package descriptor for a package.
Expand Down Expand Up @@ -975,7 +990,7 @@ Return size of the current package.
Create execution with the responsive message output.

```elisp
(eask-with-progress
(eask-with-progress
"Downloading files... "
(eask-with-verbosity 'debug ; Often used with `eask-with-verbosity'
;; Execute some operations..
Expand Down
25 changes: 20 additions & 5 deletions docs/content/Development-API/_index.zh-tw.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ $ eask init
💡 我們不經常呼叫它,因為我們不希望直接執行另一個命令!
{{< /hint >}}

## 🔍 Function: eask-import (`url`)
## 🔍 函式: eask-import (`url`)

從 url 載入並評估腳本。

Expand Down Expand Up @@ -246,15 +246,30 @@ $ eask init

臨時使存檔可用的範圍。

`ARCHIVES` 可以是字符串或字符串列表
參數 `archives` 可以是字串或字串列表

```elisp
(eask-with-archives "melpa"
(eask-package-install 'dash)) ; 安裝僅在 MELPA 中定義的包
```

{{< hint info >}}
💡 當您需要某些檔案中的某些包時,這很方便。
💡 當您需要某些存檔中的特定套件時,這非常方便。
{{< /hint >}}

## 🔍 函式: eask-archive-install-packages (`archives` `names`)

使用 archives 設定安裝套件。

參數 `names` 可以是符號或符號列表。

```elisp
(eask-archive-install-packages '("gnu" "melpa")
'el2org) ; 接受列表
```

{{< hint info >}}
💡 這只會在套件遺失時安裝套件。
{{< /hint >}}

## 🔍 函式: eask-package-desc (`name` &optional `current`)
Expand Down Expand Up @@ -965,7 +980,7 @@ This will kill Emacs process.
使用響應消息輸出創建執行。

```elisp
(eask-with-progress
(eask-with-progress
"檔案下載中s... "
(eask-with-verbosity 'debug ; 通常與 `eask-with-verbosity` 一起使用
;; 執行一些操作..
Expand Down Expand Up @@ -1011,6 +1026,6 @@ This will kill Emacs process.

返回可能的包名稱。

## 🔍 Function: eask-guess-entry-point ()
## 🔍 函式: eask-guess-entry-point ()

返回可能的包的入口點。
12 changes: 10 additions & 2 deletions lisp/_prepare.el
Original file line number Diff line number Diff line change
Expand Up @@ -569,8 +569,8 @@ scope of the dependencies (it's either `production' or `development')."
(eask-defvc< 27 (eask-pkg-init)) ; XXX: remove this after we drop 26.x
(when eask-depends-on-recipe-p
(eask-log "Installing required external packages...")
(eask-with-archives '("gnu" "melpa")
(eask-package-install 'package-build))
(eask-archive-install-packages '("gnu" "melpa")
'package-build)
(eask-with-progress
"Building temporary archives (this may take a while)... "
(eask-with-verbosity 'debug (github-elpa-build))
Expand Down Expand Up @@ -656,6 +656,14 @@ Argument BODY are forms for execution."
"done ✓"))
,@body))

(defun eask-archive-install-packages (archives names)
"Install package NAMES with ARCHIVES setup."
(eask-defvc< 27 (eask-pkg-init)) ; XXX: remove this after we drop 26.x
(when-let* ((names (eask-listify names))
((cl-some (lambda (pkg) (not (package-installed-p pkg))) names)))
(eask-with-archives archives
(eask--package-mapc #'eask-package-install names))))

(defun eask-package-installable-p (pkg)
"Return non-nil if package (PKG) is installable."
(assq (eask-intern pkg) package-archive-contents))
Expand Down
4 changes: 2 additions & 2 deletions lisp/core/cat.el
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

(eask-start
;; Preparation
(eask-with-archives "melpa"
(eask-package-install 'e2ansi))
(eask-archive-install-packages '("gnu" "melpa")
'e2ansi)
(eask-msg "")

;; Start the task
Expand Down
4 changes: 2 additions & 2 deletions lisp/core/docs.el
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@

(eask-start
;; Preparation
(eask-with-archives '("gnu" "melpa")
(eask-package-install 'el2org))
(eask-archive-install-packages '("gnu" "melpa")
'el2org)

;; Start building...
(require 'el2org)
Expand Down
6 changes: 3 additions & 3 deletions lisp/core/loc.el
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@

(eask-start
;; Preparation
(eask-with-archives '("gnu" "melpa")
(eask-package-install 'markdown-mode))
(eask-archive-install-packages '("gnu" "melpa")
'markdown-mode)

(require 'markdown-mode)
;; Start LOC
(if-let* ((files (or (eask-expand-file-specs (eask-args))
(eask-package-files)))
(eask-output (get-buffer-create "*eask-output*")))
(eask-output (get-buffer-create "*eask-output*")))
(with-current-buffer eask-output
(erase-buffer)
(progn ; Print header
Expand Down
4 changes: 2 additions & 2 deletions lisp/core/package.el
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ Argument VERSION is a string represent the version number of this package."
(ignore-errors (make-directory eask-dist-path t))

(eask-defvc< 27 (eask-pkg-init)) ; XXX: remove this after we drop 26.x
(eask-with-archives '("gnu" "melpa")
(eask-package-install 'package-build))
(eask-archive-install-packages '("gnu" "melpa")
'package-build)
(eask-load "extern/package-build") ; override

(let* ((version (eask-package-version))
Expand Down
4 changes: 2 additions & 2 deletions lisp/format/elfmt.el
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@

(eask-start
;; Preparation
(eask-with-archives '("gnu" "melpa" "jcs-elpa")
(eask-package-install 'elfmt))
(eask-archive-install-packages '("gnu" "melpa" "jcs-elpa")
'elfmt)
(setq eask-format-elfmt--version (eask-package--version-string 'elfmt))

;; Start formatting
Expand Down
4 changes: 2 additions & 2 deletions lisp/format/elisp-autofmt.el
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@

(eask-start
;; Preparation
(eask-with-archives '("gnu" "melpa")
(eask-package-install 'elisp-autofmt))
(eask-archive-install-packages '("gnu" "melpa")
'elisp-autofmt)
(setq eask-format-elisp-autofmt--version (eask-package--version-string 'elisp-autofmt))

;; Start formatting
Expand Down
4 changes: 2 additions & 2 deletions lisp/generate/ignore.el
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@

(eask-start
;; Preparation
(eask-with-archives "melpa"
(eask-package-install 'gitignore-templates))
(eask-archive-install-packages '("gnu" "melpa")
'gitignore-templates)

;; Start the task
(require 'gitignore-templates)
Expand Down
4 changes: 2 additions & 2 deletions lisp/generate/license.el
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@

(eask-start
;; Preparation
(eask-with-archives "melpa"
(eask-package-install 'license-templates))
(eask-archive-install-packages '("gnu" "melpa")
'license-templates)

;; Start the task
(require 'license-templates)
Expand Down
5 changes: 2 additions & 3 deletions lisp/generate/test/buttercup.el
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@
" test-file name test-file))))))

(eask-start
(eask-with-archives '("gnu" "melpa")
(eask-package-install 'buttercup)
(eask-package-install 'f))
(eask-archive-install-packages '("gnu" "melpa")
'(buttercup f))
(require 'buttercup)
(require 'f)
(eask-generate-test-buttercup--init (eask-guess-package-name)))
Expand Down
4 changes: 2 additions & 2 deletions lisp/generate/test/ecukes.el
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
nil t))

(eask-start
(eask-with-archives '("gnu" "melpa")
(eask-package-install 'ecukes))
(eask-archive-install-packages '("gnu" "melpa")
'ecukes)
(require 'ecukes-new)
(ecukes-new))

Expand Down
4 changes: 2 additions & 2 deletions lisp/generate/test/ert-runner.el
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
" name))))

(eask-start
(eask-with-archives '("gnu" "melpa")
(eask-package-install 'ert-runner))
(eask-archive-install-packages '("gnu" "melpa")
'ert-runner)
(advice-add 'ert-runner/run :override #'ignore)
(load-library "ert-runner")
(load-library "f")
Expand Down
5 changes: 2 additions & 3 deletions lisp/init/cask.el
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,8 @@ Optional argument CONTENTS is used for nested directives. e.g. development."

(eask-start
;; Preparation
(eask-with-archives `("gnu" "melpa" "jcs-elpa")
(eask-package-install 'package-build)
(eask-package-install 'cask))
(eask-archive-install-packages '("gnu" "melpa" "jcs-elpa")
'(package-build cask))

;; Start Converting
(require 'cask)
Expand Down
4 changes: 2 additions & 2 deletions lisp/init/eldev.el
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@

(eask-start
;; Preparation
(eask-with-archives "melpa"
(eask-package-install 'eldev))
(eask-archive-install-packages '("gnu" "melpa")
'eldev)

;; Start Converting
(require 'eldev)
Expand Down
4 changes: 2 additions & 2 deletions lisp/init/keg.el
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ If no found the Keg file, returns nil."

(eask-start
;; Preparation
(eask-with-archives "melpa"
(eask-package-install 'keg))
(eask-archive-install-packages '("gnu" "melpa")
'keg)

;; Start Converting
(require 'keg)
Expand Down
4 changes: 2 additions & 2 deletions lisp/lint/elisp-lint.el
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@

(eask-start
;; Preparation
(eask-with-archives '("gnu" "melpa")
(eask-package-install 'elisp-lint))
(eask-archive-install-packages '("gnu" "melpa")
'elisp-lint)
(setq eask-lint-elisp-lint--version (eask-package--version-string 'elisp-lint))

;; Start Linting
Expand Down
4 changes: 2 additions & 2 deletions lisp/lint/elsa.el
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@

(eask-start
;; Preparation
(eask-with-archives '("gnu" "melpa")
(eask-package-install 'elsa))
(eask-archive-install-packages '("gnu" "melpa")
'elsa)
(setq eask-lint-elsa--version (eask-package--version-string 'elsa))

;; Start Linting
Expand Down
4 changes: 2 additions & 2 deletions lisp/lint/package.el
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@

(eask-start
;; Preparation
(eask-with-archives '("gnu" "melpa")
(eask-package-install 'package-lint))
(eask-archive-install-packages '("gnu" "melpa")
'package-lint)
(setq eask-lint-package--version (eask-package--version-string 'package-lint))

;; Start Linting
Expand Down
4 changes: 2 additions & 2 deletions lisp/lint/regexps.el
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@

(eask-start
;; Preparation
(eask-with-archives "gnu"
(eask-package-install 'relint))
(eask-archive-install-packages '("gnu")
'relint)
(setq eask-lint-regexps--relint-version (eask-package--version-string 'relint))

;; Start Linting
Expand Down
4 changes: 2 additions & 2 deletions lisp/test/buttercup.el
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

(eask-start
;; Preparation
(eask-with-archives '("gnu" "melpa")
(eask-package-install 'buttercup))
(eask-archive-install-packages '("gnu" "melpa")
'buttercup)

;; Start Testing
(require 'buttercup)
Expand Down
4 changes: 2 additions & 2 deletions lisp/test/ecukes.el
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ Modified from function `ecukes-cli/run'."

(eask-start
;; Preparation
(eask-with-archives '("gnu" "melpa")
(eask-package-install 'ecukes))
(eask-archive-install-packages '("gnu" "melpa")
'ecukes)

;; Start Testing
(require 'ecukes)
Expand Down
4 changes: 2 additions & 2 deletions lisp/test/ert-runner.el
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
(setq ert-runner-verbose t))))

(eask-start
(eask-with-archives '("gnu" "melpa")
(eask-package-install 'ert-runner))
(eask-archive-install-packages '("gnu" "melpa")
'ert-runner)
(require 'ert-runner))

;;; test/ert-runner.el ends here
5 changes: 2 additions & 3 deletions lisp/test/melpazoid.el
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@

(eask-start
;; Preparation
(eask-with-archives '("gnu" "melpa")
(eask-package-install 'package-lint)
(eask-package-install 'pkg-info))
(eask-archive-install-packages '("gnu" "melpa")
'(package-lint pkg-info))

;; Start Testing
(let* ((dirs (or (eask-args) `(,default-directory))))
Expand Down

0 comments on commit 6c23af4

Please sign in to comment.