Skip to content

Commit 83b6271

Browse files
release : bump version 1.3.3
1 parent 8bea3fa commit 83b6271

File tree

2 files changed

+70
-63
lines changed

2 files changed

+70
-63
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ build-backend = "flit_core.buildapi"
55
[project]
66
# Check https://flit.readthedocs.io/en/latest/pyproject_toml.html for all available sections
77
name = "ansys-sphinx-theme"
8-
version = "1.3.2"
8+
version = "1.3.3"
99
description = "A theme devised by ANSYS, Inc. for Sphinx documentation."
1010
readme = "README.rst"
1111
requires-python = ">=3.10,<4"

src/ansys_sphinx_theme/__init__.py

Lines changed: 69 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
"""Module for the Ansys Sphinx theme."""
2424

2525
from itertools import islice, tee
26-
import logging
2726
import os
2827
import pathlib
2928
import re
@@ -34,6 +33,7 @@
3433
from docutils import nodes
3534
from sphinx import addnodes
3635
from sphinx.application import Sphinx
36+
from sphinx.util import logging
3737

3838
from ansys_sphinx_theme.extension.linkcode import DOMAIN_KEYS, sphinx_linkcode_resolve
3939
from ansys_sphinx_theme.latex import generate_404
@@ -51,6 +51,7 @@
5151
import importlib_metadata
5252

5353
__version__ = importlib_metadata.version(__name__.replace(".", "-"))
54+
logger = logging.getLogger(__name__)
5455

5556

5657
# Declare the fundamental paths of the theme
@@ -260,7 +261,7 @@ def fix_edit_link_page(link: str) -> str:
260261
edit=True,
261262
)
262263
except ValueError as e:
263-
logging.debug(f"An error occurred: {e}") # Log the exception as debug info
264+
logger.error(f"An error occurred: {e}") # Log the exception as debug info
264265
return link
265266

266267
elif "api" in pagename:
@@ -413,10 +414,25 @@ def convert_pdf_to_png(pdf_path: pathlib.Path, output_dir: pathlib.Path, output_
413414
images[0].save(output_dir / output_png, "PNG")
414415
except Exception as e:
415416
raise RuntimeError(
416-
f"Failed to convert PDF to PNG: {e}, ensure `poppler` is installed. See https://pypi.org/project/pdf2image/" # noqa: E501
417+
f"Failed to convert PDF to PNG: {e}. Ensure the PDF file is valid and poppler is installed." # noqa: E501
417418
)
418419

419420

421+
def run_quarto_command(command, cwd):
422+
"""Run quarto command and logs its output."""
423+
command = ["quarto"] + command
424+
try:
425+
result = subprocess.run(command, cwd=cwd, check=True, capture_output=True, text=True)
426+
if result.stdout:
427+
logger.info(result.stdout)
428+
429+
if result.stderr:
430+
logger.info(result.stderr)
431+
432+
except subprocess.CalledProcessError as e:
433+
raise RuntimeError(f"Failed to run the command: {e}")
434+
435+
420436
def add_cheat_sheet(
421437
app: Sphinx, pagename: str, templatename: str, context: Dict[str, Any], doctree: nodes.document
422438
) -> None:
@@ -459,78 +475,69 @@ def build_quarto_cheatsheet(app: Sphinx):
459475
return
460476

461477
cheatsheet_file = cheatsheet_options.get("file", "")
462-
output_dir = "_static"
463-
version = cheatsheet_options.get("version", "main")
464-
465478
if not cheatsheet_file:
466479
return
467480

481+
output_dir = "_static"
482+
version = cheatsheet_options.get("version", "main")
483+
468484
cheatsheet_file = pathlib.Path(app.srcdir) / cheatsheet_file
485+
output_dir_path = pathlib.Path(app.outdir) / output_dir
469486
file_name = str(cheatsheet_file.name)
470487
file_path = cheatsheet_file.parent
471-
output_dir_path = pathlib.Path(app.outdir) / output_dir
472-
try:
473-
# Add the cheatsheet to the Quarto project
474-
subprocess.run(
475-
[
476-
"quarto",
477-
"add",
478-
f"ansys/pyansys-quarto-cheatsheet@{CHEAT_SHEET_QUARTO_EXTENTION_VERSION}",
479-
"--no-prompt",
480-
],
481-
cwd=file_path,
482-
capture_output=True,
483-
text=True,
484-
)
485-
486-
# Render the cheatsheet
487-
subprocess.run(
488-
[
489-
"quarto",
490-
"render",
491-
file_name,
492-
"--to",
493-
"cheat_sheet-pdf",
494-
"--output-dir",
495-
output_dir_path,
496-
"-V",
497-
f"version={version}",
498-
],
499-
cwd=file_path,
500-
capture_output=True,
501-
text=True,
502-
)
503-
504-
# Remove the cheatsheet from the Quarto project
505-
subprocess.run(
506-
["quarto", "remove", "ansys/cheat_sheet", "--no-prompt"],
507-
cwd=file_path,
508-
capture_output=True,
509-
text=True,
510-
)
511-
512-
# Remove all supplementary files
513-
supplementary_files = [
514-
"_static/slash.png",
515-
"_static/bground.png",
516-
"_static/ansys.png",
517-
]
518-
for file in supplementary_files:
519-
file_path = cheatsheet_file.parent / file
520-
if file_path.exists():
521-
file_path.unlink()
522488

523-
# If static folder is clean, delete it
524-
if not list(cheatsheet_file.parent.glob("_static/*")):
525-
cheatsheet_file.parent.joinpath("_static").rmdir()
489+
logger.info(f"Building Quarto cheatsheet: {file_name}")
490+
491+
# Adapt with new
492+
run_quarto_command(["--version"], file_path)
493+
run_quarto_command(
494+
[
495+
"add",
496+
f"ansys/pyansys-quarto-cheatsheet@{CHEAT_SHEET_QUARTO_EXTENTION_VERSION}",
497+
"--no-prompt",
498+
],
499+
file_path,
500+
)
501+
run_quarto_command(
502+
[
503+
"render",
504+
file_name,
505+
"--to",
506+
"cheat_sheet-pdf",
507+
"--output-dir",
508+
output_dir_path,
509+
"-V",
510+
f"version={version}",
511+
],
512+
file_path,
513+
)
514+
run_quarto_command(
515+
["remove", "ansys/pyansys-quarto-cheatsheet", "--no-prompt"],
516+
file_path,
517+
)
518+
supplementary_files = [
519+
"_static/slash.png",
520+
"_static/bground.png",
521+
"_static/ansys.png",
522+
]
523+
for file in supplementary_files:
524+
file_path = cheatsheet_file.parent / file
525+
if file_path.exists():
526+
file_path.unlink()
526527

527-
except subprocess.CalledProcessError as e:
528-
raise RuntimeError(f"Failed to build Quarto cheatsheet: {e}. Ensure Quarto is installed.")
528+
# If static folder is clean, delete it
529+
if not list(cheatsheet_file.parent.glob("_static/*")):
530+
cheatsheet_file.parent.joinpath("_static").rmdir()
529531

530532
output_file = output_dir_path / file_name.replace(".qmd", ".pdf")
531533
app.config.html_theme_options["cheatsheet"]["output_dir"] = f"{output_dir}/{output_file.name}"
532534
output_png = file_name.replace(".qmd", ".png")
535+
# Check output file exists
536+
if not output_file.exists():
537+
raise FileNotFoundError(f"Failed to build Quarto cheatsheet: {output_file} does not exist.")
538+
533539
convert_pdf_to_png(output_file, output_dir_path, output_png)
540+
logger.info(f"Cheat sheet build finished successfully: {output_file}")
534541
app.config.html_theme_options["cheatsheet"]["thumbnail"] = f"{output_dir}/{output_png}"
535542

536543

0 commit comments

Comments
 (0)