From 54d6f8ea01b594fef9eff82bb27d0e5fc2e16156 Mon Sep 17 00:00:00 2001 From: Christopher Doris Date: Wed, 1 Dec 2021 19:27:16 +0000 Subject: [PATCH] update cmd --- README.md | 17 +++++++++++------ src/MicroMamba.jl | 13 +++++++++---- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 384306b..dddfd20 100644 --- a/README.md +++ b/README.md @@ -11,16 +11,20 @@ pkg> add MicroMamba ## Usage The API consists of the following three functions: +- `available()` returns true if MicroMamba is available on this system. Use this to check if the following functions will succeed. - `executable()` returns a path to a MicroMamba executable. - `version()` returns the version of the above executable. -- `available()` returns true if MicroMamba is available on this system. +- `cmd([args])` returns a command which calls MicroMamba. -In all three cases, MicroMamba will be downloaded and installed (local to the package) -if required. +In all three cases, MicroMamba will be downloaded and installed if required to the `micromamba` directory in your Julia depot (e.g. `~/.julia/micromamba`). -Note that `executable()` and `version()` can throw errors, such as if MicroMamba is not -supported on this platform. The `available()` function exists to check for this: if it -returns true, then the other functions will succeed. +## Example + +The following example creates a new environment and installs Python into it. + +```julia +run(MicroMamba.cmd(`--prefix ./env create python --yes --channel conda-forge`)) +``` ## Environment variables @@ -32,3 +36,4 @@ The following environment variables customise the behaviour of this package. - `{platform}` is replaced with the platform, such as `linux-64`. - `{version}` is replaced with the desired version, such as `latest` or `0.19.0`. - `JULIA_MICROMAMBA_VERSION`: If MicroMamba needs to be downloaded, this specifies the version. +- `JULIA_MICROMAMBA_ROOT_PREFIX`: The root prefix used by `cmd()`. Defaults to the `micromamba/root` directory of your Julia depo (e.g. `~/.julia/micromamba/root`). diff --git a/src/MicroMamba.jl b/src/MicroMamba.jl index b837583..a2476f3 100644 --- a/src/MicroMamba.jl +++ b/src/MicroMamba.jl @@ -159,14 +159,19 @@ end Construct a command which calls MicroMamba, optionally with additional arguments. -Unless the environment variable `MAMBA_ROOT_PREFIX` is set, the root prefix will be -set to `joinpath(DEPOT_PATH[1], "micromamba", "root")`. +By default, the root prefix is a folder in the Julia depot. It can be over-ridden with +the environment variable `JULIA_MICROMAMBA_ROOT_PREFIX`. To use the default root prefix +instead (e.g. as set by `~/.mambarc`) set this variable to the empty string. """ function cmd() - root = get(ENV, "MAMBA_ROOT_PREFIX") do + ans = `$(executable())` + root = get(ENV, "JULIA_MICROMAMBA_ROOT_PREFIX") do joinpath(DEPOT_PATH[1], "micromamba", "root") end - `$(executable()) --root-prefix $root` + if root != "" + ans = `$ans --root-prefix $root` + end + ans end cmd(args) = `$(cmd()) $args`