From eeb8d1673c86983c1f03d7582f0ff7a2bd3632f3 Mon Sep 17 00:00:00 2001 From: Raphael Roberts Date: Sat, 28 Sep 2019 13:28:26 -0500 Subject: [PATCH] Added things in temporary python-conf.el file --- python-conf.el | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 python-conf.el diff --git a/python-conf.el b/python-conf.el new file mode 100644 index 0000000..b45c2f3 --- /dev/null +++ b/python-conf.el @@ -0,0 +1,34 @@ +;; This buffer is for text that is not saved, and for Lisp evaluation. +;; To create a file, visit it with C-x C-f and enter text in its buffer. + +(defun rlbr/get-venv-name (&optional library-root) + "Generate venv name based off of the base-name of the library root" + (file-name-base + (directory-file-name + (if library-root + library-root + (elpy-library-root))))) + +(defun rlbr/handle-name-conflicts (venv-name) + "Deal with potential name conflicts in venv" + (let ((venv-conflicts) + (venv-partition-name)) + (setq venv-partition-name (rlbr/split-venv-with-number venv-name)) + (setq venv-conflicts + (seq-filter + (lambda (item) (string-equal (cdr item) venv-name)) + (mapcar #'rlbr/split-venv-with-number (pyvenv-virtualenv-list)))) + (when venv-conflicts + (setcar venv-partition-name (1+ (apply 'max (mapcar #'car venv-conflicts))))) + (rlbr/join-venv-with-number venv-partition-name))) + +(defun rlbr/setup-python-venv-dirlocals () + "Setup .dir-locals file in library root and tell vc system to ignore .dir-locals file" + ) + +(defun rlbr/init-python-venv-in-library-root () + "If no venv is specified in the library root .dir-locals file, prompt to either create one or use default" + (let ((venv-name (rlbr/get-venv-name))) + (setq venv-name (rlbr/handle-name-conflicts venv-name)) + (if (y-or-n-p (format "Create venv '%'?" venv-name)) + (pyvenv-create venv-name python-command))))