Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let user customize conda root, and check env vars. #36

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions pet.el
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ and nil otherwise."
:group 'pet
:type '(repeat string))

(defcustom pet-condaish-root nil
"Absolute path to the root directory where conda/(micro)mamba environments are stored."
:group 'pet
:type 'string)



(defun pet--executable-find (command &optional remote)
Expand Down Expand Up @@ -537,6 +542,19 @@ must both be installed into the current project first."
(concat (file-name-as-directory repo-dir) "py_env-*")
t)))))

(defun pet-condaish-env-path ()
"Get the path to the current conda/(micro)mamba environment based on environment variables `pet-condaish-root'."
(let ((root
(or pet-condaish-root
(getenv "CONDA_ROOT")
(getenv "MAMBA_ROOT_PREFIX"))))
(if root
(concat (file-name-as-directory root)
"envs/"
(alist-get 'name (pet-environment)))
nil)))




;;;###autoload
Expand Down Expand Up @@ -606,6 +624,7 @@ Selects a virtualenv in the follow order:
(let* ((prefix (alist-get 'prefix (pet-environment)))
(env (car (member prefix (let-alist (pet-parse-json output) .envs)))))
(or env
(pet-condaish-env-path)
(user-error "Please create the environment with `$ %s create --file %s' first" program (pet-environment-path))))
(user-error (buffer-string)))))
(error (pet-report-error err)))))
Expand Down