#4506 Replace optparse by argparse
Opened 9 years ago by dkupka. Modified 5 years ago

Use arparse instead of already deprecated optparse.

Argparse has some nice features that optparse has not^[#cite1 1]^. Optparse is considered deprecated since python 2.7^[#cite2 2]^ and the change should be easy^[#cite3 3]^ and located mostly in ipapython/config.py^[#cite4 ?]^.

[=#cite1 (1)] https://argparse.googlecode.com/svn/trunk/doc/argparse-vs-optparse.html \
[=#cite2 (2)] https://docs.python.org/2/library/optparse.html \
[=#cite3 (3)] https://docs.python.org/2.7/library/argparse.html#upgrading-optparse-code \
[=#cite4 (?)] http://xkcd.com/285/


In the past, we had to stick to optparse as we had to support Python 2.6. But as now we already depend on Python 2.7, using argparse is possible.

We may think about this replacement as a (stretch) goal of the installers refactoring in 4.2.

The "located mostly in ipapython/config.py" part is not true, as evidenced by git grep optparse.

But yes, this would be nice to do.

May be a good target for Python 3 related work.

I can do this. It's in 22 files, but not much code.

It's also in contrib/RHEL4/ipa-client-setup - RHEL4 in the directory name makes me think I should not touch that file, is that right?

Thanks. And you are right about RHEL4 file, no Python 3 there :-)

Note that while optparse is deprecated, it is still available in Python 3, and unlikely to be removed any time soon.

It was agreed with Jan Cholasta that porting IPA from optparse to argparse won't happen as a part of porting IPA to Python3.

Originally we thought that porting to argparse will be an easy task but Miro Hroncok found out that IPA is using some features from optparse which are not available in argparse and currently we don't have a time to resolve such issue and as Petr Viktorin noted above optparse won't be removed any time soon so this is not a critical issue for Python3 task.

Metadata Update from @dkupka:
- Issue assigned to churchyard
- Issue set to the milestone: FreeIPA 4.5 backlog

7 years ago

optparse is still in Python 3.7 and not yet slated for removal. Re-evaluate for FreeIPA 4.8.

Metadata Update from @cheimes:
- Assignee reset
- Issue close_status updated to: None
- Issue set to the milestone: FreeIPA 4.8 (was: FreeIPA 4.5 backlog)

5 years ago

Login to comment on this ticket.

Metadata