Personal emacs config
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
1.4 KiB

  1. ;; This buffer is for text that is not saved, and for Lisp evaluation.
  2. ;; To create a file, visit it with C-x C-f and enter text in its buffer.
  3. (defun rlbr/get-venv-name (&optional library-root)
  4. "Generate venv name based off of the base-name of the library root"
  5. (file-name-base
  6. (directory-file-name
  7. (if library-root
  8. library-root
  9. (elpy-library-root)))))
  10. (defun rlbr/handle-name-conflicts (venv-name)
  11. "Deal with potential name conflicts in venv"
  12. (let ((venv-conflicts)
  13. (venv-partition-name))
  14. (setq venv-partition-name (rlbr/split-venv-with-number venv-name))
  15. (setq venv-conflicts
  16. (seq-filter
  17. (lambda (item) (string-equal (cdr item) venv-name))
  18. (mapcar #'rlbr/split-venv-with-number (pyvenv-virtualenv-list))))
  19. (when venv-conflicts
  20. (setcar venv-partition-name (1+ (apply 'max (mapcar #'car venv-conflicts)))))
  21. (rlbr/join-venv-with-number venv-partition-name)))
  22. (defun rlbr/setup-python-venv-dirlocals ()
  23. "Setup .dir-locals file in library root and tell vc system to ignore .dir-locals file"
  24. )
  25. (defun rlbr/init-python-venv-in-library-root ()
  26. "If no venv is specified in the library root .dir-locals file, prompt to either create one or use default"
  27. (let ((venv-name (rlbr/get-venv-name)))
  28. (setq venv-name (rlbr/handle-name-conflicts venv-name))
  29. (if (y-or-n-p (format "Create venv '%'?" venv-name))
  30. (pyvenv-create venv-name python-command))))