Skip to content

Commit 76b2ab6

Browse files
committed
Fix for the python2/3 argparser issues.
1 parent 2c953b8 commit 76b2ab6

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

common/default_utils.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,19 @@ def initialize_parameters(bmk):
227227

228228
#print('Args:', args)
229229
# Get parameters from configuration file
230-
aux = bmk.parser.parse_args(['conffile'])
231-
#print(aux.config_file)
232-
fileParameters = bmk.read_config_file(aux.config_file)#args.config_file)
230+
# Reads parameter subset, just checking if a config_file has been set
231+
# by comand line (the parse_known_args() function allows a partial
232+
# parsing)
233+
aux = bmk.parser.parse_known_args()
234+
try : # Try to get the 'config_file' option
235+
conffile_txt = aux[0].config_file
236+
except AttributeError: # The 'config_file' option was not set by command-line
237+
conffile = bmk.conffile # use default file
238+
else: # a 'config_file' has been set --> use this file
239+
conffile = os.path.join(bmk.file_path, conffile_txt)
240+
241+
print("Configuration file: ", conffile)
242+
fileParameters = bmk.read_config_file(conffile)#aux.config_file)#args.config_file)
233243
# Get command-line parameters
234244
args = bmk.parser.parse_args()
235245
#print ('Params:', fileParameters)
@@ -254,7 +264,6 @@ def get_default_neon_parser(parser):
254264
"""
255265
# Logging Level
256266
parser.add_argument("-v", "--verbose", type=str2bool,
257-
default=argparse.SUPPRESS,
258267
help="increase output verbosity")
259268
parser.add_argument("-l", "--log", dest='logfile',
260269
default=None,
@@ -308,6 +317,10 @@ def get_common_parser(parser):
308317
parser for command-line options
309318
"""
310319

320+
# Configuration file
321+
parser.add_argument("--config_file", dest='config_file', default=argparse.SUPPRESS,
322+
help="specify model configuration file")
323+
311324
# General behavior
312325
parser.add_argument("--train_bool", dest='train_bool', type=str2bool,
313326
default=True,
@@ -585,20 +598,9 @@ def parse_from_common(self):
585598

586599
self.parser = parser
587600

588-
subparsers = self.parser.add_subparsers()
589-
self.parser_a = subparsers.add_parser('conffile', help='a help')
590-
#parser_a.add_argument('bar', type=int, help='bar help')
591-
592601
# Set default configuration file
593-
#self.parser.add_argument("--config_file", dest='config_file', type=str,
594-
# default=os.path.join(self.file_path, self.default_model),
595-
# help="specify model configuration file")
596-
597-
self.parser_a.add_argument("--config_file", dest='config_file', type=str,
598-
default=os.path.join(self.file_path, self.default_model),
599-
help="specify model configuration file")
600-
601-
602+
self.conffile = os.path.join(self.file_path, self.default_model)
603+
602604

603605
def parse_from_benchmark(self):
604606
"""Functionality to parse options specific

0 commit comments

Comments
 (0)