Skip to content

Commit

Permalink
Merge pull request #226 from pkryger/assorted-fixes-oct-2024
Browse files Browse the repository at this point in the history
Assorted fixes
  • Loading branch information
pkryger authored Nov 2, 2024
2 parents 5c3b653 + daef68a commit 1d69211
Show file tree
Hide file tree
Showing 20 changed files with 211 additions and 156 deletions.
2 changes: 2 additions & 0 deletions .ci/compilation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ ${EMACS} -Q --batch \
--eval '
(progn
(setq debug-on-error t
eval-expression-print-length 100
edebug-print-length 500
user-emacs-directory "'"${EMACS_DIR}"'")
(load-file "'"${EMACS_DIR}"'/init.el"))' \
-f batch-byte-compile "${EMACS_DIR}"/{modules,extensions}/*.el
2 changes: 2 additions & 0 deletions .ci/first-start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ ${EMACS} -Q --batch \
--eval '
(progn
(setq debug-on-error t
eval-expression-print-length 100
edebug-print-length 500
user-emacs-directory "'"${EMACS_DIR}"'")
(defun ask-user-about-lock (file opponent)
(sleep-for 5)
Expand Down
19 changes: 14 additions & 5 deletions .ci/unit-test-cl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,17 @@ EMACS=${EMACS:=emacs}
${EMACS} -Q --batch \
--eval '
(progn
(setq user-emacs-directory "'"${EMACS_DIR}"'")
(load-file "'"${EMACS_DIR}"'/init.el")
(setq debug-on-error t)
(load-file "'"${EMACS_DIR}"'/modules/init-util-cl.t.el")
(ert-run-tests-batch-and-exit))'
(setq user-emacs-directory "'"${EMACS_DIR}"'")
(load-file "'"${EMACS_DIR}"'/init.el")
(setq debug-on-error t)
(load-file "'"${EMACS_DIR}"'/modules/init-util-cl.t.el")
(let ((print-level 50)
(eval-expression-print-level 50)
(eval-expression-print-length 1000)
(edebug-print-level 50)
(edebug-print-length 1000)
(ert-batch-print-level 50)
(ert-batch-print-length 1000)
(ert-batch-backtrace-line-length 1000)
(ert-batch-backtrace-right-margin 1000))
(ert-run-tests-batch-and-exit)))'
11 changes: 10 additions & 1 deletion .ci/unit-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,13 @@ ${EMACS} -Q --batch \
(load-file "'"${EMACS_DIR}"'/modules/init-forge.t.el")
(load-file "'"${EMACS_DIR}"'/modules/init-util.t.el")
(load-file "'"${EMACS_DIR}"'/modules/init-lib.t.el")
(ert-run-tests-batch-and-exit))'
(let ((print-level 50)
(eval-expression-print-level 50)
(eval-expression-print-length 1000)
(edebug-print-level 50)
(edebug-print-length 1000)
(ert-batch-print-level 50)
(ert-batch-print-length 1000)
(ert-batch-backtrace-line-length 1000)
(ert-batch-backtrace-right-margin 1000))
(ert-run-tests-batch-and-exit)))'
23 changes: 14 additions & 9 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,31 @@ jobs:
- ubuntu-latest
- macos-latest
emacs_version:
- 27.1
- 27.2
- 28.1
- 28.2
- 29.1
- 29.2
- 29.3
- 29.4
- snapshot
steps:
- uses: purcell/setup-emacs@master
with:
version: ${{ matrix.emacs_version }}
- uses: actions/checkout@v3

- uses: actions/checkout@v4
with:
path: '.emacs.d'

- name: First start # So most modules are pulled in from melpa and gnu
run: '.emacs.d/.ci/first-start.sh .emacs.d'

# - name: Compilation # This pulls extra modules not enabled by default
# run: '.emacs.d/.ci/compilation.sh .emacs.d'

- name: Unit tests
run: '.emacs.d/.ci/unit-tests.sh .emacs.d'

- name: Verify no obsolete cl- functions
run: '.emacs.d/.ci/unit-test-cl.sh .emacs.d'

Expand All @@ -51,22 +57,21 @@ jobs:
strategy:
matrix:
include:
- os: ubuntu-latest
emacs_version: 27.2
- os: macos-latest
emacs_version: 29.1
- os: macos-latest
emacs_version: snapshot
steps:
- uses: purcell/setup-emacs@master
with:
version: ${{ matrix.emacs_version }}
- uses: actions/checkout@v3

- uses: actions/checkout@v4
with:
path: '.emacs.d'
- uses: actions/checkout@v3

- uses: actions/checkout@v4
with:
repository: 'pkryger/exordium-commontap'
path: '.emacs.d/taps/commontap'

- name: First start # So most modules are pulled in from melpa and gnu
run: '.emacs.d/.ci/first-start.sh .emacs.d'
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,6 @@ transient/*

# request stash
request/
/.cask/
/forge-database-*.sqlite
/projects
14 changes: 10 additions & 4 deletions init.el
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ Each element of the list is in the same form as in `package-pinned-packages'."
;; Initialize the package system
(require 'seq)
(require 'package)
(setq package-install-upgrade-built-in t)
(when (or (not (string= exordium-melpa-package-repo
exordium-pinned-melpa-package-repo))
(seq-filter (lambda (pkg)
Expand All @@ -157,13 +158,13 @@ Each element of the list is in the same form as in `package-pinned-packages'."

;; Load the packages we need if they are not installed already
(let ((package-pinned-packages (append
'((use-package . "melpa-pinned")
(diminish . "melpa-pinned")
'((use-package . "gnu")
(diminish . "gnu")
(bind-key . "melpa-pinned"))
exordium-extra-pinned))
(has-refreshed nil))

(defun update-package (p has-refreshed)
(defun update-package (p has-refreshed)
(unless (package-installed-p p)
(unless has-refreshed
(message "Refreshing package database...")
Expand Down Expand Up @@ -220,6 +221,10 @@ Each element of the list is in the same form as in `package-pinned-packages'."
(require 'diminish) ;; if you use :diminish
(require 'bind-key) ;; if you use any :bind variant

;; Ensure use-package and diminish are from gnu
(use-package-pin-package 'use-package 'gnu)
(use-package-pin-package 'diminish 'gnu)

(require 'use-package-ensure)
(setq use-package-always-ensure t)
(setq use-package-compute-statistics t)
Expand Down Expand Up @@ -285,7 +290,8 @@ the .elc exists. Also discard .elc without corresponding .el"
;;; Usability
(use-package init-window-manager :ensure nil) ; navigate between windows
(use-package init-util :ensure nil) ; utilities like match paren, bookmarks...
(use-package init-ido :ensure nil) ; supercharged completion engine
(unless exordium-helm-everywhere
(use-package init-ido :ensure nil)) ; supercharged completion engine
(use-package init-highlight :ensure nil) ; highlighting current line, symbol under point
(use-package init-autocomplete :ensure nil
:if (eq exordium-complete-mode :auto-complete))
Expand Down
4 changes: 2 additions & 2 deletions modules/init-company.el
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@
(when (or (save-match-data (looking-at "\\W"))
(= (point) (point-max)))
(cons (or (match-string 1) "") t)))))
(candidates (when-let ((repo (forge-get-repository 'full)))
(candidates (when-let* ((repo (forge-get-repository 'full)))
(cl-remove-if-not
(lambda (assignee)
(string-prefix-p arg assignee))
(mapcar (lambda (assignee)
(propertize (cadr assignee)
'full-name (caddr assignee)))
(oref repo assignees)))))
(annotation (when-let ((assignee (get-text-property 0 'full-name arg)))
(annotation (when-let* ((assignee (get-text-property 0 'full-name arg)))
(format " [%s]" assignee)))))

:config
Expand Down
72 changes: 44 additions & 28 deletions modules/init-flycheck.el
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,20 @@ See URL `http://mypy-lang.org/'."
:predicate flycheck-buffer-saved-p
:error-explainer
(lambda (error)
(when-let ((error-code (flycheck-error-id error))
(mypy-version
(replace-regexp-in-string
"mypy \\(\\(?:[0-9]\\.\\)+[0-9]\\).*\n"
"\\1"
(shell-command-to-string "mypy --version")))
(error-codes-alist
(exordium-setf-when-nil
(alist-get (intern mypy-version)
exordium--flycheck-mypy-error-codes-alist)
(exodrium--flycheck-mypy-retrieve-error-codes
mypy-version)))
(explanation (alist-get (intern error-code)
error-codes-alist)))
(when-let* ((error-code (flycheck-error-id error))
(mypy-version
(replace-regexp-in-string
"mypy \\(\\(?:[0-9]\\.\\)+[0-9]\\).*\n"
"\\1"
(shell-command-to-string "mypy --version")))
(error-codes-alist
(exordium-setf-when-nil
(alist-get (intern mypy-version)
exordium--flycheck-mypy-error-codes-alist)
(exodrium--flycheck-mypy-retrieve-error-codes
mypy-version)))
(explanation (alist-get (intern error-code)
error-codes-alist)))
(lambda ()
(with-current-buffer standard-output
(insert explanation)
Expand All @@ -137,8 +137,17 @@ See URL `http://mypy-lang.org/'."
To override the path to the ruff executable, set
`flycheck-exordium-python-ruff-executable'.
See URL `http://pypi.python.org/pypi/ruff'."
:command ("ruff"
"--format=text"
:command ("ruff" "check"
(eval (let ((ruff-version (replace-regexp-in-string
"ruff \\([0-9]\.\+\\).*\n?" "\\1"
(shell-command-to-string "ruff --version"))))
(cond
((version< ruff-version "0.1")
'("--format" "text"))
((version< ruff-version "0.5")
'("--output-format" "text"))
(t
'("--output-format" "concise")))))
(eval (when buffer-file-name
(concat "--stdin-filename=" buffer-file-name)))
"-")
Expand All @@ -148,24 +157,31 @@ See URL `http://pypi.python.org/pypi/ruff'."
(let ((errors (flycheck-sanitize-errors errors)))
(seq-map #'flycheck-flake8-fix-error-level errors)))
:error-patterns
((warning line-start
((error line-start
(file-name) ":" line ":" (optional column ":") " "
(id (one-or-more (any alpha digit))) ": "
(message (one-or-more not-newline)))
(warning line-start
(file-name) ":" line ":" (optional column ":") " "
(id (one-or-more (any alpha)) (one-or-more digit)) " "
(message (one-or-more not-newline))
line-end))
:error-explainer
(lambda (error)
(when-let (error-code (flycheck-error-id error))
(lambda ()
(flycheck-call-checker-process
'exordium-python-ruff nil standard-output t "rule" error-code)
(with-current-buffer standard-output
(let ((markdown-fontify-code-block-default-mode 'python-mode)
(markdown-fontify-code-blocks-natively t)
(markdown-hide-markup t))
(markdown-view-mode)
(font-lock-flush)
(font-lock-ensure))))))
(when-let* ((error-code (flycheck-error-id error))
(error-level (flycheck-error-level error)))
(if (eq error-level 'error)
(message "No explanation for error: %s" error-code)
(lambda ()
(flycheck-call-checker-process
'exordium-python-ruff nil standard-output t "rule" error-code)
(with-current-buffer standard-output
(let ((markdown-fontify-code-block-default-mode 'python-mode)
(markdown-fontify-code-blocks-natively t)
(markdown-hide-markup t))
(markdown-view-mode)
(font-lock-flush)
(font-lock-ensure)))))))
:modes (python-mode python-ts-mode))

(add-to-list 'flycheck-checkers 'exordium-python-ruff)
Expand Down
67 changes: 36 additions & 31 deletions modules/init-forge.el
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
;; https://github.com/magit/emacsql/commit/6401226 for more details.
(unless (and (fboundp 'sqlite-available-p)
(sqlite-available-p))
(use-package sqlite3))
(let ((debug-on-error (if (and debug-on-error (getenv "ci_tests"))
(progn
(message "Temporarily disable `debug-on-error': `sqlite3-api' cannot be loaded when running in CI")
nil)
debug-on-error)))
(use-package sqlite3)))

;;; Magit Forge
(use-package forge
Expand Down Expand Up @@ -83,26 +88,26 @@ USERNAME, AUTH, and HOST behave as for `ghub-request'."
(defun exordium-forge-mark-ready-for-rewiew ()
"Mark the thing (the PR) at point as ready for review."
(interactive)
(if-let ((url (forge-get-url (or (forge-post-at-point)
(forge-current-topic))))
(_ (string-match
"//\\([^/]+\\)/\\([^/]+\\)/\\([^/]+\\)/pull/\\([0-9]+\\)$"
url))
(number (match-string 4 url))
(host (car (alist-get (match-string 1 url)
forge-alist
nil nil #'string=)))
(username (magit-git-string "config"
(concat "github." host ".user")))
(id (exordium-ghub-graphql--pull-request-id
(match-string 2 url)
(match-string 3 url)
(string-to-number number)
:username username :auth 'forge :host host))
(not-a-draft-anymore
(not (exordium-ghub-grqphql--mark-pull-request-ready-for-review
id
:username username :auth 'forge :host host))))
(if-let* ((url (forge-get-url (or (forge-post-at-point)
(forge-current-topic))))
(_ (string-match
"//\\([^/]+\\)/\\([^/]+\\)/\\([^/]+\\)/pull/\\([0-9]+\\)$"
url))
(number (match-string 4 url))
(host (car (alist-get (match-string 1 url)
forge-alist
nil nil #'string=)))
(username (magit-git-string "config"
(concat "github." host ".user")))
(id (exordium-ghub-graphql--pull-request-id
(match-string 2 url)
(match-string 3 url)
(string-to-number number)
:username username :auth 'forge :host host))
(not-a-draft-anymore
(not (exordium-ghub-grqphql--mark-pull-request-ready-for-review
id
:username username :auth 'forge :host host))))
(message "PR #%s is ready for review." number)
(user-error "Nothing at point that is a PR or mark failed")))

Expand Down Expand Up @@ -167,15 +172,15 @@ Each element of TO-DELETE is in the same format as used in
(defun exordium-forge-cleanup-known-repositories ()
"Cleanup forge repositories whose worktree doesn't exist anymore."
(interactive)
(if-let ((to-delete (cl-remove-if
(lambda (repo)
(if-let ((worktree (car repo)))
(file-exists-p worktree)
t))
(forge-sql [:select [worktree githost owner name]
:from repository
:order-by [(asc owner) (asc name)]]
[worktree githost owner name]))))
(if-let* ((to-delete (cl-remove-if
(lambda (repo)
(if-let* ((worktree (car repo)))
(file-exists-p worktree)
t))
(forge-sql [:select [worktree githost owner name]
:from repository
:order-by [(asc owner) (asc name)]]
[worktree githost owner name]))))
(when (yes-or-no-p (exordium-forge-cleanup-known-repositories--question
to-delete))
(async-start
Expand All @@ -187,7 +192,7 @@ Each element of TO-DELETE is in the same format as used in
,(async-inject-variables "\\`\\(to-delete\\|forge-alist\\)\\'")
(let (results)
(dolist (repo to-delete)
(when-let ((forge-repo (forge-get-repository (cdr repo))))
(when-let* ((forge-repo (forge-get-repository (cdr repo))))
(let ((t0 (current-time))
;; Timeout is huge (10x what was the default at the
;; time of writing this) as db ops are long sometimes.
Expand Down
Loading

0 comments on commit 1d69211

Please sign in to comment.