diff --git a/spacy/__init__.py b/spacy/__init__.py index ca5a39f05..0b76f1f9e 100644 --- a/spacy/__init__.py +++ b/spacy/__init__.py @@ -35,14 +35,16 @@ set_lang_class(bn.Bengali.lang, bn.Bengali) def load(name, **overrides): data_path = overrides.get('path', util.get_data_path()) - meta = parse_package_meta(data_path, name) - lang = meta['lang'] if meta and 'lang' in meta else 'en' + meta = parse_package_meta(data_path, name, require=False) + lang = meta['lang'] if meta and 'lang' in meta else name cls = get_lang_class(lang) overrides['meta'] = meta - overrides['path'] = Path(data_path / name) + model_path = Path(data_path) / name + if model_path.exists(): + overrides['path'] = model_path return cls(**overrides) def info(name): - meta = parse_package_meta(util.get_data_path(), name) + meta = parse_package_meta(util.get_data_path(), name, require=True) print(json.dumps(meta, indent=2)) diff --git a/spacy/util.py b/spacy/util.py index ef6d9884d..63c57bf69 100644 --- a/spacy/util.py +++ b/spacy/util.py @@ -149,15 +149,16 @@ def check_renamed_kwargs(renamed, kwargs): raise TypeError("Keyword argument %s now renamed to %s" % (old, new)) -def parse_package_meta(package_path, package, on_error=False): +def parse_package_meta(package_path, package, require=True): location = os.path.join(str(package_path), package, 'meta.json') - if not os.path.isfile(location) and on_error: - on_error() - else: + if os.path.isfile(location): with io.open(location, encoding='utf8') as f: meta = json.load(f) return meta - return False + elif require: + raise IOError("Could not read meta.json from %s" % location) + else: + return None def print_msg(*text, **kwargs):