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

Command Line Interface Fails #797

Closed
gledi opened this issue Feb 22, 2016 · 4 comments
Closed

Command Line Interface Fails #797

gledi opened this issue Feb 22, 2016 · 4 comments
Labels
Milestone

Comments

@gledi
Copy link

@gledi gledi commented Feb 22, 2016

I wanted to test aiohttp and I started by writing a file named example.py as shown below:

from aiohttp import web

async def hi(request):
    name = request.match_info.get('name', 'Anonymous')
    text = 'Hi ' + name
    return web.Response(body=text.encode('utf-8'))

def startapp(args):
    app = web.Application()
    app.router.add_route('GET', '/{name}', hi)
    return app

In the docs I saw the section about the CLI and decide to try that. The example shown in the docs is written as:

$ python -m aiohttp.web -H localhost -P 8080 package.module.init_func

However it wasn't working and I took a look at the code and it turned out that it was using a : to split the module from the callable so I modified my command as follows:

(aiohttptest)[gledi@testvm aiotest]$ python -d -m aiohttp.web -H localhost -P 8080 example:startapp
usage: aiohttp.web [-h] [-H HOSTNAME] [-P PORT] entry-func
aiohttp.web: error: 'entry-func' not in 'module:function' syntax

As entry-func actually was in the module:function syntax I looked at the code and it turned out that you were passing sys.argv to main:

if __name__ == "__main__":
    main(sys.argv)

and then later on in main after creating a parser you were calling it as such:

args, extra_args = arg_parser.parse_known_args(argv)

However that includes as the first parameter the name of the module (.... aiohttp/web.py) and thus it failed to parse it properly. I changed it as follows and it worked for me:

def main(argv=None):
    if argv is None:
        argv = sys.argv[1:]

...

if __name__ == '__main__':
    sys.exit(main()) # or simply just: main()

Also we might need to change the docs so that they use : to separate the module from the callable.

@asvetlov
Copy link
Member

@asvetlov asvetlov commented Feb 22, 2016

@jashandeep-sohi would you take a look?

@jashandeep-sohi
Copy link
Contributor

@jashandeep-sohi jashandeep-sohi commented Feb 22, 2016

@asvetlov Yeah, I mixed up parse_known_args semantics when called w/ args. Thanks @gledi 🙇

asvetlov added a commit that referenced this issue Feb 27, 2016
Fix command line arg parsing; issue #797
@asvetlov
Copy link
Member

@asvetlov asvetlov commented Feb 27, 2016

Fixed by #798

@asvetlov asvetlov closed this Feb 27, 2016
@asvetlov asvetlov added this to the 0.22 milestone Feb 27, 2016
@lock
Copy link

@lock lock bot commented Oct 29, 2019

This thread has been automatically locked since there has not been
any recent activity after it was closed. Please open a new issue for
related bugs.

If you feel like there's important points made in this discussion,
please include those exceprts into that new issue.

@lock lock bot added the outdated label Oct 29, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.