Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to use transient.el #26

Merged
merged 5 commits into from
Aug 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 26 additions & 20 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ __ https://www.gnu.org/software/emacs/
__ https://pytest.org/

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

__ https://magit.vc/manual/magit-popup.html
__ https://magit.vc/manual/transient
__ https://magit.vc/


Expand Down Expand Up @@ -81,22 +81,19 @@ screenshot
-s do not capture output (--capture=no)
-t do not cut tracebacks (--full-trace)
-v verbose (--verbose)
-w very verbose (--verbose --verbose)
-x exit after first failure (--exitfirst)

Options
=k only names matching expression (-k)
=m only marks matching expression (-m)
=k only names matching expression (-k=)
=m only marks matching expression (-m=)
=t traceback style (--tb=)
=x exit after N failures or errors (--maxfail="10")
=x exit after N failures or errors (--maxfail=)

Run tests
t Test all r Repeat last test run x Test last-failed

Run tests for specific files
f Test file (dwim) F Test this file m Test multiple files

Run tests for current function/class
d Test def/class (dwim) D Test this def/class
Run tests Run tests for specific files Run tests for current function/class
pkryger marked this conversation as resolved.
Show resolved Hide resolved
t Test all f Test file (dwim) d Test def/class (dwim)
r Repeat last test run F Test this file D Test this def/classx
x Test last-failed m Test multiple files


installation
Expand Down Expand Up @@ -133,13 +130,13 @@ basics
------

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

::

M-x python-pytest-popup
M-x python-pytest-dispatch

this shows a dispatcher menu.
change some switches and options,
Expand Down Expand Up @@ -316,9 +313,9 @@ extending the popup

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

__ https://magit.vc/manual/magit-popup.html
__ https://magit.vc/manual/transient

as an example, this will add a ``-z`` switch that,
when enabled, will invoke ``pytest --zzz``:
Expand All @@ -327,9 +324,18 @@ when enabled, will invoke ``pytest --zzz``:

(use-package python-pytest
:config
(magit-define-popup-switch 'python-pytest-popup
?z "Custom flag" "--zzz"))
(transient-append-suffix
'foo-popup2
"-x"
'("-z" "Custom flag" "--zzz")))


`transient` lets you save defaults you want for it. Just
select all options on ``python-pytest-dispatch`` and then
- ``C-x C-s`` to save current settings as default and make
them persistent,
- ``C-x s`` to save current settings as default for the
current emacs session.

contributing
============
Expand Down Expand Up @@ -391,7 +397,7 @@ __ https://stable.melpa.org/
------------------

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

0.2.2 (2018-02-26)
Expand Down
102 changes: 52 additions & 50 deletions python-pytest.el
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

;; Author: wouter bolsterlee <wouter@bolsterl.ee>
;; Version: 1.0.0
;; 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"))
;; Package-Requires: ((emacs "24.4") (dash "2.12.0") (dash-functional "2.12.0") (transient "20200719") (projectile "0.14.0") (s "1.12.0"))
pkryger marked this conversation as resolved.
Show resolved Hide resolved
;; Keywords: pytest, test, python, languages, processes, tools
;; URL: https://github.com/wbolster/emacs-python-pytest
;;
Expand All @@ -25,7 +25,7 @@

(require 'dash)
(require 'dash-functional)
(require 'magit-popup)
(require 'transient)
(require 'projectile)
(require 's)

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

(fmakunbound 'python-pytest-popup)
(makunbound 'python-pytest-popup)

;;;###autoload (autoload 'python-pytest-popup "python-pytest" nil t)
(magit-define-popup python-pytest-popup
;;;###autoload (autoload 'python-pytest-dispatch "python-pytest" nil t)
(define-transient-command python-pytest-dispatch ()
"Show popup for running pytest."
'python-pytest
:switches
'((?c "color" "--color" t)
(?d "run doctests" "--doctest-modules")
(?f "failed first" "--failed-first")
(?l "show locals" "--showlocals")
(?p "debug on error" "--pdb")
(?q "quiet" "--quiet")
(?s "do not capture output" "--capture=no")
(?t "do not cut tracebacks" "--full-trace")
(?v "verbose" "--verbose")
(?w "very verbose" "-vv")
(?x "exit after first failure" "--exitfirst"))
:options
'((?k "only names matching expression" "-k")
(?m "only marks matching expression" "-m")
(?t "traceback style" "--tb=" python-pytest--choose-traceback-style)
(?x "exit after N failures or errors" "--maxfail="))
:actions
'("Run tests"
(?t "Test all" python-pytest)
(?r "Repeat last test run" python-pytest-repeat)
(?x "Test last-failed" python-pytest-last-failed)
"Run tests for specific files"
(?f "Test file (dwim)" python-pytest-file-dwim)
(?F "Test this file" python-pytest-file)
(?m "Test multiple files" python-pytest-files)
"Run tests for current function/class"
(?d "Test def/class (dwim)" python-pytest-function-dwim)
(?D "Test this def/class" python-pytest-function))
:max-action-columns 3
:default-action 'python-pytest-repeat)
:man-page "pytest"
:incompatible '(("--verbose" "--verbose --verbose"))
:value '("--color")
["Switches"
("-c" "color" "--color")
("-d" "run doctests" "--doctest-modules")
("-f" "failed first" "--failed-first")
("-l" "show locals" "--showlocals")
("-p" "debug on error" "--pdb")
("-q" "quiet" "--quiet")
("-s" "do not capture output" "--capture=no")
("-t" "do not cut tracebacks" "--full-trace")
("-v" "verbose" ("-v" "--verbose"))
("-w" "very verbose" ("-vv" "--verbose --verbose"))
("-x" "exit after first failure" "--exitfirst")]
["Options"
("=k" "only names matching expression" "-k=")
("=m" "only marks matching expression" "-m=")
(python-pytest-dispatch:--tb)
("=x" "exit after N failures or errors" "--maxfail=")]
[["Run tests"
("t" "Test all" python-pytest)
("r" "Repeat last test run" python-pytest-repeat)
("x" "Test last-failed" python-pytest-last-failed)]
["Run tests for specific files"
("f" "Test file (dwim)" python-pytest-file-dwim)
("F" "Test this file" python-pytest-file)
("m" "Test multiple files" python-pytest-files)]
["Run tests for current function/class"
("d" "Test def/class (dwim)" python-pytest-function-dwim)
("D" "Test this def/class" python-pytest-function)]])

(define-obsolete-function-alias 'python-pytest-popup 'python-pytest-dispatch)

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

(defun python-pytest--get-buffer ()
"Get a create a suitable compilation buffer."
(magit-with-pre-popup-buffer
(if (eq major-mode 'python-pytest-mode)
(current-buffer) ;; re-use buffer
(let ((name python-pytest-buffer-name))
(when python-pytest-project-name-in-buffer-name
(setq name (format "%s<%s>" name (python-pytest--project-name))))
(get-buffer-create name)))))
(if (eq major-mode 'python-pytest-mode)
(current-buffer) ;; re-use buffer
(let ((name python-pytest-buffer-name))
(when python-pytest-project-name-in-buffer-name
(setq name (format "%s<%s>" name (python-pytest--project-name))))
(get-buffer-create name))))

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

(defun python-pytest--choose-traceback-style (prompt _value)
pkryger marked this conversation as resolved.
Show resolved Hide resolved
"Helper to choose a pytest traceback style using PROMPT."
(completing-read
prompt '("long" "short" "line" "native" "no") nil t))
(transient-define-argument python-pytest-dispatch:--tb ()
:description "traceback style"
:class 'transient-option
:key "=t"
:argument "--tb="
:choices '("long" "short" "line" "native" "no"))

(defun python-pytest-arguments ()
(transient-args 'python-pytest-dispatch))


;; python helpers
Expand Down