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

Adding custom plugins support easily #71

Open
paquiteau opened this issue Jan 4, 2024 · 3 comments
Open

Adding custom plugins support easily #71

paquiteau opened this issue Jan 4, 2024 · 3 comments

Comments

@paquiteau
Copy link

paquiteau commented Jan 4, 2024

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.

@wbolster
Copy link
Owner

wbolster commented Jan 4, 2024

is there a way to not have that ‘local options’ section in the transient window at all? i'd like to avoid useless clutter for a feature that not many people will use and that doesn't do anything by default.

@paquiteau
Copy link
Author

Yes !

(defvar pytest-local-transient nil "Local transient options for pytest")

(transient-define-prefix python-pytest-dispatch ()
  "Show popup for running pytest."
  :man-page "pytest"
  :incompatible '(("--exitfirst" "--maxfail="))
  :value '("--color")
  ["Output"
   [("-c" "color" "--color")
    ("-q" "quiet" "--quiet")
    ("-s" "no output capture" "--capture=no")
    (python-pytest:-v)]]
  ["Selection, filtering, ordering"
   [(python-pytest:-k)
    (python-pytest:-m)
    "                                          "] ;; visual alignment
   [("--dm" "run doctests" "--doctest-modules")
    ("--nf" "new first" "--new-first")
    ("--sw" "stepwise" "--stepwise")
    ("--co" "collect only" "--collect-only")]]
  ["Failures, errors, debugging"
   [("-l" "show locals" "--showlocals")
    ("-p" "debug on error" "--pdb")
    ("-x" "exit after first failure" "--exitfirst")]
   [("--ff" "failed first" "--failed-first")
    ("--ft" "full tracebacks" "--full-trace")
    ("--mf" "exit after N failures or errors" "--maxfail=")
    ("--rx" "run xfail tests" "--runxfail")
    (python-pytest:--tb)
    ("--tr" "debug on each test" "--trace")]]
  ["Options for pytest-xdist"
   [(python-pytest:-n)]
   [("-f" "loop on failure" "--looponfail")]]
  ["Local Options"
    :setup-children (lambda (_) (transient-parse-suffixes transient--suffixes pytest-local-transient))
    :if-non-nil pytest-local-transient
    (:info "No Local options")]
  ["Run tests"
   [("t" "all" python-pytest)]
   [("r" "repeat" python-pytest-repeat)
    ("x" "last failed" python-pytest-last-failed)]
   [("f" "file (dwim)" python-pytest-file-dwim)
    ("F" "file (this)" python-pytest-file)]
   [("m" "files" python-pytest-files)
    ("M" "directories" python-pytest-directories)]
   [("d" "def/class (dwim)" python-pytest-function-dwim)
    ("D" "def/class (this)" python-pytest-function)]])

I overwrite the definition for prototyping , using transient-append-suffix was creating a new section each time ...

Also now we can define multiple CLI arguments like so

 ((python-mode (pytest-local-transient .
                                [(
                                    "b" "Backend to run" "--backend="
                                    :multi-value repeat
                                    :choices ("cpu" "gpu")
                                )
                                ("c" "custom command" "--custom-command")])
))

@paquiteau paquiteau reopened this Jan 4, 2024
@ns-rse
Copy link

ns-rse commented Sep 23, 2024

Oooh, this looks really interesting.

I just discovered some of the options to pytest-mpl such as the ability to add the flag --mpl-generate-summary={html,json,basic-html} option and it would be great to have these available in the transient buffer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants