示例#1
0
    def test_parser_args(self):
        # create target config object
        target = dummy_config.DummyConfig()
        target.x = 3
        target.y = "abc"
        # z is NOT specified

        # TEST: parse config using positional args
        sys.argv = "test --x TRES abc".split(" ")
        self.assertEqual(
                target,
                argmagic.parse_args(dummy_config.DummyConfig, positional_args=True)
        )

        # TEST: parse config without positional args
        sys.argv = "test --y abc --x TRES".split(" ")
        self.assertEqual(
                target,
                argmagic.parse_args(dummy_config.DummyConfig, positional_args=False)
        )
        
        # create target config object
        target = dummy_config_2.DummyConfig2()
        target.a = "1"
        target.b = "2"
        target.c = "3"
        
        # parse args
        sys.argv = "test 3 1 2".split(" ")
        parsed = argmagic.parse_args(dummy_config_2.DummyConfig2)
        
        self.assertEqual(target, parsed)
示例#2
0
        if os.path.isfile(data_path):
            print("discovered data at '{}'".format(data_path))
        else:
            print("downloading data to '{}'...".format(data_path))
            urllib.request.urlretrieve(DATA_URL, data_path)
        conf.data = data_path
        print("OK\n")

    # load the data from disk
    print("loading data from '{}'...".format(conf.data))
    data = _load_data(conf.data)
    print("found data about {} countries".format(len(data)))
    print("OK\n")

    # invoke dataset generator to create the required datasets
    print("generating {} dataset{} with {} training sample{}\n".format(
        conf.num_datasets, "s" if conf.num_datasets > 1 else "",
        conf.num_training_samples,
        "s" if conf.num_training_samples > 1 else ""))
    generator = data_gen.DatasetGenerator(data, conf.setting,
                                          dlv_solver.DlvSolver(conf.dlv),
                                          ONTOLOGY, conf.class_facts)
    generator.generate_datasets(conf.num_datasets, conf.num_training_samples,
                                conf.output_dir)


main(
    argmagic.parse_args(config.Config,
                        app_name=APP_NAME,
                        app_description=APP_DESCRIPTION))
示例#3
0
        return self._name

    @name.setter
    def name(self, name: str) -> None:
        if not isinstance(name, str):
            raise TypeError(
                "The arg <name> has to be of type str, but is %s!" %
                type(name))
        self._name = name


class DataTypeOption(enum.Enum):
    """Describes the option MyConfig.data_type."""

    INTEGER = int
    STRING = str


# parse the args that were provided to this script
config = argmagic.parse_args(
    MyConfig,
    fixed_types={"data_type": DataTypeOption},
    app_name="Test",
    app_description=
    "This is an example that demonstrates the use of the package argmagic.")

# print the parsed configuration
print("CONFIGURATION OF TYPE %s:" % type(config))
for option, value in argmagic.get_config(config).items():
    print("*", option, "-", value)
示例#4
0
        print(("{:" + str(max_name_len) + "} : {}").format(name, value))
    print(h_line)
    print()


def main(conf: config.Config):
    
    # create output directory if it does not exist yet
    if not os.path.isdir(conf.output_dir):
        os.mkdir(conf.output_dir)
    
    # set up logging
    streamtologger.redirect(
            os.path.join(conf.output_dir, LOG_FILE_NAME),
            print_to_screen=not conf.quiet,
            append=False,
            header_format=LOG_FILE_HEADER
    )
    
    # seed RNG
    random.seed(conf.seed)
    
    # print user-defined configuration to screen
    _print_config(conf)
    
    # run generator
    generator.Generator.generate(conf)


main(argmagic.parse_args(config.Config, app_name=APP_NAME, app_description=APP_DESCRIPTION, positional_args=True))