Skip to content
This repository has been archived by the owner on Jan 30, 2019. It is now read-only.

Add support for creating envs from requirements.txt files via pip #172

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from

Conversation

dan-blanchard
Copy link

I found myself frequently wishing this existed, so I added it.

It will use conda packages if available, and fallback to pip otherwise.

There was a bit of nonsense necessary to get editable packages working
properly, but it all works.

…es via pip.

I found myself frequently wishing this existed, so I added it.

It will use conda packages if available, and fallback to pip otherwise.

There was a bit of nonsense necessary to get editable packages working
properly, but it all works.
@dan-blanchard
Copy link
Author

I tweaked this a bit so that it now pulls in all dependencies of packages in requirements.txt and checks to see if those are available as conda packages. That way people don't end up with pip-installed numpy and other stuff like that.

@dan-blanchard
Copy link
Author

All tests are now passing, so this is good for review.

@dan-blanchard
Copy link
Author

I have no idea why this build is failing on Travis when it works fine on my machine.

"""
pip_cmd = ('pip', 'install', '--src', temp_dir, '--download', temp_dir,
'--no-use-wheel', '-r', requirements_path)
try:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment elsewhere. Please use isdir to check if dir exists, then create if necessary rather than try/except.

@msarahan
Copy link
Collaborator

Sorry I don't have time to help you troubleshoot Travis right now. I would like to merge this if you can get it past Travis. Please see my other comments. This is a nice addition - thanks for your work on it.

@malev
Copy link
Contributor

malev commented Oct 27, 2015

@dan-blanchard what's gonna happen if in the same directory you have an environment.yml file and a requirements.txt file?
Also, I think you sould take a look at https://github.com/conda/conda-env/tree/develop/conda_env/specs
You could have a new spec called requirements_txt_spec (maybe)
And this one should return a env like object.
This is how we architecture the different ways to create an environment.
make sense?

@dan-blanchard
Copy link
Author

@dan-blanchard what's gonna happen if in the same directory you have an environment.yml file and a requirements.txt file?

The environment.yml file will be used by default (since it's the default value for the --file argument to conda env create), and requirements.txt will be used if you specify it as the file you want to use with --file.

You could have a new spec called requirements_txt_spec (maybe)

I can certainly do that if that's what y'all want me to, but I went with this since it is so similar to what is happening for the pip requirements in environment.yml. I wasn't sure if the extra spec was really necessary, but obviously I'm not intimately familiar with the conda-env code.

@malev
Copy link
Contributor

malev commented Oct 27, 2015

@dan-blanchard I think going with specs is a better approach because you'll take advantage of the architecture already in place for creating new environments.

@malev malev mentioned this pull request Nov 18, 2015
@@ -80,6 +80,8 @@ def execute(args, parser):
# FIXME conda code currently requires args to have a name or prefix
if args.name is None:
args.name = env.name
else:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't fully understand what's going on here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this the environment won't get a name, because requirements.txt files cannot contain the name of the environment.

@malev
Copy link
Contributor

malev commented Nov 18, 2015

I'm starting to feel like this might be outside the scope of the project. What does @msarahan thinks about?

@msarahan
Copy link
Collaborator

I don't think it's out of scope, necessarily. I see it as a good compatibility layer that may make conda a more compelling platform. The best platform isn't conda or pip, it's both. I don't fully understand the long-term support implications, though. It sort of joins conda to pip, and requires you to keep supporting pip once people start using this feature. What happens if/when pip is replaced down the line? You'll have to support pip likely longer than pip itself is supported. I don't think this issue is a deal breaker. I just think we need to discuss long-term implications, and figure out if any engineering solution can reduce future risk.

@malev
Copy link
Contributor

malev commented Nov 19, 2015

@msarahan that's my concern.
On the other hand I like it ...
I'm gonna try to put some time on run tests and try out this PR
Thanks!

# properly.
specs = list(chain(*[s.split() if '-e' in s else [s] for s in specs]))
# Directory where pip will store VCS checkouts for editable packages
src_dir = join(config.envs_dirs[0], env.name, 'src')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like config.envx_dirs[0] is the location of the root environment.
how is this gonna work when we want to install into some other environment? (like the one we have just created)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

config.envs_dirs[0] should be $CONDA_ROOT/envs, and I'm joining that with the name of the environment and src, so the final path will be $CONDA_ROOT/envs/$CONDA_ENV/src. That's exactly what we want.

@dan-blanchard
Copy link
Author

@githubfun, I've been successfully using my branch since September without any issues, so if this is something you need as much as I do, I suggest you just clone my branch and install it in your conda root environment with python setup.py develop.

@dan-blanchard
Copy link
Author

Any movement on adding this officially? I was talking to somebody at work about how they can use conda with requirements.txt files now and then I remembered it's only with my fork.

@cowlicks
Copy link

cowlicks commented Feb 11, 2016

One thing I haven't seen mentioned here, conda install has a --file flag which can take a requirements.txt file. This is only helpful when everything in the requirements.txt is has a conda package. But it is still probably useful in some cases @githubfun @dan-blanchard . Sorry if y'all were already aware of this.

However using conda install --file is usually a pretty bad experience since most of the time there is not a conda package for everything in the requirements.txt. Trying to use conda install --file makes me want this.

At the end of the day what I (and probably others) want is a consistent workflow across projects, whether they use a requirements.txt or environment.yml. Something like

  1. cd project-name
  2. conda env create
  3. source activate project-name

Which is what this PR would let me do.

So yeah +1 to this.

@malev how does #203 address this?

@AlJohri
Copy link

AlJohri commented Apr 24, 2016

@malev any word on how to get this merged in? what can we do to help?

@dan-blanchard
Copy link
Author

This is only helpful when everything in the requirements.txt is has a conda package.

Yeah, the main advantage of the approach here is that this will support editable packages on GitHub and the like, which are currently not supported by conda env.

@mlaprise
Copy link

hey @dan-blanchard, like you probably know, I'm really interested by this. Are you using this approach in production ? As of today, is there any other ways to achieve the same goal ?

@dan-blanchard
Copy link
Author

hey @mlaprise, we still aren't using conda in production at Parse.ly, but I use this at least once a week for development. I don't know of any other way to achieve the same goal.

@jni
Copy link
Contributor

jni commented Jun 2, 2017

FWIW I would very much like to see this addition merged. I have wanted it so many times.

@nicoddemus
Copy link
Contributor

@jni this repository has been deprecated, if there's still interested in this PR it should be re-opened in conda/conda.

@ccordoba12 @kalefranz perhaps using the GH API to post a comment in all open issues and PRs to let people now that the developement has been moved to conda/conda is a good approach to prevent confusion?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants