2017-03-18 12:01:16 +00:00
|
|
|
# coding: utf8
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
import platform
|
|
|
|
from pathlib import Path
|
2017-03-18 17:57:45 +00:00
|
|
|
|
2017-05-07 21:25:29 +00:00
|
|
|
from ..compat import path2str
|
2017-03-18 14:14:48 +00:00
|
|
|
from .. import about
|
|
|
|
from .. import util
|
2017-03-18 12:01:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
def info(model=None, markdown=False):
|
|
|
|
if model:
|
2017-05-20 10:24:40 +00:00
|
|
|
model_path = util.resolve_model_path(model)
|
|
|
|
meta = util.parse_package_meta(model_path)
|
2017-03-18 12:01:16 +00:00
|
|
|
if model_path.resolve() != model_path:
|
2017-05-20 10:24:40 +00:00
|
|
|
meta['link'] = path2str(model_path)
|
|
|
|
meta['source'] = path2str(model_path.resolve())
|
2017-03-18 12:01:16 +00:00
|
|
|
else:
|
2017-05-20 10:24:40 +00:00
|
|
|
meta['source'] = path2str(model_path)
|
|
|
|
print_info(meta, 'model %s' % model, markdown)
|
2017-03-18 12:01:16 +00:00
|
|
|
else:
|
2017-05-07 21:25:29 +00: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 12:01:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
def print_info(data, title, markdown):
|
2017-05-07 21:25:29 +00:00
|
|
|
title = 'Info about %s' % title
|
2017-03-18 12:01:16 +00:00
|
|
|
if markdown:
|
|
|
|
util.print_markdown(data, title=title)
|
|
|
|
else:
|
|
|
|
util.print_table(data, title=title)
|
|
|
|
|
|
|
|
|
|
|
|
def list_models():
|
2017-05-07 21:25:29 +00: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 12:01:16 +00:00
|
|
|
data_path = util.get_data_path()
|
2017-04-14 14:48:02 +00:00
|
|
|
if data_path:
|
|
|
|
models = [f.parts[-1] for f in data_path.iterdir() if f.is_dir()]
|
2017-05-07 21:25:29 +00:00
|
|
|
return ', '.join([m for m in models if not exclude_dir(m)])
|
|
|
|
return '-'
|