Skip to content

Commit

Permalink
Rerun notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
jayqi committed Mar 26, 2024
1 parent 6481667 commit baed976
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 265 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
.vscode

docs/docs/examples/diagram.png
docs/docs/examples/diagram.svg
docs/docs/examples/
docs/notebooks/diagram.png
docs/notebooks/diagram.svg
docs/site

tests/_outputs
Expand Down
44 changes: 22 additions & 22 deletions docs/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,27 @@
REPO_ROOT = Path(__file__).resolve().parents[1]


def _github_alert_to_admonition(markdown: str):
"""Converts GitHub alert blockquote syntax to admonition syntax."""
# Ungreedy regex https://stackoverflow.com/a/7124976
pattern = re.compile(r"> \[\!(?P<type>\w+)\]\n(?P<content>.+?)(?=\n[^>])", re.DOTALL)
match = pattern.search(markdown)
alert_type = match.group("type")
alert_content = "\n".join(
line.removeprefix("> ") for line in match.group("content").split("\n")
)
template = textwrap.dedent(
"""\
!!! {admonition_type}
{content}
"""
)
admonition = template.format(
admonition_type=alert_type.lower(),
content=textwrap.indent(alert_content, " "),
)
return pattern.sub(admonition, markdown)
# def _github_alert_to_admonition(markdown: str):
# """Converts GitHub alert blockquote syntax to admonition syntax."""
# # Ungreedy regex https://stackoverflow.com/a/7124976
# pattern = re.compile(r"> \[\!(?P<type>\w+)\]\n(?P<content>.+?)(?=\n[^>])", re.DOTALL)
# match = pattern.search(markdown)
# alert_type = match.group("type")
# alert_content = "\n".join(
# line.removeprefix("> ") for line in match.group("content").split("\n")
# )
# template = textwrap.dedent(
# """\
# !!! {admonition_type}

# {content}
# """
# )
# admonition = template.format(
# admonition_type=alert_type.lower(),
# content=textwrap.indent(alert_content, " "),
# )
# return pattern.sub(admonition, markdown)


def _read_readme():
Expand All @@ -50,7 +50,7 @@ def _read_readme():
"./HISTORY.md",
"changelog.md",
)
readme_text = _github_alert_to_admonition(readme_text)
# readme_text = _github_alert_to_admonition(readme_text)
return readme_text


Expand Down
1 change: 1 addition & 0 deletions docs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ hooks:
markdown_extensions:
- admonition:
- def_list:
- github-callouts:
- pymdownx.highlight:
- pymdownx.superfences:
- pymdownx.tabbed:
Expand Down
8 changes: 4 additions & 4 deletions docs/docs/examples/attrs.ipynb → docs/notebooks/attrs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"id": "suspected-backing",
"metadata": {},
"source": [
"# Usage Example: dataclasses\n",
"# Usage Example: attrs\n",
"\n",
"This notebook shows an example of using erdantic with classes created with the [attrs](https://www.attrs.org/en/stable/index.html) package.\n",
"\n",
Expand Down Expand Up @@ -139,9 +139,9 @@
"name": "stdout",
"output_type": "stream",
"text": [
"2024-03-25 14:36:31,805 | erdantic.core | INFO | Adding model 'erdantic.examples.attrs.Party' to diagram...\n",
"2024-03-25 14:36:31,807 | erdantic.core | INFO | Rendering diagram to diagram.png\n",
"2024-03-25 14:36:32,053 | erdantic.cli | INFO | Rendered diagram to diagram.png\n"
"2024-03-25 20:33:45,588 | erdantic.core | INFO | Adding model 'erdantic.examples.attrs.Party' to diagram...\n",
"2024-03-25 20:33:45,591 | erdantic.core | INFO | Rendering diagram to diagram.png\n",
"2024-03-25 20:33:45,897 | erdantic.cli | INFO | Rendered diagram to diagram.png\n"
]
}
],
Expand Down

Large diffs are not rendered by default.

145 changes: 33 additions & 112 deletions docs/docs/examples/pydantic.ipynb → docs/notebooks/pydantic.ipynb

Large diffs are not rendered by default.

21 changes: 12 additions & 9 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,27 +103,30 @@ def test_sdist(session):
session.run("python", "-m", "erdantic", "--version")


@nox.session(venv_backend="mamba|conda", python="3.11", reuse_venv=True)
def docs(session):
def _docs_base(session):
session.conda_install("graphviz", channel="conda-forge")
if platform.system() == "Windows":
session.conda_install("pygraphviz", channel="conda-forge")
if HAS_UV:
session.run(UV, "pip", "install", "-r", "requirements/docs.txt", external=True)
else:
session.install("-r", "requirements/docs.txt")
examples_dir = Path("docs/docs/examples").resolve()
examples_dir.mkdir(exist_ok=True)
for notebook_path in sorted(Path("docs/notebooks").glob("*.ipynb")):
out_path = examples_dir / notebook_path.name
session.run("jupyter", "execute", f"--output={out_path}", notebook_path)


@nox.session(venv_backend="mamba|conda", python="3.11", reuse_venv=True)
def docs(session):
_docs_base(session)
with session.chdir("docs"):
session.run("mkdocs", "build")


@nox.session(venv_backend="mamba|conda", python="3.11", reuse_venv=True)
def docs_serve(session):
session.conda_install("graphviz", channel="conda-forge")
if platform.system() == "Windows":
session.conda_install("pygraphviz", channel="conda-forge")
if HAS_UV:
session.run(UV, "pip", "install", "-r", "requirements/docs.txt", external=True)
else:
session.install("-r", "requirements/docs.txt")
_docs_base(session)
with session.chdir("docs"):
session.run("mkdocs", "serve")
2 changes: 2 additions & 0 deletions requirements/docs.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
-e .[attrs]

black
markdown-callouts>=0.4.0
mdx_truly_sane_lists==1.3
mike
mkdocs>=1.4
mkdocs-jupyter
mkdocs-material>=7.2.6
mkdocstrings[python]>=0.19.0
nbconvert>=7.7.0
rich

0 comments on commit baed976

Please sign in to comment.