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

Pre-hook for virtual env #1

Closed
pauleveritt opened this issue Sep 28, 2015 · 15 comments
Closed

Pre-hook for virtual env #1

pauleveritt opened this issue Sep 28, 2015 · 15 comments

Comments

@pauleveritt
Copy link

First, I'm very interested in this project. I communicated with Danny and Audrey once though about making a virtualenv before running the template, thus automating that step as well (to be more newbie friendly.) I think they were interested, but CookieCutter has a million things to do and not enough volunteers to do them.

Is this something that can be done in a template? I doubt it, because the template itself needs to run in a virtual env. But then again, I've seen some virtualenv and PyVenv wrappers that do funky things.

@cguardia
Copy link
Owner

Yeah, I remember that. I'll take a look at the bunch of new features in 1.1 and see if something can be done along these lines.

@cguardia
Copy link
Owner

cguardia commented Oct 1, 2015

@pauleveritt: Ok, not sure I grasp exactly what you wanted to get, but I made a branch that allows you to pass a flag, --setup-venv, when running cookiecutter. I can now do, e.g.:

$ cookiecutter --setup-venv myrepo

After I answer the questions, I end up with a directory, myrepo. If I cd there, the virtualenv is already set up and I can just run:

$ bin/python setup.py development.ini

Is that what you were after?

See: https://github.com/cguardia/cookiecutter/tree/setup-venv

@pauleveritt
Copy link
Author

That’s pretty cool, in that it eliminates the step of making the virtual environment. I wonder if it this knob could be in the template, as a way to further decrease the concepts needed for a newbie.

I was hoping, though, to eliminate the part of running “env/bin/python ./setup.py develop” or “env/bin/pip -e .” to put the Python project (to use the correct jargon) in editable mode. It’s a hard thing to explain.

I doubt though that this is easy. I’ve seen some subclasses of Python 3’s EnvBuilder that automate actions inside the build virtual environment (e.g. executing a CookieCutter template):

https://docs.python.org/3/library/venv.html#an-example-of-extending-envbuilder

I think virtualenv might have some similar scripting, not sure.

—Paul

On Sep 30, 2015, at 11:27 PM, Carlos de la Guardia [email protected] wrote:

Ok, not sure I grasp exactly what you wanted to get, but I made a branch that allows you to pass a flag, --setup-venv, when running cookiecutter. I can now do, e.g.:

$ cookiecutter --setup-venv myrepo

After I answer the questions, I end up with a directory, myrepo. If I cd there, the virtualenv is already set up and I can just run:

$ bin/python setup.py development.ini

Is that what you were after?

See: https://github.com/cguardia/cookiecutter/tree/setup-venv https://github.com/cguardia/cookiecutter/tree/setup-venv

Reply to this email directly or view it on GitHub #1 (comment).

@cguardia
Copy link
Owner

cguardia commented Oct 2, 2015

@pauleveritt I'd like to run it from the template as well, to avoid the --setup-venv flag on the cookiecutter call. However, in that case we would need the user to have already installed virtualenv, because the cookiecutter template itself can't have dependencies. Maybe we could convince the cookiecutter team to add it as a dependency for cookiecutter, not sure.

@pauleveritt
Copy link
Author

On Oct 2, 2015, at 1:58 PM, Carlos de la Guardia [email protected] wrote:

@pauleveritt I'd like to run it from the template as well, to avoid the --setup-venv flag on the cookiecutter call. However, in that case we would need the user to have already installed virtualenv, because the cookiecutter template itself can't have dependencies. Maybe we could convince the cookiecutter team to add it as a dependency for cookiecutter, not sure.

Yeh, unfortunately, this was an idea geared more towards Python 3.3+.

—Paul

@cguardia
Copy link
Owner

cguardia commented Oct 2, 2015

@pauleveritt I confess I have mostly stayed with 2.7, but looking at this now, I'm not loving pyvenv. It doesn't install setuptools, so that would need to be done by the template as well, whereas with good old virtualenv, we get that for free.

@cguardia
Copy link
Owner

cguardia commented Oct 3, 2015

@pauleveritt Ok, I changed tracks. Maybe this doesn't belong in cookiecutter after all.

Try this template again, but make sure virtualenv is installed for the python with which you run cookiecutter. It should create the environment and run setup.py develop. All the user has to do after that is cd to the project directory and run bin/pserve development.ini.

We can always change this to deal with pyvenv later.

@pauleveritt
Copy link
Author

Do I still do the --setup-venv flag?

@pauleveritt
Copy link
Author

Ok, ran it, and yep, it did exactly as you described. Very cool! Very very very cool.

@cguardia
Copy link
Owner

cguardia commented Oct 3, 2015

No need for flag anymore. This time the work is all done in the template.

@cguardia
Copy link
Owner

@pauleveritt I turned parts of this into a PR for cookiecutter:

cookiecutter/cookiecutter#554

Please see their comment at the bottom. Do you use homebrew? I don't really know much about homebrew. Would virtualenv work there?

@pauleveritt
Copy link
Author

On Oct 17, 2015, at 1:37 PM, Carlos de la Guardia [email protected] wrote:

@pauleveritt https://github.com/pauleveritt I turned parts of this into a PR for cookiecutter:

cookiecutter/cookiecutter#554 cookiecutter/cookiecutter#554
Please see their comment at the bottom. Do you use homebrew? I don't really know much about homebrew. Would virtualenv work there?

I do use Homebrew. I don’t quite see their point, though. They depend on click etc. You’re just adding another pure-Python dependency.

Stated differently, is there anything about virtualenv that makes it more problematic for cookiecutter to install than click?

—Paul

@cguardia
Copy link
Owner

Virtualenv now works (if installed). There's a pull request to the cookiecutter project that could make sure virtualenv is there, but it's currently waiting for review/support:

cookiecutter/cookiecutter#554

In the meantime, I'll close this, since one way or another we have virtualenv support available now.

@pauleveritt
Copy link
Author

Well, I wonder if we don't come back to Python 3.4+. You said: "I confess I have mostly stayed with 2.7, but looking at this now, I'm not loving pyvenv. It doesn't install setup tools" but pyvenv in 3.4 does install pip and setuptools in the environment. I guess I should look at the couple of lines in here that script virtualenv and see what it would be like under 3.4/3.5. For the target audience, it would sure be nice to eliminate an explanation of pip install virtualenv into a possible-system location.

@pauleveritt
Copy link
Author

I should say, though, that this shouldn't stop evaluation of this template and hopeful adoption by the Pyramid community.

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

No branches or pull requests

2 participants