mirror of
https://github.com/explosion/spaCy.git
synced 2025-01-13 18:56:36 +03:00
Fix loading when no package found
This commit is contained in:
parent
5c66cffafd
commit
adb0b7e43b
|
@ -35,14 +35,16 @@ set_lang_class(bn.Bengali.lang, bn.Bengali)
|
||||||
|
|
||||||
def load(name, **overrides):
|
def load(name, **overrides):
|
||||||
data_path = overrides.get('path', util.get_data_path())
|
data_path = overrides.get('path', util.get_data_path())
|
||||||
meta = parse_package_meta(data_path, name)
|
meta = parse_package_meta(data_path, name, require=False)
|
||||||
lang = meta['lang'] if meta and 'lang' in meta else 'en'
|
lang = meta['lang'] if meta and 'lang' in meta else name
|
||||||
cls = get_lang_class(lang)
|
cls = get_lang_class(lang)
|
||||||
overrides['meta'] = meta
|
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)
|
return cls(**overrides)
|
||||||
|
|
||||||
|
|
||||||
def info(name):
|
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))
|
print(json.dumps(meta, indent=2))
|
||||||
|
|
|
@ -149,15 +149,16 @@ def check_renamed_kwargs(renamed, kwargs):
|
||||||
raise TypeError("Keyword argument %s now renamed to %s" % (old, new))
|
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')
|
location = os.path.join(str(package_path), package, 'meta.json')
|
||||||
if not os.path.isfile(location) and on_error:
|
if os.path.isfile(location):
|
||||||
on_error()
|
|
||||||
else:
|
|
||||||
with io.open(location, encoding='utf8') as f:
|
with io.open(location, encoding='utf8') as f:
|
||||||
meta = json.load(f)
|
meta = json.load(f)
|
||||||
return meta
|
return meta
|
||||||
return False
|
elif require:
|
||||||
|
raise IOError("Could not read meta.json from %s" % location)
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def print_msg(*text, **kwargs):
|
def print_msg(*text, **kwargs):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user