Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates for latest griffe #95

Merged
merged 1 commit into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 32 additions & 12 deletions docs/scripts/_dynamic_doc.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,53 @@
from __future__ import annotations

from pathlib import Path
import warnings
from griffe.dataclasses import Docstring
from griffe.docstrings import numpy
from pathlib import Path

from cylindra import _shared_doc, start, instance
from griffe import Docstring, Parser, parsers

from cylindra import _shared_doc, instance, start

warnings.simplefilter("ignore", DeprecationWarning)

parse_orig = numpy._read_parameters
parse_orig = parsers[Parser.numpy]

DOCS = Path(__file__).parent.parent
PATH_13_3 = DOCS.parent / "tests" / "13pf_MT.tif"


def on_startup(**kwargs):
def _read_parameters(docstring: Docstring, **kwargs):
if docstring.value:
docstring.value = _shared_doc.update_doc(docstring.value, indent=0)
return parse_orig(docstring, **kwargs)
def _dynamic_parse(docstring: Docstring, **kwargs):
if docstring.value:
docstring.value = _shared_doc.update_doc(docstring.value, indent=0)
if ">>> " in docstring.value:
docstring.value = _replace_codes(docstring.value)
return parse_orig(docstring, **kwargs)

numpy._read_parameters = _read_parameters

def _replace_codes(docstring: str):
lines = docstring.split("\n")
is_code = False
for i in range(len(lines)):
if is_code:
if lines[i].startswith((">>> ", "... ")):
lines[i] = lines[i][4:]
else:
is_code = False
lines[i] = f"```\n{lines[i]}"
else:
if lines[i].startswith(">>> "):
lines[i] = f"``` python\n{lines[i][4:]}"
is_code = True
return "\n".join(lines)


def on_startup(**kwargs):
parsers[Parser.numpy] = _dynamic_parse
ui = start()
ui.open_image(PATH_13_3)


def on_shutdown(**kwargs):
numpy._read_parameters = parse_orig
parsers[Parser.numpy] = parse_orig
ui = instance()
try:
ui.parent_viewer.close()
Expand Down
8 changes: 5 additions & 3 deletions docs/scripts/_screenshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from magicgui import magicgui
from qtpy import QtWidgets as QtW

from cylindra import instance
from cylindra import instance, widgets

DOCS = Path(__file__).parent.parent
PATH_13_3 = DOCS.parent / "tests" / "13pf_MT.tif"
Expand All @@ -22,9 +22,11 @@ def _imsave(widget: QtW.QWidget, name: str):
widget.grab().save(f.name, "png")


def _viewer_screenshot(ui, name: str, canvas_only: bool = True):
def _viewer_screenshot(
ui: widgets.CylindraMainWidget, name: str, canvas_only: bool = True
):
with mkdocs_gen_files.FilesEditor.current().open(f"images/{name}.png", "wb") as f:
ui.parent_viewer.screenshot(f.name, canvas_only=canvas_only)
ui.parent_viewer.screenshot(f.name, canvas_only=canvas_only, flash=False)


def main():
Expand Down
Loading