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

virtualenv's main should take arguments #172

Closed
k0s opened this issue Sep 19, 2011 · 6 comments
Closed

virtualenv's main should take arguments #172

k0s opened this issue Sep 19, 2011 · 6 comments

Comments

@k0s
Copy link

k0s commented Sep 19, 2011

https://github.com/pypa/virtualenv/blob/develop/virtualenv.py#L672

Should be

def main(args=sys.argv[1:]):

where args are later passed to parser.parse_args; this lets virtualenv be (more) meaningfully used as an API

@carljm
Copy link

carljm commented Sep 19, 2011

I don't necessarily have a problem with this change - but if you want to use virtualenv as an API just call the existing create_environment() function, that's a much nicer API than putting together a fake sys.argv.

@k0s
Copy link
Author

k0s commented Sep 19, 2011

Unfortunately, this doesn't work either since logger is defined in main:

│python -c 'import virtualenv; virtualenv.create_environment("/home/jhammel/foo")'
Traceback (most recent call last):
File "", line 1, in
File "virtualenv.py", line 647, in create_environment
site_packages=site_packages, clear=clear))
File "virtualenv.py", line 750, in install_python
mkdir(lib_dir)
File "virtualenv.py", line 205, in mkdir
logger.info('Creating %s', path)
NameError: global name 'logger' is not defined

While I would like this change, I'm open to other possibilities, with the caveat that I do (for silly reasons that I can go into if desired) need to run python -c "import virtualenv; ..." rather than some saner method

@carljm
Copy link

carljm commented Sep 19, 2011

You must be using an old version of virtualenv. That was fixed last March in ea1786 and works fine in at least 1.6 and up.

@k0s
Copy link
Author

k0s commented Sep 19, 2011

Ah, true enough. Thanks!

@chadwhitacre
Copy link

I can confirm that the missing global logger is not an issue anymore (I'm using 1.9.1), and that calling create_environment directly works fine. I came here thinking it'd be nice to factor out the checks between the adjust_options hook and the create_environment call or perhaps push them down into create_environment itself, but now I think that it's fine to pick and choose from the behavior represented there because it doesn't all apply to use cases in which one wants to use virtualenv as a library anyway. Configuring the logger could be nicer, but that's a separate issue. I suggest closing this one.

@stale
Copy link

stale bot commented Jan 15, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Just add a comment if you want to keep it open. Thank you for your contributions.

@stale stale bot added the wontfix label Jan 15, 2019
@stale stale bot closed this as completed Jan 22, 2019
@pypa pypa locked and limited conversation to collaborators Jan 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants