Skip to content

Commit 573f3a1

Browse files
committed
Switch to use transient
`transient` is a replacement to `magit-popup` and even `magit` has already switched to use `transient`. The switch is pretty idiomatic, however there are a few differences. The default layout is slightly different but I didn't try to replace it as the new one seems to match what `magit` is presenting these days. The concept of `:default-action` seems to be gone, so it is not replaced. The `magit-with-pre-popup-buffer` doesn't seem to have an obvious replacement, however the documentation for `transient--original-buffer` suggest that the `transient` is not changing the current buffer.
1 parent 6e6ba84 commit 573f3a1

File tree

2 files changed

+66
-64
lines changed

2 files changed

+66
-64
lines changed

README.rst

+16-17
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ __ https://www.gnu.org/software/emacs/
1818
__ https://pytest.org/
1919

2020
most functionality can be used via
21-
a dispatcher popup menu built using `magit-popup`__,
21+
a dispatcher popup menu built using `transient`__,
2222
which gives a look and feel
2323
similar to the fantastic `magit`__ package.
2424

25-
__ https://magit.vc/manual/magit-popup.html
25+
__ https://magit.vc/manual/transient
2626
__ https://magit.vc/
2727

2828

@@ -81,22 +81,19 @@ screenshot
8181
-s do not capture output (--capture=no)
8282
-t do not cut tracebacks (--full-trace)
8383
-v verbose (--verbose)
84+
-w very verbose (--verbose --verbose)
8485
-x exit after first failure (--exitfirst)
8586

8687
Options
87-
=k only names matching expression (-k)
88-
=m only marks matching expression (-m)
88+
=k only names matching expression (-k=)
89+
=m only marks matching expression (-m=)
8990
=t traceback style (--tb=)
90-
=x exit after N failures or errors (--maxfail="10")
91+
=x exit after N failures or errors (--maxfail=)
9192

92-
Run tests
93-
t Test all r Repeat last test run x Test last-failed
94-
95-
Run tests for specific files
96-
f Test file (dwim) F Test this file m Test multiple files
97-
98-
Run tests for current function/class
99-
d Test def/class (dwim) D Test this def/class
93+
Run tests Run tests for specific files Run tests for current function/class
94+
t Test all f Test file d Test def/class (dwim)
95+
r Repeat last test run F Test this file D Test this def/classx
96+
x Test last-failed m Test multiple files
10097

10198

10299
installation
@@ -316,9 +313,9 @@ extending the popup
316313

317314
when using pytest plugins that provide extra switches,
318315
it may be useful to integrate those into the popup.
319-
see the `magit-popup`__ manual for more information.
316+
see the `transient`__ manual for more information.
320317

321-
__ https://magit.vc/manual/magit-popup.html
318+
__ https://magit.vc/manual/transient
322319

323320
as an example, this will add a ``-z`` switch that,
324321
when enabled, will invoke ``pytest --zzz``:
@@ -327,8 +324,10 @@ when enabled, will invoke ``pytest --zzz``:
327324
328325
(use-package python-pytest
329326
:config
330-
(magit-define-popup-switch 'python-pytest-popup
331-
?z "Custom flag" "--zzz"))
327+
(transient-append-suffix
328+
'foo-popup2
329+
"-x"
330+
'("-z" "Custom flag" "--zzz")))
332331
333332
334333
contributing

python-pytest.el

+50-47
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
;; Author: wouter bolsterlee <[email protected]>
44
;; Version: 1.0.0
5-
;; Package-Requires: ((emacs "24.4") (dash "2.12.0") (dash-functional "2.12.0") (magit-popup "2.12.0") (projectile "0.14.0") (s "1.12.0"))
5+
;; Package-Requires: ((emacs "24.4") (dash "2.12.0") (dash-functional "2.12.0") (transient "20200719") (projectile "0.14.0") (s "1.12.0"))
66
;; Keywords: pytest, test, python, languages, processes, tools
77
;; URL: https://github.com/wbolster/emacs-python-pytest
88
;;
@@ -25,7 +25,7 @@
2525

2626
(require 'dash)
2727
(require 'dash-functional)
28-
(require 'magit-popup)
28+
(require 'transient)
2929
(require 'projectile)
3030
(require 's)
3131

@@ -119,41 +119,50 @@ When non-nil only ‘test_foo()’ will match, and nothing else."
119119
(fmakunbound 'python-pytest-popup)
120120
(makunbound 'python-pytest-popup)
121121

122+
(transient-define-argument python-pytest-popup:--tb ()
123+
:description "traceback style"
124+
:class 'transient-option
125+
:key "=t"
126+
:argument "--tb="
127+
:choices '("long" "short" "line" "native" "no"))
128+
122129
;;;###autoload (autoload 'python-pytest-popup "python-pytest" nil t)
123-
(magit-define-popup python-pytest-popup
130+
(define-transient-command python-pytest-popup ()
124131
"Show popup for running pytest."
125-
'python-pytest
126-
:switches
127-
'((?c "color" "--color" t)
128-
(?d "run doctests" "--doctest-modules")
129-
(?f "failed first" "--failed-first")
130-
(?l "show locals" "--showlocals")
131-
(?p "debug on error" "--pdb")
132-
(?q "quiet" "--quiet")
133-
(?s "do not capture output" "--capture=no")
134-
(?t "do not cut tracebacks" "--full-trace")
135-
(?v "verbose" "--verbose")
136-
(?w "very verbose" "-vv")
137-
(?x "exit after first failure" "--exitfirst"))
138-
:options
139-
'((?k "only names matching expression" "-k")
140-
(?m "only marks matching expression" "-m")
141-
(?t "traceback style" "--tb=" python-pytest--choose-traceback-style)
142-
(?x "exit after N failures or errors" "--maxfail="))
143-
:actions
144-
'("Run tests"
145-
(?t "Test all" python-pytest)
146-
(?r "Repeat last test run" python-pytest-repeat)
147-
(?x "Test last-failed" python-pytest-last-failed)
148-
"Run tests for specific files"
149-
(?f "Test file (dwim)" python-pytest-file-dwim)
150-
(?F "Test this file" python-pytest-file)
151-
(?m "Test multiple files" python-pytest-files)
152-
"Run tests for current function/class"
153-
(?d "Test def/class (dwim)" python-pytest-function-dwim)
154-
(?D "Test this def/class" python-pytest-function))
155-
:max-action-columns 3
156-
:default-action 'python-pytest-repeat)
132+
:man-page "pytest"
133+
:incompatible '(("--verbose" "--verbose --verbose"))
134+
:value '("--color")
135+
["Switches"
136+
("-c" "color" "--color")
137+
("-d" "run doctests" "--doctest-modules")
138+
("-f" "failed first" "--failed-first")
139+
("-l" "show locals" "--showlocals")
140+
("-p" "debug on error" "--pdb")
141+
("-q" "quiet" "--quiet")
142+
("-s" "do not capture output" "--capture=no")
143+
("-t" "do not cut tracebacks" "--full-trace")
144+
("-v" "verbose" ("-v" "--verbose"))
145+
("-w" "very verbose" ("-vv" "--verbose --verbose"))
146+
("-x" "exit after first failure" "--exitfirst")]
147+
["Options"
148+
("=k" "only names matching expression" "-k=")
149+
("=m" "only marks matching expression" "-m=")
150+
(python-pytest-popup:--tb)
151+
("=x" "exit after N failures or errors" "--maxfail=")]
152+
[["Run tests"
153+
("t" "Test all" python-pytest)
154+
("r" "Repeat last test run" python-pytest-repeat)
155+
("x" "Test last-failed" python-pytest-last-failed)]
156+
["Run tests for specific files"
157+
("f" "Test file (dwifdsafjda;sfjsdla;kfjm)" python-pytest-file-dwim)
158+
("F" "Test this file" python-pytest-file)
159+
("m" "Test multiple files" python-pytest-files)]
160+
["Run tests for current function/class"
161+
("d" "Test def/class (dwim)" python-pytest-function-dwim)
162+
("D" "Test this def/class" python-pytest-function)]])
163+
164+
(defun python-pytest-arguments ()
165+
(transient-args 'python-pytest-popup))
157166

158167
;;;###autoload
159168
(defun python-pytest (&optional args)
@@ -388,13 +397,12 @@ With a prefix ARG, allow editing."
388397

389398
(defun python-pytest--get-buffer ()
390399
"Get a create a suitable compilation buffer."
391-
(magit-with-pre-popup-buffer
392-
(if (eq major-mode 'python-pytest-mode)
393-
(current-buffer) ;; re-use buffer
394-
(let ((name python-pytest-buffer-name))
395-
(when python-pytest-project-name-in-buffer-name
396-
(setq name (format "%s<%s>" name (python-pytest--project-name))))
397-
(get-buffer-create name)))))
400+
(if (eq major-mode 'python-pytest-mode)
401+
(current-buffer) ;; re-use buffer
402+
(let ((name python-pytest-buffer-name))
403+
(when python-pytest-project-name-in-buffer-name
404+
(setq name (format "%s<%s>" name (python-pytest--project-name))))
405+
(get-buffer-create name))))
398406

399407
(defun python-pytest--process-sentinel (proc _state)
400408
"Process sentinel helper to run hooks after PROC finishes."
@@ -429,11 +437,6 @@ When present ON-REPLACEMENT is substituted, else OFF-REPLACEMENT is appended."
429437
(format "%s %s" option it)))
430438
args))
431439

432-
(defun python-pytest--choose-traceback-style (prompt _value)
433-
"Helper to choose a pytest traceback style using PROMPT."
434-
(completing-read
435-
prompt '("long" "short" "line" "native" "no") nil t))
436-
437440

438441
;; python helpers
439442

0 commit comments

Comments
 (0)