From 5f3f04bd0a42d26192e0fcbda3625b7596a347a4 Mon Sep 17 00:00:00 2001 From: ines Date: Thu, 16 Mar 2017 17:10:05 +0100 Subject: [PATCH] Add util function to load and parse package meta.json --- spacy/util.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/spacy/util.py b/spacy/util.py index 7873bec0c..946ce6aab 100644 --- a/spacy/util.py +++ b/spacy/util.py @@ -149,6 +149,18 @@ def check_renamed_kwargs(renamed, kwargs): raise TypeError("Keyword argument %s now renamed to %s" % (old, new)) +def parse_package_meta(package_path, package): + location = os.path.join(str(package_path), package, 'meta.json') + if not os.path.isfile(location): + print_msg("'{p}' doesn't seem to be a valid model package.".format(p=package), + title="No meta.json found") + else: + with io.open(location, encoding='utf8') as f: + meta = json.load(f) + return meta + return False + + def print_msg(*text, **kwargs): """Print formatted message. Each positional argument is rendered as newline- separated paragraph. If kwarg 'title' exist, title is printed above the text