From ce7eec846bf2834f3e4013b1c7c8a095f1ee2e8e Mon Sep 17 00:00:00 2001 From: Ines Montani Date: Sat, 1 Dec 2018 04:55:48 +0100 Subject: [PATCH] Move CLi-specific Markdown helper to CLI --- spacy/cli/info.py | 27 ++++++++++++++++++++++++--- spacy/util.py | 23 +---------------------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/spacy/cli/info.py b/spacy/cli/info.py index 90387f9f7..8e239363e 100644 --- a/spacy/cli/info.py +++ b/spacy/cli/info.py @@ -7,7 +7,7 @@ from pathlib import Path from wasabi import Printer from ._messages import Messages -from ..compat import path2str +from ..compat import path2str, basestring_, unicode_ from .. import util 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") } if markdown: - util.print_markdown(model_meta, title=title) + print_markdown(model_meta, title=title) else: msg.table(model_meta, title=title) return meta @@ -58,7 +58,7 @@ def info(model=None, markdown=False, silent=False): if not silent: title = "Info about spaCy" if markdown: - util.print_markdown(data, title=title) + print_markdown(data, title=title) else: msg.table(data, title=title) return data @@ -75,3 +75,24 @@ def list_models(): 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 "-" + + +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))) diff --git a/spacy/util.py b/spacy/util.py index 927a69796..d8c82da89 100644 --- a/spacy/util.py +++ b/spacy/util.py @@ -18,7 +18,7 @@ import numpy.random 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 .errors import Errors @@ -621,27 +621,6 @@ def from_disk(path, readers, exclude): 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): """Perform a template-specific, rudimentary HTML minification for displaCy. Disclaimer: NOT a general-purpose solution, only removes indentation and