mirror of
https://github.com/explosion/spaCy.git
synced 2025-01-26 09:14:32 +03:00
Update wasabi: new diff_strings and MarkdownRenderer
This commit is contained in:
parent
79d460e3a2
commit
3aec98ca38
|
@ -5,7 +5,7 @@ thinc>=8.0.0a30,<8.0.0a40
|
||||||
blis>=0.4.0,<0.5.0
|
blis>=0.4.0,<0.5.0
|
||||||
ml_datasets>=0.1.1
|
ml_datasets>=0.1.1
|
||||||
murmurhash>=0.28.0,<1.1.0
|
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
|
srsly>=2.1.0,<3.0.0
|
||||||
catalogue>=0.0.7,<1.1.0
|
catalogue>=0.0.7,<1.1.0
|
||||||
typer>=0.3.0,<0.4.0
|
typer>=0.3.0,<0.4.0
|
||||||
|
|
|
@ -42,7 +42,7 @@ install_requires =
|
||||||
preshed>=3.0.2,<3.1.0
|
preshed>=3.0.2,<3.1.0
|
||||||
thinc>=8.0.0a30,<8.0.0a40
|
thinc>=8.0.0a30,<8.0.0a40
|
||||||
blis>=0.4.0,<0.5.0
|
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
|
srsly>=2.1.0,<3.0.0
|
||||||
catalogue>=0.0.7,<1.1.0
|
catalogue>=0.0.7,<1.1.0
|
||||||
typer>=0.3.0,<0.4.0
|
typer>=0.3.0,<0.4.0
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from typing import Optional, Dict, Any, Union
|
from typing import Optional, Dict, Any, Union
|
||||||
import platform
|
import platform
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from wasabi import Printer
|
from wasabi import Printer, MarkdownRenderer
|
||||||
import srsly
|
import srsly
|
||||||
|
|
||||||
from ._util import app, Arg, Opt
|
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.
|
title (str / None): Title, will be rendered as headline 2.
|
||||||
RETURNS (str): The Markdown string.
|
RETURNS (str): The Markdown string.
|
||||||
"""
|
"""
|
||||||
markdown = []
|
md = MarkdownRenderer()
|
||||||
|
if title:
|
||||||
|
md.add(md.title(2, title))
|
||||||
|
items = []
|
||||||
for key, value in data.items():
|
for key, value in data.items():
|
||||||
if isinstance(value, str) and Path(value).exists():
|
if isinstance(value, str) and Path(value).exists():
|
||||||
continue
|
continue
|
||||||
markdown.append(f"* **{key}:** {value}")
|
items.append(f"{md.bold(f'{key}:')} {value}")
|
||||||
result = "\n{}\n".format("\n".join(markdown))
|
md.add(md.list(items))
|
||||||
if title:
|
return f"\n{md.text}\n"
|
||||||
result = f"\n## {title}\n{result}"
|
|
||||||
return result
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
from typing import Iterable, Optional
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from wasabi import msg
|
from wasabi import msg, MarkdownRenderer
|
||||||
|
|
||||||
from ...util import working_dir
|
from ...util import working_dir
|
||||||
from .._util import project_cli, Arg, Opt, PROJECT_FILE, load_project_config
|
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:
|
with output_file.open("w") as f:
|
||||||
f.write(content)
|
f.write(content)
|
||||||
msg.good("Saved project documentation", output_file)
|
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})"
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user