-
-
Notifications
You must be signed in to change notification settings - Fork 155
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
Allow using conda environment.yml files to create environments #260
Comments
This feels like too far from how the virtualenvs work, which is to create an empty environment and then install the needed packages inside the session. What if in addition to
|
Cool! I didn't know about the As a workaround, I'll just call session._run(*[
'conda',
'env',
'update',
'--prefix',
session.virtualenv.location,
'--file',
str(path),
'--prune',], silent=True) |
+1 for loading env.yaml files. I use them quite a bit for pinning versions and such. |
I'm happy to see support for this, but I don't know much about Conda to be
honest. If Tim is willing to review I'd more than welcome a PR.
…On Tue, Apr 7, 2020 at 9:00 AM salotz ***@***.***> wrote:
+1 for loading env.yaml files. I use them quite a bit for pinning versions
and such.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#260 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAB5I42EEKE4DESYVALQMTTRLNEZ7ANCNFSM4JGNQJQA>
.
|
Its likely that I'll swing around to this at some point since I was basically building the same thing ad hoc in my own projects before I found nox. |
I can review a PR when it comes |
I have been using something similar to what @antonl gave above just to see if there are any problems.
I just remove the The only issue so far (and in my experience is a problem with conda and perhaps not really fixable with nox) is that the order of installation matters. If you install some things with pip in the session before running the above command, weird things will happen that break your env. I had to put this as the first thing. Otherwise it seems to work. From looking at the code for specific commands like Again I might get around to making a PR at some point, but I will run it like this for a while and see if there are any other issues. |
It looks good @salotz ! Do you have feedback so far about such usage ? |
My personal experience with the workaround provided by @salotz is that it takes far too much time to execute the update command everytime the session is run. So I would rather vote for the possibility to declare the environment file (this can be a conda yaml file or a pip requirements.txt file) in some new argument of What do you think ? |
That would be nice. One way to do this is to run something like |
This feels a bit outside of how |
not that I know unfortunately but I am not very familiar with the conda evolutions roadmap - I rather consider it as marginally evolving now |
I agree with this. And yes doing anything with conda is painfully slow other than keeping the same env and jamming lots of crap into it one at a time whenever an import fails. Which I think is the intended use case (not for specifying groups of dependencies for specific purposes). I'm actually just fine with the way things are and not having nox support them at all. Since there is a lot specific interactions between the order of install between conda and pip that I know how to deal with in my specific workflows, but that I am not curious in figuring out in general. Especially since I'm not particularly confident that this won't change very rapidly on conda's end.
Like tswast was saying this would be a totally different architecture. Yes that would be ideal, but it would be a different project. I've hand-rolled my own nox-like env-creator/task-runner just using invoke (https://github.com/salotz/jubeo/blob/master/modules/env.py) and while not trivial its not too onerous. My current project is to upgrade from invoke to pydoit, which would give you the incremental build aspect. |
In my current project the reason why I can not use |
@smarie oh cool! ya I haven't actually got into the meat of using doit for a lot of stuff yet. I agree that doit doesn't feel very pythonic, I'll check your thing out. But relevant to envs (and this thread somewhat) maybe we can work together on getting an env manager similar to |
@salotz thanks for the proposal and feedback! Unfortunately my bandwidth will be extremely limited in the upcoming months for family reasons - not really the time for opening new projects :) . However I'll be happy to contribute with ideas/PRs if the ground is solid. Note that maybe the |
I wouldn't be starting soon either, but I'll DM you when/if I do. TBH there isn't too much wheel to reinvent. I think we can all coexist in peace since its fully developer side stuff. :) |
There's a solution proposed here: #346 (comment) I'm still happy to review a PR, but again, I don't know enough about conda so it's really up to y'all. :) |
I am still playing with |
Just a quick note that I got a pretty lightweight script working with simple Sharing here in case it's useful for others! from yaml import safe_load
from pathlib import Path
# Parse the environment files we'll need later
environment = safe_load(Path("environment.yml").read_text())
conda = environment.get("dependencies")
requirements = conda.pop(-1).get("pip")
def install_environment(session):
for conda_pkg in conda:
session.conda_install(conda_pkg)
for pkg in requirements:
# We split each line in case there's a space for `-r`
session.install(*pkg.split())
session.install("-e", ".")
@nox.session(venv_backend="conda")
def build(session):
install_environment(session)
...now do other stuff |
thanks for sharing this, @choldgraf! I modified it a bit so all the conda/pip dependencies are installed in a single call, this is faster because each it only invokes conda's and pip's dependency resolver once. I'm using this: import nox
from yaml import safe_load
from pathlib import Path
environment = safe_load(Path("environment.yml").read_text())
conda = environment.get("dependencies")
requirements = conda.pop(-1).get("pip")
def install_environment(session):
session.conda_install(*conda)
session.install(*requirements)
@nox.session(venv_backend="conda")
def build(session):
install_environment(session) |
A fair bit of this code is taken from wntrblm/nox#260 (comment)
How would this feature be useful?
Conda has two environment creation commands:
conda create
andconda env create
. They differ in that the latter can reproduce an environment specified in aenvironment.yml
file, including packages that are installed usingpip
, while the former requires a list of packages.I would like to create specific frozen environments using
conda env create
and then run tests (or additional commands) in them.Describe the solution you'd like
One could create a
CondaEnv
subclass accepts a list of environment files and uses them to clone the environment. A side effect would be that it would ignore the python version.Describe alternatives you've considered
It is possible to just create the environments in two steps by parsing each
environment.yml
file, installing the conda dependencies, and then installing thepip
requirements.The text was updated successfully, but these errors were encountered: