mirror of
https://github.com/explosion/spaCy.git
synced 2025-02-13 10:00:34 +03:00
Move CLi-specific Markdown helper to CLI
This commit is contained in:
parent
40ae499f32
commit
ce7eec846b
|
@ -7,7 +7,7 @@ from pathlib import Path
|
||||||
from wasabi import Printer
|
from wasabi import Printer
|
||||||
|
|
||||||
from ._messages import Messages
|
from ._messages import Messages
|
||||||
from ..compat import path2str
|
from ..compat import path2str, basestring_, unicode_
|
||||||
from .. import util
|
from .. import util
|
||||||
from .. import about
|
from .. import about
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ def info(model=None, markdown=False, silent=False):
|
||||||
k: v for k, v in meta.items() if k not in ("accuracy", "speed")
|
k: v for k, v in meta.items() if k not in ("accuracy", "speed")
|
||||||
}
|
}
|
||||||
if markdown:
|
if markdown:
|
||||||
util.print_markdown(model_meta, title=title)
|
print_markdown(model_meta, title=title)
|
||||||
else:
|
else:
|
||||||
msg.table(model_meta, title=title)
|
msg.table(model_meta, title=title)
|
||||||
return meta
|
return meta
|
||||||
|
@ -58,7 +58,7 @@ def info(model=None, markdown=False, silent=False):
|
||||||
if not silent:
|
if not silent:
|
||||||
title = "Info about spaCy"
|
title = "Info about spaCy"
|
||||||
if markdown:
|
if markdown:
|
||||||
util.print_markdown(data, title=title)
|
print_markdown(data, title=title)
|
||||||
else:
|
else:
|
||||||
msg.table(data, title=title)
|
msg.table(data, title=title)
|
||||||
return data
|
return data
|
||||||
|
@ -75,3 +75,24 @@ def list_models():
|
||||||
models = [f.parts[-1] for f in data_path.iterdir() if f.is_dir()]
|
models = [f.parts[-1] for f in data_path.iterdir() if f.is_dir()]
|
||||||
return ", ".join([m for m in models if not exclude_dir(m)])
|
return ", ".join([m for m in models if not exclude_dir(m)])
|
||||||
return "-"
|
return "-"
|
||||||
|
|
||||||
|
|
||||||
|
def print_markdown(data, title=None):
|
||||||
|
"""Print data in GitHub-flavoured Markdown format for issues etc.
|
||||||
|
|
||||||
|
data (dict or list of tuples): Label/value pairs.
|
||||||
|
title (unicode or None): Title, will be rendered as headline 2.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def excl_value(value):
|
||||||
|
# contains path, i.e. personal info
|
||||||
|
return isinstance(value, basestring_) and Path(value).exists()
|
||||||
|
|
||||||
|
if isinstance(data, dict):
|
||||||
|
data = list(data.items())
|
||||||
|
markdown = [
|
||||||
|
"* **{}:** {}".format(l, unicode_(v)) for l, v in data if not excl_value(v)
|
||||||
|
]
|
||||||
|
if title:
|
||||||
|
print("\n## {}".format(title))
|
||||||
|
print("\n{}\n".format("\n".join(markdown)))
|
||||||
|
|
|
@ -18,7 +18,7 @@ import numpy.random
|
||||||
|
|
||||||
|
|
||||||
from .symbols import ORTH
|
from .symbols import ORTH
|
||||||
from .compat import cupy, CudaStream, path2str, basestring_, input_, unicode_
|
from .compat import cupy, CudaStream, path2str, basestring_, unicode_
|
||||||
from .compat import import_file, json_dumps
|
from .compat import import_file, json_dumps
|
||||||
from .errors import Errors
|
from .errors import Errors
|
||||||
|
|
||||||
|
@ -621,27 +621,6 @@ def from_disk(path, readers, exclude):
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
|
||||||
def print_markdown(data, title=None):
|
|
||||||
"""Print data in GitHub-flavoured Markdown format for issues etc.
|
|
||||||
|
|
||||||
data (dict or list of tuples): Label/value pairs.
|
|
||||||
title (unicode or None): Title, will be rendered as headline 2.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def excl_value(value):
|
|
||||||
# contains path, i.e. personal info
|
|
||||||
return isinstance(value, basestring_) and Path(value).exists()
|
|
||||||
|
|
||||||
if isinstance(data, dict):
|
|
||||||
data = list(data.items())
|
|
||||||
markdown = [
|
|
||||||
"* **{}:** {}".format(l, unicode_(v)) for l, v in data if not excl_value(v)
|
|
||||||
]
|
|
||||||
if title:
|
|
||||||
print("\n## {}".format(title))
|
|
||||||
print("\n{}\n".format("\n".join(markdown)))
|
|
||||||
|
|
||||||
|
|
||||||
def minify_html(html):
|
def minify_html(html):
|
||||||
"""Perform a template-specific, rudimentary HTML minification for displaCy.
|
"""Perform a template-specific, rudimentary HTML minification for displaCy.
|
||||||
Disclaimer: NOT a general-purpose solution, only removes indentation and
|
Disclaimer: NOT a general-purpose solution, only removes indentation and
|
||||||
|
|
Loading…
Reference in New Issue
Block a user