7171import logging
7272import os
7373import io
74- import configargparse
7574
7675# allow for unicode for stdin / stdout, it's a mess
7776try :
@@ -1422,6 +1421,11 @@ def log_message(message, level, filename, line_nr):
14221421def run (argv = sys .argv ): # pragma: no cover
14231422 """Command line interface"""
14241423
1424+ try :
1425+ import configargparse as argparse
1426+ except ImportError :
1427+ import argparse
1428+
14251429 def str2bool (str ):
14261430 """helper function to convert strings to bool"""
14271431 if str .lower () in ('yes' , 'true' , 't' , 'y' , '1' ):
@@ -1431,10 +1435,14 @@ def str2bool(str):
14311435 else :
14321436 return None
14331437
1434- parser = configargparse .ArgumentParser (prog = argv [0 ],
1435- description = 'Auto-format modern Fortran source files.' ,
1436- default_config_files = ['.fprettify.rc' , '~/.fprettify.rc' ],
1437- formatter_class = configargparse .ArgumentDefaultsHelpFormatter )
1438+ arguments = {'prog' : argv [0 ],
1439+ 'description' : 'Auto-format modern Fortran source files.' ,
1440+ 'formatter_class' : argparse .ArgumentDefaultsHelpFormatter }
1441+
1442+ if argparse .__name__ == "configargparse" :
1443+ arguments ['default_config_files' ] = ['.fprettify.rc' , '~/.fprettify.rc' ]
1444+
1445+ parser = argparse .ArgumentParser (** arguments )
14381446
14391447 parser .add_argument ("-i" , "--indent" , type = int , default = 3 ,
14401448 help = "relative indentation width" )
@@ -1478,7 +1486,7 @@ def str2bool(str):
14781486 group .add_argument ("-S" , "--silent" , "--no-report-errors" , action = 'store_true' ,
14791487 default = False , help = "Don't write any errors or warnings to stderr" )
14801488 group .add_argument ("-D" , "--debug" , action = 'store_true' ,
1481- default = False , help = configargparse .SUPPRESS )
1489+ default = False , help = argparse .SUPPRESS )
14821490 parser .add_argument ("path" , type = str , nargs = '*' ,
14831491 help = "Paths to files to be formatted inplace. If no paths are given, stdin (-) is used by default. Path can be a directory if --recursive is used." , default = ['-' ])
14841492 parser .add_argument ('-r' , '--recursive' , action = 'store_true' ,
0 commit comments