Skip to content

Instantly share code, notes, and snippets.

@andcarnivorous
Last active May 1, 2022 10:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andcarnivorous/9a9fad7a267cba8f7840f338ad76cbf5 to your computer and use it in GitHub Desktop.
Save andcarnivorous/9a9fad7a267cba8f7840f338ad76cbf5 to your computer and use it in GitHub Desktop.
pyconf.el
;;; pyconf PYCONF
(defun runpythonproc (command-s path-to-file exec-dir &optional params venv env-vars)
(unless venv (setq venv ""))
(unless params (setq params ""))
(unless env-vars (setq env-vars '()))
(if venv
(progn
(pyvenv-deactivate)
(pyvenv-activate venv))
(setq venv ""))
(if (> (length params) 0)
(setq built-params params)
(setq built-params ""))
(if (> (length env-vars) 0)
(setq built-env-vars (string-join env-vars " "))
(setq built-env-vars ""))
(progn
(let ((default-directory exec-dir))
;(print (string-join (list built-env-vars command-s path-to-file built-params) " "))
;(print built-params)
(async-shell-command (string-join
(list built-env-vars command-s path-to-file built-params) " ") (format "*PyConf %s*" path-to-file)))))
(defclass python-config ()
((name :initarg :name
:type string
:custom string)
(pyconf-exec-command :initarg :pyconf-exec-command
:type string
:custom string)
(pyconf-file-to-exec :initarg :pyconf-file-to-exec
:type string
:custom string)
(pyconf-path-to-exec :initarg :pyconf-path-to-exec
:type string
:custom string
:initform ".")
(pyconf-params :initarg :pyconf-params
:type string
:custom string)
(pyconf-venv :initarg :pyconf-venv
:type string
:custom string
:initform "")
(pyconf-env-vars :initarg :pyconf-env-vars
:type list
:custom list
:initform '())))
(defun pyconf-execute-config (pyconf-config-obj)
(runpythonproc (slot-value pyconf-config-obj 'pyconf-exec-command)
(slot-value pyconf-config-obj 'pyconf-file-to-exec)
(slot-value pyconf-config-obj 'pyconf-path-to-exec)
(slot-value pyconf-config-obj 'pyconf-params)
(slot-value pyconf-config-obj 'pyconf-venv)
(slot-value pyconf-config-obj 'pyconf-env-vars)))
(setq pyconf-config-list '())
(defun pyconf-start (choice)
"Prompts to choose one of the available configurations and then executes it"
(interactive
(let ((completion-ignore-case t))
(list (completing-read "Choose Config: " pyconf-config-list nil t))))
(pyconf-execute-config (cdr (assoc choice pyconf-config-list)))
choice)
(defun pyconf-add-config (config-listp)
"Adds a pyconf-config object to the configurations list"
(let ((config-name (slot-value config-listp 'name)))
(add-to-list 'pyconf-config-list `(,(slot-value config-listp 'name) . ,config-listp))))
(defun pyconf-add-configurations (configurations-list)
(dolist (configuration-item configurations-list)
(pyconf-add-config configuration-item)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment