def parse_config(cls, args): """ Standard constructor. This method parses the :param args: a set of arguments as handed over to the frontend :type args: list(str) """ cls.argument_parser = argparse.ArgumentParser( description='''NESTML is a domain specific language that supports the specification of neuron models in a precise and concise syntax, based on the syntax of Python. Model equations can either be given as a simple string of mathematical notation or as an algorithm written in the built-in procedural language. The equations are analyzed by NESTML to compute an exact solution if possible or use an appropriate numeric solver otherwise. Version ''' + str(pynestml.__version__), formatter_class=argparse.RawDescriptionHelpFormatter) cls.argument_parser.add_argument(qualifier_input_path_arg, metavar='PATH', type=str, nargs='+', help=help_input_path, required=True) cls.argument_parser.add_argument(qualifier_target_path_arg, metavar='PATH', type=str, nargs='?', help=help_target_path) cls.argument_parser.add_argument(qualifier_target_arg, metavar='NEST, none', type=str, nargs='?', help=help_target, default='NEST') cls.argument_parser.add_argument(qualifier_logging_level_arg, metavar='[INFO, WARNING/S, ERROR/S, NO]', type=str,help=help_logging) cls.argument_parser.add_argument(qualifier_module_name_arg, metavar='NAME', type=str, help=help_module) cls.argument_parser.add_argument(qualifier_store_log_arg, action='store_true', help=help_log) cls.argument_parser.add_argument(qualifier_suffix_arg, metavar='SUFFIX', type=str, help=help_suffix, default='') cls.argument_parser.add_argument(qualifier_dev_arg, action='store_true', help=help_dev) parsed_args = cls.argument_parser.parse_args(args) # get the source path cls.handle_source_path(parsed_args.input_path[0]) # initialize the logger if parsed_args.logging_level is not None: cls.logging_level = parsed_args.logging_level Logger.init_logger(Logger.string_to_level(parsed_args.logging_level)) else: cls.logging_level = "ERROR" Logger.init_logger(Logger.string_to_level("ERROR")) # now update the target cls.handle_target(parsed_args.target) # now update the target path cls.handle_target_path(parsed_args.target_path) # now adjust the name of the module, if it is a single file, then it is called just module if parsed_args.module_name is not None: assert parsed_args.module_name.endswith('module'), "Module name (\"" + parsed_args.module_name + "\") should end with \"module\"" cls.module_name = parsed_args.module_name elif os.path.isfile(parsed_args.input_path[0]): cls.module_name = 'nestmlmodule' elif os.path.isdir(parsed_args.input_path[0]): cls.module_name = os.path.basename(os.path.normpath(parsed_args.input_path[0])) else: cls.module_name = 'nestmlmodule' cls.store_log = parsed_args.store_log cls.suffix = parsed_args.suffix cls.is_debug = parsed_args.dev return
def parse_config(cls, args): """ Standard constructor. This method parses the :param args: a set of arguments as handed over to the frontend :type args: list(str) """ cls.argument_parser = argparse.ArgumentParser( description= '''NESTML is a domain specific language that supports the specification of neuron models in a precise and concise syntax, based on the syntax of Python. Model equations can either be given as a simple string of mathematical notation or as an algorithm written in the built-in procedural language. The equations are analyzed by NESTML to compute an exact solution if possible or use an appropriate numeric solver otherwise. Version ''' + str(pynestml.__version__), formatter_class=argparse.RawDescriptionHelpFormatter) cls.argument_parser.add_argument(qualifier_input_path_arg, metavar='PATH', nargs='+', type=str, help=help_input_path, required=True) cls.argument_parser.add_argument(qualifier_target_path_arg, metavar='PATH', type=str, help=help_target_path) cls.argument_parser.add_argument(qualifier_target_arg, choices=['NEST', 'autodoc', 'none'], type=str, help=help_target, default='NEST') cls.argument_parser.add_argument( qualifier_logging_level_arg, metavar='{DEBUG, INFO, WARNING, ERROR, NONE}', choices=[ 'DEBUG', 'INFO', 'WARNING', 'WARNINGS', 'ERROR', 'ERRORS', 'NONE', 'NO' ], type=str, help=help_logging, default='ERROR') cls.argument_parser.add_argument(qualifier_module_name_arg, metavar='NAME', type=str, help=help_module) cls.argument_parser.add_argument(qualifier_store_log_arg, action='store_true', help=help_log) cls.argument_parser.add_argument(qualifier_suffix_arg, metavar='SUFFIX', type=str, help=help_suffix, default='') cls.argument_parser.add_argument(qualifier_dev_arg, action='store_true', help=help_dev) cls.argument_parser.add_argument(qualifier_codegen_opts_arg, metavar='PATH', type=str, help=help_codegen_opts, default='', dest='codegen_opts_fn') parsed_args = cls.argument_parser.parse_args(args) # initialize the logger cls.logging_level = parsed_args.logging_level Logger.init_logger(Logger.string_to_level(parsed_args.logging_level)) cls.handle_input_path(parsed_args.input_path) cls.handle_target(parsed_args.target) cls.handle_target_path(parsed_args.target_path) cls.handle_module_name(parsed_args.module_name) cls.handle_codegen_opts_fn(parsed_args.codegen_opts_fn) cls.store_log = parsed_args.store_log cls.suffix = parsed_args.suffix cls.is_dev = parsed_args.dev
def parse_config(cls, args): """ Standard constructor. This method parses the :param args: a set of arguments as handed over to the frontend :type args: list(str) """ cls.argument_parser = argparse.ArgumentParser( description= '''NESTML is a domain specific language that supports the specification of neuron models in a precise and concise syntax, based on the syntax of Python. Model equations can either be given as a simple string of mathematical notation or as an algorithm written in the built-in procedural language. The equations are analyzed by NESTML to compute an exact solution if possible or use an appropriate numeric solver otherwise. Version ''' + str(pynestml.__version__), formatter_class=argparse.RawDescriptionHelpFormatter) cls.argument_parser.add_argument(qualifier_input_path_arg, metavar='PATH', type=str, help=help_input_path, required=True) cls.argument_parser.add_argument(qualifier_target_path_arg, metavar='PATH', type=str, help=help_target_path) cls.argument_parser.add_argument(qualifier_target_arg, choices=['NEST', 'none'], type=str, help=help_target, default='NEST') cls.argument_parser.add_argument( qualifier_logging_level_arg, metavar='{INFO, WARNING, ERROR, NONE}', choices=[ 'INFO', 'WARNING', 'WARNINGS', 'ERROR', 'ERRORS', 'NONE', 'NO' ], type=str, help=help_logging, default='ERROR') cls.argument_parser.add_argument(qualifier_module_name_arg, metavar='NAME', type=str, help=help_module) cls.argument_parser.add_argument(qualifier_store_log_arg, action='store_true', help=help_log) cls.argument_parser.add_argument(qualifier_suffix_arg, metavar='SUFFIX', type=str, help=help_suffix, default='') cls.argument_parser.add_argument(qualifier_dev_arg, action='store_true', help=help_dev) parsed_args = cls.argument_parser.parse_args(args) # initialize the logger cls.logging_level = parsed_args.logging_level Logger.init_logger(Logger.string_to_level(parsed_args.logging_level)) cls.handle_input_path(parsed_args.input_path) cls.handle_target(parsed_args.target) cls.handle_target_path(parsed_args.target_path) # parse or compose the module name if parsed_args.module_name is not None: if not parsed_args.module_name.endswith('module'): raise Exception( 'Invalid module name specified ("' + parsed_args.module_name + '"): the module name should end with the word "module"') if not re.match('[a-zA-Z_][a-zA-Z0-9_]*\Z', parsed_args.module_name): raise Exception('The specified module name ("' + parsed_args.module_name + '") cannot be parsed as a C variable name') cls.module_name = parsed_args.module_name elif os.path.isfile(parsed_args.input_path): cls.module_name = 'nestmlmodule' Logger.log_message( code=MessageCode.MODULE_NAME_INFO, message= 'No module name specified; the generated module will be named "' + cls.module_name + '"', log_level=LoggingLevel.INFO) elif os.path.isdir(parsed_args.input_path): cls.module_name = os.path.basename( os.path.normpath(parsed_args.input_path)) if not re.match('[a-zA-Z_][a-zA-Z0-9_]*\Z', cls.module_name): raise Exception( 'No module name specified; tried to use the input directory name ("' + cls.module_name + '"), but it cannot be parsed as a C variable name') if not cls.module_name.endswith('module'): cls.module_name += 'module' Logger.log_message( code=MessageCode.MODULE_NAME_INFO, message= 'No module name specified; the generated module will be named "' + cls.module_name + '"', log_level=LoggingLevel.INFO) else: assert False # input_path should be either a file or a directory; failure should have been caught already by handle_input_path() cls.store_log = parsed_args.store_log cls.suffix = parsed_args.suffix cls.is_dev = parsed_args.dev
def config(cls, _args=None): """ Standard constructor. :param _args: a set of arguments as handed over to the frontend :type _args: list(str) """ cls.argument_parser = argparse.ArgumentParser( description= 'NESTML is a domain specific language that supports the specification of neuron models in a' ' precise and concise syntax, based on the syntax of Python. Model equations can either be ' ' given as a simple string of mathematical notation or as an algorithm written in the built-in ' ' procedural language. The equations are analyzed by NESTML to compute an exact solution' ' if possible or use an appropriate numeric solver otherwise.' ' Version 0.0.6, beta.') cls.argument_parser.add_argument('-path', type=str, nargs='+', help=help_path) cls.argument_parser.add_argument('-target', metavar='Target', type=str, nargs='?', help=help_target) cls.argument_parser.add_argument('-dry', action='store_true', help=help_dry) cls.argument_parser.add_argument('-logging_level', type=str, nargs='+', help=help_logging) cls.argument_parser.add_argument('-module_name', type=str, nargs='+', help=help_module) cls.argument_parser.add_argument('-store_log', action='store_true', help=help_log) cls.argument_parser.add_argument('-dev', action='store_true', help=help_dev) parsed_args = cls.argument_parser.parse_args(_args) cls.provided_path = parsed_args.path if cls.provided_path is None: # check if the mandatory path arg has been handed over, just terminate raise InvalidPathException('Invalid source path!') cls.paths_to_compilation_units = list() if parsed_args.path is None: raise InvalidPathException('Invalid source path!') elif os.path.isfile(parsed_args.path[0]): cls.paths_to_compilation_units.append(parsed_args.path[0]) elif os.path.isdir(parsed_args.path[0]): for filename in os.listdir(parsed_args.path[0]): if filename.endswith(".nestml"): cls.paths_to_compilation_units.append( os.path.join(parsed_args.path[0], filename)) else: cls.paths_to_compilation_units = parsed_args.path[0] raise InvalidPathException('Incorrect path provided' + parsed_args.path[0]) # initialize the logger if parsed_args.logging_level is not None: cls.logging_level = parsed_args.logging_level Logger.init_logger( Logger.string_to_level(parsed_args.logging_level[0])) else: cls.logging_level = "ERROR" Logger.init_logger(Logger.string_to_level("ERROR")) # check if a dry run shall be preformed, i.e. without generating a target model cls.dry_run = parsed_args.dry # now update the target path cls.handle_target_path(parsed_args.target) # now adjust the name of the module, if it is a single file, then it is called just module if parsed_args.module_name is not None: cls.module_name = parsed_args.module_name[0] elif os.path.isfile(parsed_args.path[0]): cls.module_name = 'module' elif os.path.isdir(parsed_args.path[0]): cls.module_name = os.path.basename( os.path.normpath(parsed_args.path[0])) else: cls.module_name = 'module' cls.store_log = parsed_args.store_log cls.is_debug = parsed_args.dev return