emacs-python-pytest icon indicating copy to clipboard operation
emacs-python-pytest copied to clipboard

Adding custom plugins support easily

Open paquiteau opened this issue 6 months ago • 2 comments

Hello there, I am using your package more and more, and keep liking it. In my python projects I usually defines some custom command lines arguments for pytest, and found a nice way to add them dynamically to the transient menu.

I rely on .dir-locals.el for projects variables, to store custom transients menu and load them accordingly:

(defvar pytest-local-transient '((:info "No local options")) "Local options for creating local prefixes." )

;; Custom Group specification 
;; https://www.gnu.org/software/emacs/manual/html_mono/transient.html#Group-Specifications
(transient-append-suffix 'python-pytest-dispatch '(-2)
 ["Local Options" 
  :setup-children (lambda (_) 
     (list (transient-parse-suffix transient--suffixes pytest-local-transient)))
]))

And then define custom transient suffix in a .dir-locals.el file:

;; $MY_PYTHON_PROJECT/.dir-locals.el
((python-mode (pytest-local-transient .
                ((
                    "b" "Backend to run" "--backend="
                    :multi-value repeat
                    :choices ("cpu" "gpu")
                )))
))

Let me know if you would like to have this as a PR, but as it is fairly minimal coda I think it will still be happy if it stayed comfy in my config.

paquiteau avatar Jan 04 '24 13:01 paquiteau