mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-25 17:36:30 +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):
|
||||
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))
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue
Block a user