Checks that an environment exists, and that its installed packages
satisfy every package match spec. validate_env() is a query: it never
creates or changes an environment. With the micromamba backend, it
reports an environment that does not exist without starting a process
or installing micromamba.
When no micromamba binary is installed, the micromamba backend reads
the envs directory of its data directory and the package records in
conda-meta/ instead. It never installs micromamba.
Usage
validate_env(
...,
env_name = "condathis-env",
method = "auto",
verbose = "silent",
channels = NULL,
platform = NULL,
error = c("cancel", "continue")
)Arguments
- ...
Package match specs (MatchSpec strings), unnamed, as in
create_env(): character strings or character vectors, in order. With no specs,validate_env()only checks that the environment exists. An installed package satisfies a spec when it matches the name, version, build string and channel of the spec, as Existing environments increate_env()describes. The name match ignores case:"PyYAML"matchespyyaml. A spec without a channel matches a package fromchannels(see below). A spec with a channel, such as"conda-forge::zlib", matches only a package from that channel. A spec that is not compared, such as"zlib[md5=...]"or"zlib<2.*", never counts as satisfied. A spec for a virtual package, whose name starts with__("__cuda=12","__unix"), is not checked: it describes the host, and an environment never lists it.packages = <specs>still works, as increate_env(), andpackages = NULLonly checks that the environment exists. It is deprecated. It warns once per session (classcondathis_deprecated_packages_arg) when the call comes from the console, a script or the tests of the package that makes it. Calls made inside other packages do not warn, except in tests that use testthat's third edition (see condathis-conditions).Or one lock file, given by
env_definition(), such asenv_definition("conda-lock.yml"), without package specs. Then the environment must have exactly the packages that the lock lists for its platform, ascreate_env()compares them (see Existing environments there):platformwhen it is given, else any platform of the lock. Only a lock whose packages the backend reports can be compared, such as an@EXPLICIT, conda-lock or mambajs file with micromamba. Any other file, such asenvironment.yml, or a lock that has no packages forplatform, aborts with classcondathis_validate_env_unsupported_definition(alsocondathis_invalid_arg), with either value oferror. Package specs and a definition together, or two definitions, abort with classcondathis_validate_env_conflicting_args.These values abort with class
condathis_validate_env_invalid_packages:A named argument that
validate_env()does not have. Names are never abbreviated.A value that is not a character vector.
NAor"".A file name that ends in
.yml,.yaml,.jsonor.lock. Pass a lock file withenv_definition().
These classes abort too:
condathis_validate_env_positional_env_nameenv_nameis not given, the specs are two or more unnamed arguments, and the last of them is one string that names an existing environment. Specs given withpackages =or as one vector are never checked this way.condathis_parse_match_spec_invalid_name
a spec that condathis cannot read, such as"::".condathis_parse_match_spec_invalid_url
the URL of a package file that condathis cannot read.
Both parse errors also have class
condathis_invalid_arg. They abort witherror = "continue"too.- env_name
Character string with the environment name. It must be a plain directory name that is valid on Linux, macOS and Windows:
Not empty, and not
.or...Not starting with
-, and not ending with..Without path separators,
:,#, whitespace, control characters or<>"|?*.Not a Windows device name, such as
NULorCOM1(see Environment names increate_env()).
Invalid values abort with class
condathis_invalid_env_name.run(),run_bin(),run_pipeline()andrun_step()also accept anenv_path()value. The other functions reject it with classcondathis_env_path_read_only.- method
Character string naming the backend.
"auto"(the default) uses the backend that ownsenv_namewhen it exists, and otherwise the first available backend ingetOption("condathis.backend_priority")order (see condathis-options). Any name fromlist_registered_backend_names()selects that backend, and"micromamba"is built in. The name of a backend whose packagecondathisknows, such as"rattler"of therattlerthispackage, also selects it.condathisloads the package on first use."native"is a deprecated alias for"micromamba"(warns once per session). The 0.1.4 defaultc("native", "auto")is read as"native".If you name a backend other than the owner, functions that change the environment abort. The others warn and use the owner. The classes:
condathis_backend_not_installed: the package of the named backend is not installed.condathis_backend_mismatch: the named backend does not own the environment, and the function changes it.condathis_backend_mismatch_warning(a warning): the same, for a function that does not change the environment.condathis_backend_ambiguous_env: several backends have an environment of that name, andmethodnames none of them.condathis_invalid_method: an invalid value.
- verbose
Character string that controls the console output. One of:
"output": show the output of the command and the messages ofcondathis."silent": show nothing."cmd": show the command line."spinner": show only a spinner."full": show the command line, the output, and the backend's own log.
TRUEmeans"output"andFALSEmeans"silent". Every level except"silent"shows a spinner in interactive sessions. It also shows these messages and this warning when they occur (see condathis-conditions):condathis_micromamba_downloading(a message): no usablemicromambawas found, so it is downloaded. Queries, such aslist_envs(), never download it.condathis_env_lock_waitingandcondathis_cache_lock_waiting(messages): the call waits for another R session.condathis_install_micromamba_checksum_unavailable(a warning): the checksum of the downloadedmicromambacould not be checked.
Invalid values abort with class
condathis_invalid_verbose. The default is shown in Usage.The command line shown, the
cmdof a result and the messages ofcondathisshow the password and the token of a URL as*****.micromambadoes the same (https://user:*****@host/channel,https://host/t/*****/channel). The command still gets them.- channels
NULL(the default) or a non-empty character vector of channel names or URLs. WithNULL, a spec without a channel matches a package from any channel. Otherwise, a spec without a channel must match a package from one ofchannels, compared as increate_env(). A spec with a channel ignoreschannels. When a package matches a spec but comes from a channel that is not inchannels, the error names that channel. There is noadditional_channels: put those channels inchannels. Invalid values abort with classcondathis_validate_env_invalid_channels.- platform
NULL(the default) or a known conda platform name, such as"linux-64", asplatformofcreate_env()accepts. When given, the packages of the environment must be built for it (noarchpackages match any platform). Other values abort with classcondathis_validate_env_invalid_platform.- error
Character string. What happens when the environment does not exist or does not have the requested packages:
"cancel"(the default) aborts, and"continue"returnsFALSE. A backend failure always aborts. Invalid values abort with classcondathis_invalid_error.
Value
TRUE, invisibly, when the environment exists and has every
requested package.
Otherwise, with error = "cancel", it aborts with one of these
classes:
condathis_validate_env_env_not_found(alsocondathis_env_not_found)
the environment does not exist.condathis_validate_env_unsatisfied
a spec is not satisfied or the platform differs. The message lists each spec that is not satisfied.
With error = "continue", it returns FALSE with two attributes.
reason is one of "env_not_found", "platform_mismatch" and
"unsatisfied". unsatisfied is a character vector of the specs that
are not satisfied (every spec when the environment does not exist).
validate_env() reports a platform mismatch before unsatisfied specs.
For a lock file, unsatisfied lists the packages of the lock that the
environment does not have, as "<name>-<version>-<build>", and a
third attribute, unexpected, lists the packages of the environment
that the lock does not list.
A backend failure aborts with either value of error, with the class
condathis_validate_env_failed (also condathis_backend_error).
Details
It uses the same check as create_env(overwrite = FALSE). A spec without
a channel must match a package from channels, or from any channel when
channels is NULL (the default). Given
channels = c(channels, additional_channels) of a create_env() call
(by default "conda-forge"), validate_env() gives the same answer as
that call, with two exceptions. They exist because validate_env() only
reads:
When
methodnames a backend that does not own the environment,validate_env()warns with classcondathis_backend_mismatch_warningand checks the environment with its owner.create_env()aborts with classcondathis_backend_mismatch.When a backend cannot tell whether the environment exists,
validate_env()still lists its packages, and reports the listing's error if it fails. In that case,create_env()aborts with the classcondathis_backend_probe_failed.
See also
condathis-conditions for every condition class.
Other environments:
create_env(),
env_definition(),
env_exists(),
env_path(),
get_env_dir(),
install_packages(),
list_envs(),
list_packages(),
remove_env()
Examples
condathis::with_sandbox_dir({
# A missing environment: FALSE, with the reason
res <- condathis::validate_env(
"polyglot",
env_name = "no-such-env",
error = "continue"
)
print(res)
})
#> [1] FALSE
#> attr(,"reason")
#> [1] "env_not_found"
#> attr(,"unsatisfied")
#> [1] "polyglot"
if (FALSE) { # \dontrun{
condathis::with_sandbox_dir({
# A local channel shipped with condathis, with `polyglot`: a
# dependency-free script that runs on Linux, macOS and Windows.
channel <- system.file(
"extdata", "polyglot-channel",
package = "condathis"
)
condathis::create_env(
"polyglot",
env_name = "polyglot-env",
channels = channel
)
# TRUE, invisibly.
condathis::validate_env("polyglot", env_name = "polyglot-env")
# Also TRUE: `polyglot` comes from `channel`, as `create_env()` with
# the same channels requires.
condathis::validate_env(
"polyglot",
env_name = "polyglot-env",
channels = channel
)
# FALSE, with the reason and the specs that are not satisfied.
res <- condathis::validate_env(
"polyglot>=2",
env_name = "polyglot-env",
error = "continue"
)
print(attr(res, "reason"))
#> [1] "unsatisfied"
attr(res, "unsatisfied")
#> [1] "polyglot>=2"
})
} # }