Exemplo n.º 1
0
def _configure(args: argparse.Namespace) -> None:
    cla55 = args.cla55
    parts = cla55.split(".")
    module = ".".join(parts[:-1])
    class_name = parts[-1]

    print()

    try:
        config = configure(cla55)
        if isinstance(config, Config):
            if cla55:
                print(f"configuration stub for {cla55}:\n")
            else:
                print(f"configuration stub for AllenNLP:\n")
            print(render_config(config))
        else:
            print(f"{class_name} is an abstract base class, choose one of the following subclasses:\n")
            for subclass in config:
                print("\t", subclass)
    except ModuleNotFoundError:
        print(f"unable to load module {module}")
    except AttributeError:
        print(f"class {class_name} does not exist in module {module}")

    print()
Exemplo n.º 2
0
    def api() -> Response:  # pylint: disable=unused-variable
        class_name = request.args.get('class', '')

        config = configure(class_name)

        if isinstance(config, Config):
            return jsonify({
                "className": class_name,
                "config": config.to_json()
            })
        else:
            return jsonify({"className": class_name, "choices": config})
Exemplo n.º 3
0
    def test_specific_subclass(self):
        config = configure(
            'allennlp.data.dataset_readers.semantic_role_labeling.SrlReader')
        assert isinstance(config, Config)

        items = {item.name: item for item in config.items}

        assert len(items) == 3

        assert 'token_indexers' in items
        token_indexers = items['token_indexers']
        assert token_indexers.default_value is None

        assert 'domain_identifier' in items
        domain_identifier = items['domain_identifier']
        assert domain_identifier.annotation == str
        assert domain_identifier.default_value is None

        assert 'lazy' in items
        lazy = items['lazy']
        assert lazy.annotation == bool
        assert not lazy.default_value
Exemplo n.º 4
0
    def test_configure_top_level(self):
        config = configure()

        assert config == BASE_CONFIG
Exemplo n.º 5
0
    def test_errors(self):
        with pytest.raises(ModuleNotFoundError):
            configure('allennlp.non_existent_module.SomeClass')

        with pytest.raises(AttributeError):
            configure('allennlp.data.dataset_readers.NonExistentDatasetReader')
Exemplo n.º 6
0
    def test_abstract_base_class(self):
        config = configure(
            'allennlp.data.dataset_readers.dataset_reader.DatasetReader')

        assert isinstance(config, list)
        assert 'allennlp.data.dataset_readers.snli.SnliReader' in config