Skip to content

Commit ee61741

Browse files
pkrygerwbolster
andauthored
Switch to use transient.el (#26)
transient is a replacement to magit-popup and even magit has already switched to use transient. This fixes #18. Co-authored-by: wouter bolsterlee <[email protected]>
1 parent 6e6ba84 commit ee61741

File tree

2 files changed

+78
-70
lines changed

2 files changed

+78
-70
lines changed

README.rst

+26-20
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 (dwim) 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
@@ -133,13 +130,13 @@ basics
133130
------
134131

135132
the typical usage pattern is to invoke the popup menu,
136-
named ``python-pytest-popup``.
133+
named ``python-pytest-dispatch``.
137134
it is a good idea to create a dedicated keybinding for this command,
138135
but it can also be run manually:
139136

140137
::
141138

142-
M-x python-pytest-popup
139+
M-x python-pytest-dispatch
143140

144141
this shows a dispatcher menu.
145142
change some switches and options,
@@ -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,9 +324,18 @@ 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")))
331+
332332
333+
`transient` lets you save defaults you want for it. Just
334+
select all options on ``python-pytest-dispatch`` and then
335+
- ``C-x C-s`` to save current settings as default and make
336+
them persistent,
337+
- ``C-x s`` to save current settings as default for the
338+
current emacs session.
333339

334340
contributing
335341
============
@@ -391,7 +397,7 @@ __ https://stable.melpa.org/
391397
------------------
392398

393399
* repopulate the popup with the previously used values
394-
when running ``python-pytest-popup`` from an output buffer.
400+
when running ``python-pytest-dispatch`` from an output buffer.
395401
(`#3 <https://github.com/wbolster/emacs-python-pytest/issues/3>`_)
396402

397403
0.2.2 (2018-02-26)

python-pytest.el

+52-50
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

@@ -116,44 +116,42 @@ When non-nil only ‘test_foo()’ will match, and nothing else."
116116
(defvar-local python-pytest--current-command nil
117117
"Current command; used in python-pytest-mode buffers.")
118118

119-
(fmakunbound 'python-pytest-popup)
120-
(makunbound 'python-pytest-popup)
121-
122-
;;;###autoload (autoload 'python-pytest-popup "python-pytest" nil t)
123-
(magit-define-popup python-pytest-popup
119+
;;;###autoload (autoload 'python-pytest-dispatch "python-pytest" nil t)
120+
(define-transient-command python-pytest-dispatch ()
124121
"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)
122+
:man-page "pytest"
123+
:incompatible '(("--verbose" "--verbose --verbose"))
124+
:value '("--color")
125+
["Switches"
126+
("-c" "color" "--color")
127+
("-d" "run doctests" "--doctest-modules")
128+
("-f" "failed first" "--failed-first")
129+
("-l" "show locals" "--showlocals")
130+
("-p" "debug on error" "--pdb")
131+
("-q" "quiet" "--quiet")
132+
("-s" "do not capture output" "--capture=no")
133+
("-t" "do not cut tracebacks" "--full-trace")
134+
("-v" "verbose" ("-v" "--verbose"))
135+
("-w" "very verbose" ("-vv" "--verbose --verbose"))
136+
("-x" "exit after first failure" "--exitfirst")]
137+
["Options"
138+
("=k" "only names matching expression" "-k=")
139+
("=m" "only marks matching expression" "-m=")
140+
(python-pytest-dispatch:--tb)
141+
("=x" "exit after N failures or errors" "--maxfail=")]
142+
[["Run tests"
143+
("t" "Test all" python-pytest)
144+
("r" "Repeat last test run" python-pytest-repeat)
145+
("x" "Test last-failed" python-pytest-last-failed)]
146+
["Run tests for specific files"
147+
("f" "Test file (dwim)" python-pytest-file-dwim)
148+
("F" "Test this file" python-pytest-file)
149+
("m" "Test multiple files" python-pytest-files)]
150+
["Run tests for current function/class"
151+
("d" "Test def/class (dwim)" python-pytest-function-dwim)
152+
("D" "Test this def/class" python-pytest-function)]])
153+
154+
(define-obsolete-function-alias 'python-pytest-popup 'python-pytest-dispatch)
157155

158156
;;;###autoload
159157
(defun python-pytest (&optional args)
@@ -388,13 +386,12 @@ With a prefix ARG, allow editing."
388386

389387
(defun python-pytest--get-buffer ()
390388
"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)))))
389+
(if (eq major-mode 'python-pytest-mode)
390+
(current-buffer) ;; re-use buffer
391+
(let ((name python-pytest-buffer-name))
392+
(when python-pytest-project-name-in-buffer-name
393+
(setq name (format "%s<%s>" name (python-pytest--project-name))))
394+
(get-buffer-create name))))
398395

399396
(defun python-pytest--process-sentinel (proc _state)
400397
"Process sentinel helper to run hooks after PROC finishes."
@@ -429,10 +426,15 @@ When present ON-REPLACEMENT is substituted, else OFF-REPLACEMENT is appended."
429426
(format "%s %s" option it)))
430427
args))
431428

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))
429+
(transient-define-argument python-pytest-dispatch:--tb ()
430+
:description "traceback style"
431+
:class 'transient-option
432+
:key "=t"
433+
:argument "--tb="
434+
:choices '("long" "short" "line" "native" "no"))
435+
436+
(defun python-pytest-arguments ()
437+
(transient-args 'python-pytest-dispatch))
436438

437439

438440
;; python helpers

0 commit comments

Comments
 (0)