def __init__(self, target, options: Optional[Mapping[str, Any]] = None): super(CodeGenerator, self).__init__(options) from pynestml.frontend.pynestml_frontend import get_known_targets if not target.upper() in get_known_targets(): code, msg = Messages.get_unknown_target(target) Logger.log_message(message=msg, code=code, log_level=LoggingLevel.ERROR) self._target = "" raise InvalidTargetException() self._target = target
def handle_target_platform(cls, target_platform: Optional[str]): if target_platform is None or target_platform.upper() == 'NONE': target_platform = '' # make sure `target_platform` is always a string from pynestml.frontend.pynestml_frontend import get_known_targets if target_platform.upper() not in get_known_targets(): code, message = Messages.get_unknown_target_platform( target_platform) Logger.log_message(None, code, message, None, LoggingLevel.ERROR) raise InvalidTargetException() cls.target_platform = target_platform
def builder_from_target_name( target_name: str, options: Optional[Mapping[str, Any]] = None) -> Builder: r"""Static factory method that returns a new instance of a child class of Builder""" from pynestml.frontend.pynestml_frontend import get_known_targets assert target_name.upper() in get_known_targets( ), "Unknown target platform requested: \"" + str(target_name) + "\"" if target_name.upper() in ["NEST", "NEST2"]: from pynestml.codegeneration.nest_builder import NESTBuilder return NESTBuilder(options) return None # no builder requested or available
def code_generator_from_target_name( target_name: str, options: Optional[Mapping[str, Any]] = None) -> CodeGenerator: """Static factory method that returns a new instance of a child class of CodeGenerator""" assert target_name.upper() in get_known_targets( ), "Unknown target platform requested: \"" + str(target_name) + "\"" if target_name.upper() == "NEST": from pynestml.codegeneration.nest_code_generator import NESTCodeGenerator return NESTCodeGenerator(options) elif target_name.upper() == "NEST2": from pynestml.codegeneration.nest2_code_generator import NEST2CodeGenerator return NEST2CodeGenerator(options) elif target_name.upper() == "AUTODOC": from pynestml.codegeneration.autodoc_code_generator import AutoDocCodeGenerator assert options is None or options == {}, "\"autodoc\" code generator does not support options" return AutoDocCodeGenerator() elif target_name.upper() == "NONE": # dummy/null target: user requested to not generate any code code, message = Messages.get_no_code_generated() Logger.log_message(None, code, message, None, LoggingLevel.INFO) return CodeGenerator("", options) assert "Unknown code generator requested: " + target_name # cannot reach here due to earlier assert -- silence static checker warnings
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) """ from pynestml.frontend.pynestml_frontend import get_known_targets 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_install_path_arg, metavar='PATH', type=str, help=help_install_path) cls.argument_parser.add_argument(qualifier_target_platform_arg, choices=get_known_targets(), type=str.upper, 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 = Logger.level_to_string( Logger.string_to_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_platform(parsed_args.target_platform) cls.handle_target_path(parsed_args.target_path) cls.handle_install_path(parsed_args.install_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