You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be nice to have support for conda in pre-commit as a "language"/environment manager. This would enable setups where packages are installed through conda. The typical usage for this will be for Python and R setups (e.g. lorenzwalthert/precommit#99) where conda is most popular but as conda is language independent.
The implementation would work as follows:
A hook is expected to have a requirements.txt that is installed using conda create -p <prefix> --file=requirements.txt. I would not use the conda environment.yml as this already dictates the name of the environment.
The hook is run using conda run -p <prefix> <entry>
We will use the conda executable that is available on the PATH.
Note: I would volunteer to implement this once there are some 👍 that the proposal is sound.
seems fine, you can go ahead and start implementing if you'd like -- a few questions:
isn't conda create -f environment.yml more standard?
can we avoid conda run and just use PATH to run the executables (this'll be faster and is more consistent with the current languages)?
how does this interact with language_version? (this can be ignored for the first pass implementation)
how does this interact with additional_dependencies? (this can be ignored for the first pass implementation)
should we bootstrap conda for systems where it isn't installed (this can be ignored for the first pass implementation and just depend on system-installed conda)
isn't conda create -f environment.yml more standard?
I wouldn't say either is standard. It's just whichever fits your workflow best. environment.yml allows you to specify channels and pip packages in a way that the other approach does not.
The name in the environment.yml file can be overridden by passing an env name to the conda env create command, so don't let that block you from using it.
can we avoid conda run and just use PATH to run the executables (this'll be faster and is more consistent with the current languages)?
That'll work for probably about 98% of the time. Anything that requires environment variables to be set (which is done via shell scripts that are sourced by activation) won't work. There's a few notable things here - java being the main concern with JAVAHOME.
should we bootstrap conda for systems where it isn't installed (this can be ignored for the first pass implementation and just depend on system-installed conda)
isn't conda create -f environment.yml more standard?
As mentioned above, this sadly forces a name, thus I'm omitting it. Still, I posted this in the conda gitter with the hope of some comments about that.
can we avoid conda run and just use PATH to run the executables (this'll be faster and is more consistent with the current languages)?
This will work with most, but not all executables. conda allows to set custom environment variables on environment activation. They could be required for some tools.
how does this interact with language_version? (this can be ignored for the first pass implementation)
We could force the conda version here but I don't think this would be helpful, especially if we were using a pre-installed conda.
how does this interact with additional_dependencies? (this can be ignored for the first pass implementation)
These can just be passed as additional arguments to the conda create call.
should we bootstrap conda for systems where it isn't installed (this can be ignored for the first pass implementation and just depend on system-installed conda)
miniconda normally asks you to accept a license on installation. I'm not sure whether it is ok to skip this when installing conda in the background.
The name in the environment.yml file can be overridden by passing an env name to the conda env create command, so don't let that block you from using it.
conda env create -h
usage: conda-env create [-h] [-f FILE] [-n ENVIRONMENT | -p PATH] [--force]
[--json] [-v] [-q]
[remote_definition]
Create an environment based on an environment file
Options:
positional arguments:
remote_definition remote environment definition / IPython notebook
optional arguments:
-h, --help Show this help message and exit.
-f FILE, --file FILE environment definition file (default: environment.yml)
--force force creation of environment (removing a previously
existing environment of the same name).
Target Environment Specification:
-n ENVIRONMENT, --name ENVIRONMENT
Name of environment.
-p PATH, --prefix PATH
Full path to environment location (i.e. prefix).
Output, Prompt, and Flow Control Options:
--json Report all output as json. Suitable for using conda
programmatically.
-v, --verbose Use once for info, twice for debug, three times for
trace.
-q, --quiet Do not display progress bar.
examples:
conda env create
conda env create -n name
conda env create vader/deathstar
conda env create -f=/path/to/environment.yml
conda env create -f=/path/to/requirements.txt -n deathstar
conda env create -f=/path/to/requirements.txt -p /home/user/software/deathstar
I noticed the default environment.yml sets the default channel. Where I am this is blocked and this causes the pre-commit install to fail. In other environments I use ‘nodefault’ and conda-forge instead. Is there a way of overriding the default environment.yml template? Thanks
Activity
asottile commentedon Nov 4, 2019
seems fine, you can go ahead and start implementing if you'd like -- a few questions:
conda create -f environment.ymlmore standard?conda runand just usePATHto run the executables (this'll be faster and is more consistent with the currentlanguages)?language_version? (this can be ignored for the first pass implementation)additional_dependencies? (this can be ignored for the first pass implementation)condafor systems where it isn't installed (this can be ignored for the first pass implementation and just depend on system-installedconda)more docs on adding a language are here
msarahan commentedon Nov 4, 2019
I wouldn't say either is standard. It's just whichever fits your workflow best. environment.yml allows you to specify channels and pip packages in a way that the other approach does not.
The name in the environment.yml file can be overridden by passing an env name to the conda env create command, so don't let that block you from using it.
That'll work for probably about 98% of the time. Anything that requires environment variables to be set (which is done via shell scripts that are sourced by activation) won't work. There's a few notable things here - java being the main concern with JAVAHOME.
For installation purposes, you might want to use the standalone executables: https://repo.anaconda.com/pkgs/misc/conda-execs/
These won't work for activation, but if you only do the PATH modification, it doesn't matter.
xhochy commentedon Nov 4, 2019
As mentioned above, this sadly forces a name, thus I'm omitting it. Still, I posted this in the conda gitter with the hope of some comments about that.
This will work with most, but not all executables.
condaallows to set custom environment variables on environment activation. They could be required for some tools.We could force the conda version here but I don't think this would be helpful, especially if we were using a pre-installed conda.
These can just be passed as additional arguments to the
conda createcall.minicondanormally asks you to accept a license on installation. I'm not sure whether it is ok to skip this when installing conda in the background.xhochy commentedon Nov 4, 2019
@msarahan Which env var would that be? There is not mention of it on either https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#creating-an-environment-from-an-environment-yml-file nor https://docs.conda.io/projects/conda/en/latest/user-guide/concepts/environments.html
msarahan commentedon Nov 4, 2019
Specify the env name as a CLI flag (-n or -p):
Support for conda as a language
Support for conda as a language
Support for conda as a language
Support for conda as a language
asottile commentedon Jan 2, 2020
This has been released as part of v1.21.0 -- thanks again for the issue and PR 🎉!
mikeengland commentedon Oct 5, 2021
I noticed the default environment.yml sets the default channel. Where I am this is blocked and this causes the pre-commit install to fail. In other environments I use ‘nodefault’ and conda-forge instead. Is there a way of overriding the default environment.yml template? Thanks
xhochy commentedon Oct 5, 2021
@mikeengland Please open a new issue with more context, e.g. to which hook you are referring and ping me there.