Update wasabi: new diff_strings and MarkdownRenderer

This commit is contained in:
Ines Montani 2020-08-26 15:33:11 +02:00
parent 79d460e3a2
commit 3aec98ca38
4 changed files with 11 additions and 42 deletions

View File

@ -5,7 +5,7 @@ thinc>=8.0.0a30,<8.0.0a40
blis>=0.4.0,<0.5.0
ml_datasets>=0.1.1
murmurhash>=0.28.0,<1.1.0
wasabi>=0.7.1,<1.1.0
wasabi>=0.8.0,<1.1.0
srsly>=2.1.0,<3.0.0
catalogue>=0.0.7,<1.1.0
typer>=0.3.0,<0.4.0

View File

@ -42,7 +42,7 @@ install_requires =
preshed>=3.0.2,<3.1.0
thinc>=8.0.0a30,<8.0.0a40
blis>=0.4.0,<0.5.0
wasabi>=0.7.1,<1.1.0
wasabi>=0.8.0,<1.1.0
srsly>=2.1.0,<3.0.0
catalogue>=0.0.7,<1.1.0
typer>=0.3.0,<0.4.0

View File

@ -1,7 +1,7 @@
from typing import Optional, Dict, Any, Union
import platform
from pathlib import Path
from wasabi import Printer
from wasabi import Printer, MarkdownRenderer
import srsly
from ._util import app, Arg, Opt
@ -97,12 +97,13 @@ def get_markdown(data: Dict[str, Any], title: Optional[str] = None) -> str:
title (str / None): Title, will be rendered as headline 2.
RETURNS (str): The Markdown string.
"""
markdown = []
md = MarkdownRenderer()
if title:
md.add(md.title(2, title))
items = []
for key, value in data.items():
if isinstance(value, str) and Path(value).exists():
continue
markdown.append(f"* **{key}:** {value}")
result = "\n{}\n".format("\n".join(markdown))
if title:
result = f"\n## {title}\n{result}"
return result
items.append(f"{md.bold(f'{key}:')} {value}")
md.add(md.list(items))
return f"\n{md.text}\n"

View File

@ -1,6 +1,5 @@
from typing import Iterable, Optional
from pathlib import Path
from wasabi import msg
from wasabi import msg, MarkdownRenderer
from ...util import working_dir
from .._util import project_cli, Arg, Opt, PROJECT_FILE, load_project_config
@ -107,34 +106,3 @@ def project_document(
with output_file.open("w") as f:
f.write(content)
msg.good("Saved project documentation", output_file)
class MarkdownRenderer:
"""Simple helper for generating raw Markdown."""
def __init__(self, no_emoji: bool = False):
self.data = []
self.no_emoji = no_emoji
@property
def text(self):
return "\n\n".join(self.data)
def add(self, content: str) -> None:
self.data.append(content)
def table(self, data: Iterable[Iterable[str]], header: Iterable[str]) -> str:
head = f"| {' | '.join(header)} |"
divider = f"| {' | '.join('---' for _ in header)} |"
body = "\n".join(f"| {' | '.join(row)} |" for row in data)
return f"{head}\n{divider}\n{body}"
def title(self, level: int, text: str, emoji: Optional[str] = None) -> str:
prefix = f"{emoji} " if emoji and not self.no_emoji else ""
return f"{'#' * level} {prefix}{text}"
def code(self, text: str) -> str:
return f"`{text}`"
def link(self, text: str, url: str) -> str:
return f"[{text}]({url})"