Skip to content

Support for conda as a language #1204

Closed

Description

@xhochy

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.

Activity

  1. asottile commented on Nov 4, 2019

    @asottile
    Member

    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)

    more docs on adding a language are here

  2. msarahan commented on Nov 4, 2019

    @msarahan

    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)

    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.

  3. xhochy commented on Nov 4, 2019

    @xhochy
    ContributorAuthor
    • 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.

  4. xhochy commented on Nov 4, 2019

    @xhochy
    ContributorAuthor
  5. msarahan commented on Nov 4, 2019

    @msarahan

    Specify the env name as a CLI flag (-n or -p):

    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
    
  6. added 4 commits that reference this issue on Dec 2, 2019
    4b8070d
    30ed0d1
    79779be
    cd8d795
  7. asottile commented on Jan 2, 2020

    @asottile
    Member

    This has been released as part of v1.21.0 -- thanks again for the issue and PR 🎉!

  8. mikeengland commented on Oct 5, 2021

    @mikeengland

    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

  9. xhochy commented on Oct 5, 2021

    @xhochy
    ContributorAuthor

    @mikeengland Please open a new issue with more context, e.g. to which hook you are referring and ping me there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions