-
-
Notifications
You must be signed in to change notification settings - Fork 688
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
Change optparse for argparse. #238
Conversation
froi
commented
Feb 26, 2017
- Change optparse for the more modern argparse.
- Refactored main() to fit new argparse code.
- Added two subcommands: encode and decode
- Added default functions for encode and decode subcommands
- Replaced implicit arguments with standard Python syntax in usage text.
- Change optparse (deprecated) for the more modern argparse. - Added two subcommands: encode and decode - Added default functions for encode and decode subcommands - Replaced implicit arguments with standard Python syntax in usage text. -Refactored main() to fit new argparse code.
- Moved argparse import to first import.
- Fixed flake8 spacing issues.
@froi looks good to me, thanks! Coverage decreased because |
Let me see if I can make that happen in a sane way. @jpadilla Do you want me to add that to this PR or another? |
@froi here's fine. |
- Refactored __main__.py so it can be more testable. - Created test_cli.py - Added tests for encode_payload, decode_payload, build_argparse, and main functions. - Added __main__,py to .coveragerc
- Add py35 env to tox.ini - Add flake8 excludes to tox.ini - Change str.format() to str % str to be compatible with older Python envs. - Removed pytest version constraint from setup.py - Reordered envs in .travis.yml - Added python 3.6 envs to .travis.yml
1 similar comment
.travis.yml
Outdated
@@ -1,6 +1,6 @@ | |||
language: python | |||
python: | |||
- "3.5" | |||
- "3.6" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is changing these required for this PR? There are some InterpreterNotFound
errors in there, which might be fixed by #262.
- Change optparse (deprecated) for the more modern argparse. - Added two subcommands: encode and decode - Added default functions for encode and decode subcommands - Replaced implicit arguments with standard Python syntax in usage text. -Refactored main() to fit new argparse code.
- Moved argparse import to first import.
- Fixed flake8 spacing issues.
- Refactored __main__.py so it can be more testable. - Created test_cli.py - Added tests for encode_payload, decode_payload, build_argparse, and main functions. - Added __main__,py to .coveragerc
- Add py35 env to tox.ini - Add flake8 excludes to tox.ini - Change str.format() to str % str to be compatible with older Python envs. - Removed pytest version constraint from setup.py - Reordered envs in .travis.yml - Added python 3.6 envs to .travis.yml
Added index to string format. Removed unused import. Fixed some flake8 warning/errors.
1 similar comment
jwt/__main__.py
Outdated
except Exception as e: | ||
print('There was an unforseen error: ', e) | ||
arg_parser.print_help() | ||
sys.exit(1) | ||
|
||
|
||
if __name__ == '__main__': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@froi Noticed another thing missing.
- Run
python setup.py install
- Run
pyjwt
It'll fail with something like this:
$ pyjwt
Traceback (most recent call last):
File "/Users/jpadilla/.pyenv/versions/pyjwt/bin/pyjwt", line 9, in <module>
load_entry_point('PyJWT==1.5.0', 'console_scripts', 'pyjwt')()
TypeError: main() takes exactly 1 argument (0 given)
Since we're using the console_scripts
entry point on our setup.py
I think we should be able to drop just drop the if __name__ == '__main__': ...
and have the main()
method optionally set args to sys.argv[1:]
. Let me know if this makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That'll work but it'll also make main()
harder to test I think. I'll take a look at it.
- Added test_encode_decode to up code coverage. decode_payload was previously not tested. - Rename test_main. This was primarily to up coverage. sys.args are monkeypatched.
- main now prints token to stdout
- Removed sys.exit it was interferring with test.
- Reordered imports - Added test_decode_payload_raises_decoded_error_isatty - Added test_main_throw_exception - Monkeypatched sys.stdin.isatty and sys.stdin.read - Monkeypatched argparse.ArgumentParser.parse_args to force exception in __main__.main
Pull Request Test Coverage Report for Build 148
💛 - Coveralls |
4 similar comments
@froi Thank you! |