Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a way to "conda env update" an environment: or more general conda commands. #346

Closed
mforbes opened this issue Sep 8, 2020 · 4 comments

Comments

@mforbes
Copy link

mforbes commented Sep 8, 2020

How would this feature be useful?
Another common way of provisioning conda environments is through an environment.yml file which can be used to update an environment with

conda env update --file environment.yml

Describe the solution you'd like
Not sure what is ideal here. This particular use-case could be solved by adding a command:

    session.conda_env_update("environment.yml")

or similar. This is easily implemented in session.py:

   ...
    def conda_env_update(self, envfile='environment.yml': str, **kwargs: Any) -> None:
        """Install invokes `conda env update`_ to update the session's
        environment.

        To install packages directly::

            session.conda_env_update('environment.yml')

        .. _conda env update:
        """
        venv = self._runner.venv

        prefix_args = ()  # type: Tuple[str, ...]
        if isinstance(venv, CondaEnv):
            prefix_args = ("--prefix", venv.location)
        elif not isinstance(venv, PassthroughEnv):  # pragma: no cover
            raise ValueError(
                "A session without a conda environment cannot update."
            )

        if "silent" not in kwargs:
            kwargs["silent"] = True

        self._run(
            "conda", "env", "update", *prefix_args, "--file", envfile, external="error", **kwargs
        )
   ...

however, it might be better to provide a more general fallback that allows users to customize commands for conda provisioning.

    session.conda("env update --file environment.yml")

possibly with variables for the --prefix argument. The other commands like conda_install could then be aliases to this more generic command. Note: there are some differences between conda install and conda env command (for example, --yes is not supported by the latter) which can cause confusion.

Related: one might also like to replace conda with mamba, so perhaps a kwarg could be provided. I will play with this a bit and try to make a reasonable PR/

@smarie
Copy link
Contributor

smarie commented Sep 8, 2020

Looks interesting @mforbes ! Could this be a possible duplicate of #260 ?

@mforbes
Copy link
Author

mforbes commented Sep 8, 2020

Yes - it looks very similar. Sorry, not sure how I missed that... I will review what was discussed there, then merge my comments and discussion with that issue and then close this.

@bjlittle
Copy link

bjlittle commented Nov 3, 2020

@mforbes and @smarie I've just discovered nox, and it's really pretty awesome! Congratulations 💯 🎉

I'd love to be able to create a conda environment based on an environment.yml so it would be great to know if this issue will mature into a pull-request?

@theacodes
Copy link
Collaborator

Closing in favor of #260

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

No branches or pull requests

4 participants