diff --git a/pet.el b/pet.el index 65eac7e..4a4e7f2 100644 --- a/pet.el +++ b/pet.el @@ -600,11 +600,20 @@ Selects a virtualenv in the follow order: (default-directory (file-name-directory (pet-environment-path)))) (condition-case err (with-temp-buffer - (let ((exit-code (process-file program nil t nil "env" "list" "--json")) + (let ((exit-code (process-file program nil t nil "info" "--json")) (output (string-trim (buffer-string)))) (if (zerop exit-code) - (let* ((prefix (alist-get 'prefix (pet-environment))) - (env (car (member prefix (let-alist (pet-parse-json output) .envs))))) + (let* ((json-output (pet-parse-json output)) + (env-dirs (or (let-alist json-output .envs_dirs) + (let-alist json-output .envs\ directories))) + (env-name (alist-get 'name (pet-environment))) + (env (seq-find 'file-directory-p + (seq-map (lambda (dir) + (file-name-as-directory + (concat + (file-name-as-directory dir) + env-name))) + env-dirs)))) (or env (user-error "Please create the environment with `$ %s create --file %s' first" program (pet-environment-path)))) (user-error (buffer-string))))) diff --git a/test/pet-test.el b/test/pet-test.el index 23f88cf..e82a555 100644 --- a/test/pet-test.el +++ b/test/pet-test.el @@ -719,6 +719,7 @@ (describe "pet-virtualenv-root" :var ((project-root "/home/user/project/") (conda-path "/usr/bin/conda") + (conda-env-dirs '("/home/user/miniforge3/envs" "/home/user/.conda/envs")) (conda-virtualenv "/home/user/miniforge3/envs/project/") (poetry-path "/usr/bin/poetry") (poetry-virtualenv "/home/user/.cache/pypoetry/virtualenvs/project/") @@ -755,11 +756,22 @@ (it "should return the absolute path of the virtualenv for a project using `conda'" (spy-on 'pet-use-conda-p :and-return-value conda-path) (spy-on 'pet-environment-path :and-return-value "/home/user/project/environment.yml") - (spy-on 'call-process :and-call-fake (lambda (&rest _) (insert (format "{\"envs\": [\"%s\"]}" conda-virtualenv)) 0)) - (spy-on 'pet-environment :and-return-value `((prefix . ,conda-virtualenv))) + (spy-on 'call-process :and-call-fake + (lambda (&rest _) + (insert + (format "{\"envs_dirs\": [%s]}" + (string-join + (seq-map + (lambda (dir) + (format "\"%s\"" dir)) + conda-env-dirs) + ","))) + 0)) + (spy-on 'pet-environment :and-return-value `((name . "project"))) + (spy-on 'file-directory-p :and-call-fake (lambda (filename) (equal filename conda-virtualenv))) (expect (pet-virtualenv-root) :to-equal conda-virtualenv) (expect (assoc-default project-root pet-project-virtualenv-cache) :to-equal conda-virtualenv) - (expect 'call-process :to-have-been-called-with conda-path nil t nil "env" "list" "--json")) + (expect 'call-process :to-have-been-called-with conda-path nil t nil "info" "--json")) (it "should return the absolute path of the virtualenv for a project using `poetry'" (spy-on 'pet-use-conda-p :and-return-value nil)