Skip to content

Commit 9f9b37e

Browse files
committed
Allow multiple envs in ~/.emacs.d/python-environments/
1 parent 2128b30 commit 9f9b37e

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

python-environment.el

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,16 @@
3434

3535
(defconst python-environment-version "0.0.0")
3636

37-
(defcustom python-environment-root
38-
(locate-user-emacs-file "python-environment")
39-
"Path to default Python virtual environment."
37+
(defcustom python-environment-directory
38+
(locate-user-emacs-file "python-environments")
39+
"Path to directory to store all Python virtual environments"
40+
:group 'python-environment)
41+
42+
(defcustom python-environment-default-root-name "default"
43+
"Default Python virtual environment name.
44+
This is a name of directory relative to `python-environment-directory'.
45+
Thus, typically the default virtual environment path is
46+
``~/.emacs.d/python-environments/default``."
4047
:group 'python-environment)
4148

4249
(defcustom python-environment-virtualenv
@@ -74,9 +81,14 @@
7481
(unless (= exit-code 0)
7582
(error "Command %S exits with error code %S." command exit-code))))
7683

84+
85+
(defun python-environment-root-path (&optional root)
86+
(expand-file-name (or root python-environment-default-root-name)
87+
python-environment-directory))
88+
7789
(defun python-environment--make-with-runner (proc-runner root virtualenv)
78-
(let ((path (convert-standard-filename (expand-file-name
79-
(or root python-environment-root))))
90+
(let ((path (convert-standard-filename
91+
(python-environment-root-path root)))
8092
(virtualenv (or virtualenv python-environment-virtualenv)))
8193
(unless (executable-find (car virtualenv))
8294
(error "Program named %S does not exist." (car virtualenv)))
@@ -108,7 +120,7 @@ For reason, see `python-environment-run-block'"
108120
(defun python-environment--existing (root &rest paths)
109121
(when paths
110122
(let ((full-path (expand-file-name (car paths)
111-
(or root python-environment-root))))
123+
(python-environment-root-path root))))
112124
(if (file-exists-p full-path)
113125
full-path
114126
(python-environment--existing (cdr paths))))))
@@ -147,7 +159,7 @@ For reason, see `python-environment-run-block'"
147159
"Run COMMAND installed in Python virtualenv located at ROOT
148160
asynchronously and return a deferred object.
149161
If ROOT is not specified, shared virtual environment specified by
150-
`python-environment-root' is used.
162+
`python-environment-default-root-name' is used.
151163
If VIRTUALENV (list of string) is specified, it is used instead of
152164
`python-environment-virtualenv'.
153165

test-python-environment.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ variable can be given as ENVIRONMENT (see `pye-with-mixed-environment')."
107107
(pye-eval-in-subprocess '(deferred:sync! (python-environment-make))
108108
`(("HOME" ,tmp-home)))
109109
(should (file-directory-p (expand-file-name
110-
".emacs.d/python-environment"
110+
".emacs.d/python-environments/default"
111111
tmp-home)))))
112112

113113
(provide 'test-python-environment)

0 commit comments

Comments
 (0)