Skip to content

Commit

Permalink
Fix for the python2/3 argparser issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmohdyusof committed Aug 26, 2018
1 parent 2c953b8 commit 76b2ab6
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions common/default_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,19 @@ def initialize_parameters(bmk):

#print('Args:', args)
# Get parameters from configuration file
aux = bmk.parser.parse_args(['conffile'])
#print(aux.config_file)
fileParameters = bmk.read_config_file(aux.config_file)#args.config_file)
# Reads parameter subset, just checking if a config_file has been set
# by comand line (the parse_known_args() function allows a partial
# parsing)
aux = bmk.parser.parse_known_args()
try : # Try to get the 'config_file' option
conffile_txt = aux[0].config_file
except AttributeError: # The 'config_file' option was not set by command-line
conffile = bmk.conffile # use default file
else: # a 'config_file' has been set --> use this file
conffile = os.path.join(bmk.file_path, conffile_txt)

print("Configuration file: ", conffile)
fileParameters = bmk.read_config_file(conffile)#aux.config_file)#args.config_file)
# Get command-line parameters
args = bmk.parser.parse_args()
#print ('Params:', fileParameters)
Expand All @@ -254,7 +264,6 @@ def get_default_neon_parser(parser):
"""
# Logging Level
parser.add_argument("-v", "--verbose", type=str2bool,
default=argparse.SUPPRESS,
help="increase output verbosity")
parser.add_argument("-l", "--log", dest='logfile',
default=None,
Expand Down Expand Up @@ -308,6 +317,10 @@ def get_common_parser(parser):
parser for command-line options
"""

# Configuration file
parser.add_argument("--config_file", dest='config_file', default=argparse.SUPPRESS,
help="specify model configuration file")

# General behavior
parser.add_argument("--train_bool", dest='train_bool', type=str2bool,
default=True,
Expand Down Expand Up @@ -585,20 +598,9 @@ def parse_from_common(self):

self.parser = parser

subparsers = self.parser.add_subparsers()
self.parser_a = subparsers.add_parser('conffile', help='a help')
#parser_a.add_argument('bar', type=int, help='bar help')

# Set default configuration file
#self.parser.add_argument("--config_file", dest='config_file', type=str,
# default=os.path.join(self.file_path, self.default_model),
# help="specify model configuration file")

self.parser_a.add_argument("--config_file", dest='config_file', type=str,
default=os.path.join(self.file_path, self.default_model),
help="specify model configuration file")


self.conffile = os.path.join(self.file_path, self.default_model)


def parse_from_benchmark(self):
"""Functionality to parse options specific
Expand Down

0 comments on commit 76b2ab6

Please sign in to comment.