Thanks to visit codestin.com
Credit goes to github.com

Skip to content

MAINT: replace optparse with argparse for 'doc' and 'tools' scripts #15702

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

Merged
merged 1 commit into from
Mar 9, 2020

Conversation

mwtoews
Copy link
Contributor

@mwtoews mwtoews commented Mar 4, 2020

The optparse module is deprecated since Python 2.7/3.2. This PR upgrades a few scripts to use argparse.

Because these tools are not really part of the CI testing, they need some manual checks. Here is a summary for each tool:

  • doc/postprocess.py still in used, and checked with GITVER=91118b3363 make html
  • doc/summarize.py not used, does not work (ModuleNotFoundErrror), and probably not used since numpy 1.7 (when e.g. doc/sphinxext/phantom_import.py existed); follow-up with Tool doc/summarize.py does not work #15708
  • numpy/distutils/npy_pkg_config.py not sure how to test from command line
  • numpy/distutils/system_info.py appears to still be in-use, and works as before; follow-up with MAINT: replace optparse with argparse for 'distutils' scripts #15728
  • tools/c_coverage/c_coverage_report.py still in use
  • tools/npy_tempita/__init__.py not considered in this PR, as this module is left-alone

@charris charris changed the title MAINT: replace optparse with argparse MAINT: Replace optparse with argparse Mar 4, 2020
Copy link
Member

@seberg seberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creafully went through all of this, and did not find any issue/potential error. I would be happy to put this in, if this breaks something, it will break very loudly and be easy to fix.

@mwtoews mwtoews force-pushed the optparse branch 2 times, most recently from d7905eb to 521fd30 Compare March 4, 2020 18:16
@mwtoews
Copy link
Contributor Author

mwtoews commented Mar 4, 2020

As for doc/summarize.py, this is #15708

@seberg
Copy link
Member

seberg commented Mar 4, 2020

Since some of this touches distutils, I would like @rgommers to give his OK.

@mattip
Copy link
Member

mattip commented Mar 4, 2020

Please do not touch distutils. The optparse note says "it will not be developed further" and not "it will be removed in the future", so I am comfortable leaving it as-is.

@mwtoews
Copy link
Contributor Author

mwtoews commented Mar 5, 2020

@mattip why not distutils? It's still maintained. I'm only aware that npy_tempita is not to receive any maintanance.

I don't understand the argument why use of deprecated modules should be left as-is, even if it's unlikely to be removed. There are clear benefits of using supported upstream modules.

@mattip
Copy link
Member

mattip commented Mar 5, 2020

The module is very fragile, and due to its nature is difficult to test: it is used by many more architectures, compilers, operating systems, shells, and python variants than we can test for. Breaking it is very expensive in terms of developer time to find the fix. Even replicating the failure can be such a daunting task that we simply end up reverting the change. Then we have to try to work out which change to revert, which is also non-trivial since some users only update once every few years.

We are even more unlikely to start using advanced features of argparse for the same reason. We could find out 3 years down the road that we broke someone's workflow by slightly changing some nuance in parsing command line arguments. It could take weeks to chase down the broken build with little indication that the problem is that the compiler invocation ended up having an extra space in the command, and this particular shell used to compile doesn't handle spaces.

So in the balance, we would prefer not to change distutils unless motivated by a user-reported issue.

@charris
Copy link
Member

charris commented Mar 9, 2020

Let's break this into two PRs, one for the distutils files and one for the rest. I'm not as concerned as Ralf is about fooling with distutils, I think we did alright with the subprocess change and that change had more subtle effects than this. However, I don't want to hang this PR up over the dispute.

@mwtoews mwtoews changed the title MAINT: Replace optparse with argparse MAINT: Replace optparse with argparse for 'doc' and 'tools' scripts Mar 9, 2020
@mwtoews
Copy link
Contributor Author

mwtoews commented Mar 9, 2020

@mattip thanks for the explanation! Yes, agree about the fragility of the module, and the consequences of any misstep. However it is also a good argument to move away from deprecated modules to supported modules...
@charris done as requested: the distutils edits are now in PR #15728, and this PR is otherwise unchanged (apart from removing two files and rewording commit message)

@mwtoews mwtoews changed the title MAINT: Replace optparse with argparse for 'doc' and 'tools' scripts MAINT: replace optparse with argparse for 'doc' and 'tools' scripts Mar 9, 2020
@charris charris merged commit 9da90de into numpy:master Mar 9, 2020
@charris
Copy link
Member

charris commented Mar 9, 2020

Thanks @mwtoews .

@mwtoews mwtoews deleted the optparse branch March 9, 2021 10:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants