1

I'm trying to modify a transient defined in python-pytest and add some suffix for pytest-django extension. I would like one of my arguments to be "active". It is similar to https://emacs.stackexchange.com/a/66462/13945, but I cannot modify the original transient's :value.

The following image should explain what I want (my stuff is in the group "Options for pytest-django"): example of modified transient

I define a variable that the user can customize and that will be the default for my suffix (and an helper function). Then I define the new argument that I would like to be set active by default.

My code is as follows:

(defcustom DJANGO_SETTINGS_MODULE nil
  "django settings module used by pytest."
  :type '(string)
  )

(defun python-pytest-django:--ds__init ()
  "Init value of --ds suffix"
  (concat "--ds " DJANGO_SETTINGS_MODULE))

(transient-define-argument python-pytest-django:--ds ()
  :description "Set DJANGO_SETTINGS_MODULE."
  :class 'transient-option
  :argument (python-pytest-django:--ds__init)
  ;; :init-value '(python-pytest-django:--ds__init)  ;; 🠮 transient-setup: Invalid function:...
  ;; :value '(python-pytest-django:--ds__init)  ;; 🠮 invalid-slot-name
  :allow-empty nil
  :key "--ds"
  :reader 'python-pytest--read-quoted-argument-for-short-flag)

(defun append-pytest-django-suffixes ()
  "Append options related to pytest-django to python-pytest transient."
  (transient-append-suffix 'python-pytest-dispatch '(-2)  ;; just before the last group
    ["Options for pytest-django"
     ("--rd" "reuse DB" "--reuse-db")
     ("--cd" "create DB" "--create-db")
     (python-pytest-django:--ds)
     ]))

(append-pytest-django-suffixes)

1 Answer 1

1

I was using the macro transient-define-argument wrong. As explained in the Developer Quick Start Guide, I can use :init-value to achieve my goal:

(transient-define-argument python-pytest-django:--ds ()
  :description "Set DJANGO_SETTINGS_MODULE."
  :class 'transient-option
  :argument "--ds "
  :init-value (lambda (obj)
                (setf
                 (slot-value obj 'value)
                 DJANGO_SETTINGS_MODULE))
  :allow-empty nil
  :key "--ds"
  )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.