Let parse_package_meta take full path

This commit is contained in:
ines 2017-05-08 15:30:48 +02:00
parent 326746eb15
commit 95edd9e896
2 changed files with 4 additions and 7 deletions

View File

@ -12,7 +12,7 @@ from .. import util
def info(model=None, markdown=False): def info(model=None, markdown=False):
if model: if model:
data_path = util.get_data_path() data_path = util.get_data_path()
data = util.parse_package_meta(data_path, model, require=True) data = util.parse_package_meta(data_path / model, require=True)
model_path = Path(__file__).parent / data_path / model model_path = Path(__file__).parent / data_path / model
if model_path.resolve() != model_path: if model_path.resolve() != model_path:
data['link'] = path2str(model_path) data['link'] = path2str(model_path)

View File

@ -142,20 +142,17 @@ def get_model_package_path(package_name):
# Python's installation and import rules are very complicated. # Python's installation and import rules are very complicated.
pkg = importlib.import_module(package_name) pkg = importlib.import_module(package_name)
package_path = Path(pkg.__file__).parent.parent package_path = Path(pkg.__file__).parent.parent
meta = parse_package_meta(package_path, package_name) meta = parse_package_meta(package_path / package_name)
model_name = '%s-%s' % (package_name, meta['version']) model_name = '%s-%s' % (package_name, meta['version'])
return package_path / package_name / model_name return package_path / package_name / model_name
def parse_package_meta(package_path, package, require=True): def parse_package_meta(package_path, require=True):
""" """
Check if a meta.json exists in a package and return its contents as a Check if a meta.json exists in a package and return its contents as a
dictionary. If require is set to True, raise an error if no meta.json found. dictionary. If require is set to True, raise an error if no meta.json found.
""" """
# TODO: Allow passing in full model path and only require one argument location = package_path / 'meta.json'
# instead of path and package name. This lets us avoid passing in an awkward
# empty string in spacy.load() if user supplies full model path.
location = package_path / package / 'meta.json'
if location.is_file(): if location.is_file():
return read_json(location) return read_json(location)
elif require: elif require: