stfc / fparser

This project maintains and develops a Fortran parser called fparser2 written purely in Python which supports Fortran 2003 and some Fortran 2008. A legacy parser fparser1 is also available but is not supported. The parsers were originally part of the f2py project by Pearu Peterson.
https://fparser.readthedocs.io
Other
64 stars 29 forks source link

Use argparse instead of optparse #26

Open arporter opened 7 years ago

arporter commented 7 years ago

In script_options.py fparser uses the optparse module for command-line argument processing. This module has now been deprecated in favour of argparse.

p-vitt commented 6 years ago

The script_options module contains four functions. This is get_fortran_code_group, which adds the --mode argument, and three more functions that basically all add a --task={show,none} argument, only that set_read_options does not add none as choice, which leaves show as only choice!?

Why are there these three functions doing the same thing? Would it be an option to only have one method configuring the parser?

p-vitt commented 6 years ago

They actually don't do the same thing. They all add a different help message to the parser:

  1. Read files
  2. Parse files
  3. Parse files using Fortran2003 rules

Question is: Should these different messages stay? I don't see great benefit coming from them, so I would unify them to make the code cleaner. If the user should have the choice which ruleset to use (F2003 or not), this should be a simple option as well.

arporter commented 6 years ago

In fact this module is not used by the main fparser code base - it is only used by the scripts in the scripts directory:

polo fparser$ grep script_options *.py
polo fparser$ grep script_options scripts/*.py
scripts/f2003.py:from fparser.script_options import set_f2003_options
scripts/parse.py:from fparser.script_options import set_parse_options
scripts/read.py:from fparser.script_options import set_read_options

I'd therefore be tempted to get rid of this module and move each of the respective routines into the appropriate script file. We're not getting any re-use of them as they are and it would make their purpose more obvious.

p-vitt commented 6 years ago

I actually ported all stuff to argparse, but somehow screwed up the github Pull Request process by commiting stuff in between into my fork. Need to fix that.

However, moving the parser configuration into the scripts itself shouldn't be a problem at all. And it would clearly simplify the code structure. When I figured out how to clean up my fork, I'll create a pull request for it.