71
71
import logging
72
72
import os
73
73
import io
74
- import configargparse
75
74
76
75
# allow for unicode for stdin / stdout, it's a mess
77
76
try :
@@ -1422,6 +1421,11 @@ def log_message(message, level, filename, line_nr):
1422
1421
def run (argv = sys .argv ): # pragma: no cover
1423
1422
"""Command line interface"""
1424
1423
1424
+ try :
1425
+ import configargparse as argparse
1426
+ except ImportError :
1427
+ import argparse
1428
+
1425
1429
def str2bool (str ):
1426
1430
"""helper function to convert strings to bool"""
1427
1431
if str .lower () in ('yes' , 'true' , 't' , 'y' , '1' ):
@@ -1431,10 +1435,14 @@ def str2bool(str):
1431
1435
else :
1432
1436
return None
1433
1437
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 )
1438
1446
1439
1447
parser .add_argument ("-i" , "--indent" , type = int , default = 3 ,
1440
1448
help = "relative indentation width" )
@@ -1478,7 +1486,7 @@ def str2bool(str):
1478
1486
group .add_argument ("-S" , "--silent" , "--no-report-errors" , action = 'store_true' ,
1479
1487
default = False , help = "Don't write any errors or warnings to stderr" )
1480
1488
group .add_argument ("-D" , "--debug" , action = 'store_true' ,
1481
- default = False , help = configargparse .SUPPRESS )
1489
+ default = False , help = argparse .SUPPRESS )
1482
1490
parser .add_argument ("path" , type = str , nargs = '*' ,
1483
1491
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 = ['-' ])
1484
1492
parser .add_argument ('-r' , '--recursive' , action = 'store_true' ,
0 commit comments