esabelhaus / google-api-python-client

Automatically exported from code.google.com/p/google-api-python-client
Other
0 stars 0 forks source link

Don't make argparse a required import for oauth2client/tools.py #299

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Using Python 2.5/2.6 (argparse is built in to 2.7 but is separate download 
for older versions).

2. import oauth2client.tools

3. If argparse hasn't been installed get an ImportError

What is the expected output? What do you see instead?
I use my own command line arguments and format. I don't want to force my users 
to download argparse when it's not really necessary. Ideally 
oauth2client.tools.run_flow() would be agnostic to the actual command line 
arguments. I can actually do that with:

class cmd_flags(object):
  def __init__(self):
    self.short_url = True 
    self.noauth_local_webserver = False
    self.logging_level = 'ERROR' 
    self.auth_host_name = 'localhost'
    self.auth_host_port = [8080, 9090]

and 

credentials = oauth2client.tools.run_flow(flow=FLOW, storage=storage, 
flags=cmd_flags(), http=http)

but the import of oauth2client.tools still throws errors if it's not installed 
even though my code doesn't use it. For now I just comment the import and lines 
55-68 out but ideally this would be fixed upstream.

What version of the product are you using? On what operating system?
apiclient/oauth2client 1.2. My application runs on Windows, Mac and Linux.

Original issue reported on code.google.com by jay@ditoweb.com on 26 Aug 2013 at 2:35

GoogleCodeExporter commented 8 years ago
Moreover, it would be nice if run_flow didn't need command-line arguments at 
all, and could just take named arguments. This makes the default code much more 
verbose than before.

For instance, I used to be able to do:
credentials = run(flow, STORAGE)

No I have to do:
from oauth2client import tools
argparser = argparse.ArgumentParser(
   description=__doc__,
   formatter_class=argparse.RawDescriptionHelpFormatter,
   parents=[tools.argparser])
flags = argparser.parse_args(sys.argv[1:])
credentials = tools.run_flow(flow, storage, flags)

Original comment by jtig...@gmail.com on 30 Mar 2014 at 8:39