2017-03-18 15:01:16 +03:00
|
|
|
# coding: utf8
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2017-05-22 13:28:58 +03:00
|
|
|
import plac
|
2017-03-18 15:01:16 +03:00
|
|
|
import platform
|
|
|
|
from pathlib import Path
|
2017-03-18 20:57:45 +03:00
|
|
|
|
2017-05-08 00:25:29 +03:00
|
|
|
from ..compat import path2str
|
2017-03-18 17:14:48 +03:00
|
|
|
from .. import about
|
|
|
|
from .. import util
|
2017-03-18 15:01:16 +03:00
|
|
|
|
|
|
|
|
2017-05-22 13:28:58 +03:00
|
|
|
@plac.annotations(
|
|
|
|
model=("optional: shortcut link of model", "positional", None, str),
|
2017-10-27 15:38:39 +03:00
|
|
|
markdown=("generate Markdown for GitHub issues", "flag", "md", str))
|
2017-05-27 21:01:46 +03:00
|
|
|
def info(cmd, model=None, markdown=False):
|
2017-05-22 13:28:58 +03:00
|
|
|
"""Print info about spaCy installation. If a model shortcut link is
|
|
|
|
speficied as an argument, print model information. Flag --markdown
|
|
|
|
prints details in Markdown for easy copy-pasting to GitHub issues.
|
|
|
|
"""
|
2017-03-18 15:01:16 +03:00
|
|
|
if model:
|
2017-05-28 01:22:00 +03:00
|
|
|
if util.is_package(model):
|
|
|
|
model_path = util.get_package_path(model)
|
|
|
|
else:
|
|
|
|
model_path = util.get_data_path() / model
|
|
|
|
meta_path = model_path / 'meta.json'
|
|
|
|
if not meta_path.is_file():
|
2017-06-01 17:46:15 +03:00
|
|
|
util.prints(meta_path, title="Can't find model meta.json", exits=1)
|
2017-06-04 21:44:15 +03:00
|
|
|
meta = util.read_json(meta_path)
|
2017-03-18 15:01:16 +03:00
|
|
|
if model_path.resolve() != model_path:
|
2017-05-20 13:24:40 +03:00
|
|
|
meta['link'] = path2str(model_path)
|
|
|
|
meta['source'] = path2str(model_path.resolve())
|
2017-03-18 15:01:16 +03:00
|
|
|
else:
|
2017-05-20 13:24:40 +03:00
|
|
|
meta['source'] = path2str(model_path)
|
|
|
|
print_info(meta, 'model %s' % model, markdown)
|
2017-03-18 15:01:16 +03:00
|
|
|
else:
|
2017-05-08 00:25:29 +03:00
|
|
|
data = {'spaCy version': about.__version__,
|
|
|
|
'Location': path2str(Path(__file__).parent.parent),
|
|
|
|
'Platform': platform.platform(),
|
|
|
|
'Python version': platform.python_version(),
|
|
|
|
'Models': list_models()}
|
|
|
|
print_info(data, 'spaCy', markdown)
|
2017-03-18 15:01:16 +03:00
|
|
|
|
|
|
|
|
|
|
|
def print_info(data, title, markdown):
|
2017-05-08 00:25:29 +03:00
|
|
|
title = 'Info about %s' % title
|
2017-03-18 15:01:16 +03:00
|
|
|
if markdown:
|
|
|
|
util.print_markdown(data, title=title)
|
|
|
|
else:
|
|
|
|
util.print_table(data, title=title)
|
|
|
|
|
|
|
|
|
|
|
|
def list_models():
|
2017-05-08 00:25:29 +03:00
|
|
|
def exclude_dir(dir_name):
|
|
|
|
# exclude common cache directories and hidden directories
|
|
|
|
exclude = ['cache', 'pycache', '__pycache__']
|
|
|
|
return dir_name in exclude or dir_name.startswith('.')
|
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()]
|
2017-05-08 00:25:29 +03:00
|
|
|
return ', '.join([m for m in models if not exclude_dir(m)])
|
|
|
|
return '-'
|