2017-03-18 15:01:16 +03:00
|
|
|
|
# coding: utf8
|
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
|
|
import platform
|
|
|
|
|
from pathlib import Path
|
2017-03-18 20:57:45 +03:00
|
|
|
|
|
2017-04-17 02:29:54 +03:00
|
|
|
|
from ..compat import unicode_
|
2017-03-18 17:14:48 +03:00
|
|
|
|
from .. import about
|
|
|
|
|
from .. import util
|
2017-03-18 15:01:16 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def info(model=None, markdown=False):
|
|
|
|
|
if model:
|
|
|
|
|
data = util.parse_package_meta(util.get_data_path(), model, require=True)
|
|
|
|
|
model_path = Path(__file__).parent / util.get_data_path() / model
|
|
|
|
|
if model_path.resolve() != model_path:
|
2017-04-17 02:29:54 +03:00
|
|
|
|
data['link'] = unicode_(model_path)
|
|
|
|
|
data['source'] = unicode_(model_path.resolve())
|
2017-03-18 15:01:16 +03:00
|
|
|
|
else:
|
2017-04-17 02:29:54 +03:00
|
|
|
|
data['source'] = unicode_(model_path)
|
2017-03-18 15:01:16 +03:00
|
|
|
|
print_info(data, "model " + model, markdown)
|
|
|
|
|
else:
|
|
|
|
|
data = get_spacy_data()
|
|
|
|
|
print_info(data, "spaCy", markdown)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def print_info(data, title, markdown):
|
|
|
|
|
title = "Info about {title}".format(title=title)
|
|
|
|
|
if markdown:
|
|
|
|
|
util.print_markdown(data, title=title)
|
|
|
|
|
else:
|
|
|
|
|
util.print_table(data, title=title)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_spacy_data():
|
|
|
|
|
return {
|
|
|
|
|
'spaCy version': about.__version__,
|
2017-04-17 02:29:54 +03:00
|
|
|
|
'Location': unicode_(Path(__file__).parent.parent),
|
2017-03-18 15:01:16 +03:00
|
|
|
|
'Platform': platform.platform(),
|
|
|
|
|
'Python version': platform.python_version(),
|
|
|
|
|
'Installed models': ', '.join(list_models())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def list_models():
|
2017-03-19 03:43:19 +03:00
|
|
|
|
# exclude common cache directories – this means models called "cache" etc.
|
|
|
|
|
# won't show up in list, but it seems worth it
|
|
|
|
|
exclude = ['cache', 'pycache', '__pycache__']
|
2017-03-18 15:01:16 +03:00
|
|
|
|
data_path = util.get_data_path()
|
2017-04-14 17:48:02 +03:00
|
|
|
|
if data_path:
|
|
|
|
|
models = [f.parts[-1] for f in data_path.iterdir() if f.is_dir()]
|
|
|
|
|
return [m for m in models if m not in exclude]
|