Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
honnibal committed Feb 1, 2018
2 parents a437ba8 + 3c1fb9d commit 6b1126c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
7 changes: 5 additions & 2 deletions spacy/cli/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ def validate():
prints("Couldn't fetch compatibility table.",
title="Server error (%d)" % r.status_code, exits=1)
compat = r.json()['spacy']
current_compat = compat.get(about.__version__)
if not current_compat:
prints(about.__compatibility__, exits=1,
title="Can't find spaCy v{} in compatibility table"
.format(about.__version__))
all_models = set()
for spacy_v, models in dict(compat).items():
all_models.update(models.keys())
for model, model_vs in models.items():
compat[spacy_v][model] = [reformat_version(v) for v in model_vs]

current_compat = compat[about.__version__]
model_links = get_model_links(current_compat)
model_pkgs = get_model_pkgs(current_compat, all_models)
incompat_links = {l for l, d in model_links.items() if not d['compat']}
Expand Down
8 changes: 8 additions & 0 deletions spacy/language.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,14 @@ def add_pipe(self, component, name=None, before=None, after=None,
>>> nlp.add_pipe(component, before='ner')
>>> nlp.add_pipe(component, name='custom_name', last=True)
"""
if not hasattr(component, '__call__'):
msg = ("Not a valid pipeline component. Expected callable, but "
"got {}. ".format(repr(component)))
if isinstance(component, basestring_) and component in self.factories:
msg += ("If you meant to add a built-in component, use "
"create_pipe: nlp.add_pipe(nlp.create_pipe('{}'))"
.format(component))
raise ValueError(msg)
if name is None:
if hasattr(component, 'name'):
name = component.name
Expand Down
6 changes: 6 additions & 0 deletions spacy/tests/pipeline/test_pipe_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,9 @@ def test_add_lots_of_pipes(nlp, n_pipes):
for i in range(n_pipes):
nlp.add_pipe(lambda doc: doc, name='pipe_%d' % i)
assert len(nlp.pipe_names) == n_pipes


@pytest.mark.parametrize('component', ['ner', {'hello': 'world'}])
def test_raise_for_invalid_components(nlp, component):
with pytest.raises(ValueError):
nlp.add_pipe(component)
2 changes: 1 addition & 1 deletion website/usage/_install/_instructions.jade
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ p
python -m pytest <spacy-directory> --models --en # basic and English model tests

+infobox("Note on model tests", "⚠️")
| The test suite specifies a #[+a(gh("spacy", "tests/conftest.py")) list of models]
| The test suite specifies a #[+a(gh("spacy", "spacy/tests/conftest.py")) list of models]
| to run the tests on. If a model is not installed, the tests will be
| skipped. If all models are installed, the respective tests will run once
| for each model. The easiest way to find out which models and model
Expand Down

0 comments on commit 6b1126c

Please sign in to comment.