Skip to content

Commit

Permalink
micromamba support
Browse files Browse the repository at this point in the history
  • Loading branch information
wyuenho committed Jun 24, 2024
1 parent c23dea5 commit 87807fe
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
4 changes: 3 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ Supported Python Virtual Environment Tools
it unless you are using Homebrew on macOS)
- `uv <https://github.com/astral-sh/uv>`_
- `docker <https://hub.docker.com/_/python>`_
- conda/mamba/micromamba (preliminary)
- `conda <https://docs.conda.io/en/latest/>`_
- `mamba <https://mamba.readthedocs.io/en/latest/installation/mamba-installation.html>`_
- `micromamba <https://mamba.readthedocs.io/en/latest/installation/micromamba-installation.html>`_
- Whatever is on your ``VIRTUAL_ENV`` environment variable
- Even when you aren't in a virtual environment

Expand Down
11 changes: 7 additions & 4 deletions pet.el
Original file line number Diff line number Diff line change
Expand Up @@ -596,17 +596,20 @@ Selects a virtualenv in the follow order:
(when-let ((ev (getenv "VIRTUAL_ENV")))
(expand-file-name ev))
(let ((venv-path
(cond ((when-let ((program (pet-use-conda-p))
(default-directory (file-name-directory (pet-environment-path))))
(cond ((when-let* ((program (pet-use-conda-p))
(default-directory (file-name-directory (pet-environment-path)))
(program-args (if (string-match-p "micromamba" program)
'("env" "list" "--json")
'("info" "--json"))))
(condition-case err
(with-temp-buffer
(let ((exit-code (process-file program nil t nil "info" "--envs" "--json"))
(let ((exit-code (apply 'process-file program nil t nil program-args))
(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)))))
(or env
(user-error "Please create the environment with `$ %s create -f %s' first" program (pet-environment-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)))))
((when-let ((program (pet-use-poetry-p))
Expand Down
18 changes: 15 additions & 3 deletions test/pet-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,8 @@

(describe "when using `pre-commit'"
(before-each
(spy-on 'pet-use-pre-commit-p :and-return-value "/usr/bin/pre-commit"))
(spy-on 'pet-use-pre-commit-p :and-return-value "/usr/bin/pre-commit")
(spy-on 'pet--executable-find :and-return-value nil))

(it "should return the absolute path to the executable if hook and hook repo are found and the executable is found in hook repo"
(spy-on 'pet-pre-commit-config-has-hook-p :and-return-value t)
Expand Down Expand Up @@ -718,7 +719,9 @@
(describe "pet-virtualenv-root"
:var ((project-root "/home/user/project/")
(conda-path "/usr/bin/conda")
(conda-virtualenv "/home/user/.conda/envs/project/")
(conda-virtualenv "/home/user/miniforge3/envs/project/")
(micromamba-path "/usr/bin/micromamba")
(micromamba-virtualenv "/home/user/micromamba/envs/project/")
(poetry-path "/usr/bin/poetry")
(poetry-virtualenv "/home/user/.cache/pypoetry/virtualenvs/project/")
(pipenv-path "/usr/bin/pipenv")
Expand Down Expand Up @@ -758,7 +761,16 @@
(spy-on 'pet-environment :and-return-value `((prefix . ,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 "info" "--envs" "--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 `micromamba'"
(spy-on 'pet-use-conda-p :and-return-value micromamba-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\"]}" micromamba-virtualenv)) 0))
(spy-on 'pet-environment :and-return-value `((prefix . ,micromamba-virtualenv)))
(expect (pet-virtualenv-root) :to-equal micromamba-virtualenv)
(expect (assoc-default project-root pet-project-virtualenv-cache) :to-equal micromamba-virtualenv)
(expect 'call-process :to-have-been-called-with micromamba-path nil t nil "env" "list" "--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)
Expand Down

0 comments on commit 87807fe

Please sign in to comment.