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

Switch from using optparse to argparse for command line arguments #769

Merged
merged 1 commit into from
Oct 19, 2019
Merged

Switch from using optparse to argparse for command line arguments #769

merged 1 commit into from
Oct 19, 2019

Conversation

jdufresne
Copy link
Contributor

The Python module optparse is deprecated and is no longer receiving updates. From the Python documentation:

Deprecated since version 3.2: The optparse module is deprecated and will not be developed further; development will continue with the argparse module.

Can take advantage of the argpares API by making the following cleanups:


Remove default=None. It is the default.

https://docs.python.org/3/library/argparse.html#default

The default keyword argument of add_argument(), whose value defaults to None, ...


Remove dest='...', when it matches the first long option, which is the argparse default.

https://docs.python.org/3/library/argparse.html#dest

For optional argument actions, the value of dest is normally inferred from the option strings. ArgumentParser generates the value of dest by taking the first long option string and stripping away the initial -- string. [...] Any internal - characters will be converted to _ characters to make sure the string is a valid attribute name.


Remove default=False for type='store_true' as it is an implied default:

https://docs.python.org/3/library/argparse.html#action

'store_true' and 'store_false' - These are special cases of 'store_const' used for storing the values True and False respectively. In addition, they create default values of False and True respectively.

Use argparse builtin version support:

https://docs.python.org/3/library/argparse.html#action

'version' - This expects a version= keyword argument in the add_argument() call, and prints version information and exits when invoked

@codecov
Copy link

codecov bot commented Apr 2, 2018

Codecov Report

Merging #769 into master will increase coverage by 0.12%.
The diff coverage is 89.18%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #769      +/-   ##
==========================================
+ Coverage   72.45%   72.57%   +0.12%     
==========================================
  Files          17       17              
  Lines        1706     1703       -3     
  Branches      255      254       -1     
==========================================
  Hits         1236     1236              
+ Misses        408      405       -3     
  Partials       62       62
Impacted Files Coverage Δ
locust/main.py 34.52% <89.18%> (+0.45%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5518593...fb282fd. Read the comment docs.

@cyberw
Copy link
Collaborator

cyberw commented Oct 18, 2019

LGTM. @jdufresne , if you fix the conflicts I think we should merge this. @heyman , do you agree?

@heyman
Copy link
Member

heyman commented Oct 19, 2019

Yes, sounds good!

The Python module optparse is deprecated and is no longer receiving
updates. From the Python documentation:

https://docs.python.org/3/library/optparse.html

> Deprecated since version 3.2: The optparse module is deprecated and
> will not be developed further; development will continue with the
> argparse module.

Can take advantage of the argpares API by making the following cleanups:

Remove action='store'. It is the default.

https://docs.python.org/3/library/argparse.html#action

> 'store' - This just stores the argument’s value. This is the default
> action.

Remove default=None. It is the default.

https://docs.python.org/3/library/argparse.html#default

> The default keyword argument of add_argument(), whose value defaults
> to None, ...

Remove dest='...', when it matches the first long option, which is the
argparse default.

https://docs.python.org/3/library/argparse.html#dest

> For optional argument actions, the value of dest is normally inferred
> from the option strings. ArgumentParser generates the value of dest by
> taking the first long option string and stripping away the initial --
> string. [...] Any internal - characters will be converted to _
> characters to make sure the string is a valid attribute name.

Remove default=False for type='store_true' as it is an implied default:

https://docs.python.org/3/library/argparse.html#action

> 'store_true' and 'store_false' - These are special cases of
> 'store_const' used for storing the values True and False respectively.
> In addition, they create default values of False and True
> respectively.

Use argparse builtin version support:

https://docs.python.org/3/library/argparse.html#action

> 'version' - This expects a version= keyword argument in the
> add_argument() call, and prints version information and exits when
> invoked
@jdufresne
Copy link
Contributor Author

Rebased 🙂

@heyman heyman merged commit 4bf7f6e into locustio:master Oct 19, 2019
@heyman
Copy link
Member

heyman commented Oct 19, 2019

Great, thanks!

@jdufresne jdufresne deleted the argparse branch October 19, 2019 23:03
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

Successfully merging this pull request may close these issues.

3 participants