Skip to content

Commit

Permalink
CI tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
bckohan committed Dec 16, 2023
1 parent 6212141 commit 5836879
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: Run Static Analysis
run: |
poetry run isort sphinxcontrib/typer
poetry run black sphinxcontrib/typer
poetry run black sphinxcontrib/typer --check
poetry run doc8 -q doc
poetry check
poetry run pip check
Expand Down
22 changes: 13 additions & 9 deletions sphinxcontrib/typer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,26 @@
"""
import base64
import contextlib
import hashlib
import io
import json
import os
import re
import traceback
import typing as t
import os
from enum import Enum
from html import escape as html_escape
from importlib import import_module
from pathlib import Path
import hashlib

import click
from enum import Enum
from docutils import nodes
from docutils.parsers import rst
from docutils.parsers.rst import directives
from rich.console import Console
from rich.theme import Theme
from sphinx import application
from sphinx.util import logging

from typer import rich_utils as typer_rich_utils
from typer.main import Typer, TyperCommand, TyperGroup
from typer.main import get_command as get_typer_command
Expand Down Expand Up @@ -391,12 +391,17 @@ def get_console(stderr: bool = False) -> Console:
if 'html' in self.builder:
section += nodes.raw('', svg, format='html')
else:
img_name = f'{normal_cmd.replace(":", "_")}_{self.uuid(normal_cmd)}'
img_name = (
f'{normal_cmd.replace(":", "_")}_{self.uuid(normal_cmd)}'
)
out_dir = Path(self.env.app.builder.outdir)
(out_dir / f'{img_name}.svg').write_text(svg)
pdf_img = out_dir / f'{img_name}.pdf'
self.env.app.config.typer_svg2pdf(self, svg, pdf_img)
section += nodes.image(uri=os.path.relpath(pdf_img, Path(self.env.srcdir)), alt=source_name)
section += nodes.image(
uri=os.path.relpath(pdf_img, Path(self.env.srcdir)),
alt=source_name,
)

elif self.target == RenderTarget.TEXT:
section += nodes.literal_block(
Expand Down Expand Up @@ -590,6 +595,7 @@ def svg2pdf(directive: TyperDirective, svg_contents: str, pdf_path: str):
"""
try:
import cairosvg

cairosvg.svg2pdf(bytestring=svg_contents, write_to=str(pdf_path))
except ImportError:
directive.error(f'cairosvg must be installed to render SVG in pdfs')
Expand All @@ -610,9 +616,7 @@ def setup(app: application.Sphinx) -> t.Dict[str, t.Any]:
app.add_config_value(
'typer_get_iframe_height', lambda _: get_iframe_height, 'env'
)
app.add_config_value(
'typer_svg2pdf', lambda _: svg2pdf, 'env'
)
app.add_config_value('typer_svg2pdf', lambda _: svg2pdf, 'env')
app.add_config_value('typer_iframe_height_padding', 30, 'env')
app.add_config_value(
'typer_iframe_height_cache_path',
Expand Down

0 comments on commit 5836879

Please sign in to comment.