From cace3d9b64f6aebfcff0de4f057904a9233a82a1 Mon Sep 17 00:00:00 2001 From: Brian Kohan Date: Tue, 5 Mar 2024 11:11:08 -0800 Subject: [PATCH] convert default configuration getters from lambdas in an attempt to address #17 --- doc/source/index.rst | 4 +++- pyproject.toml | 4 ++++ sphinxcontrib/typer/__init__.py | 26 +++++++++++++++++++++----- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/doc/source/index.rst b/doc/source/index.rst index ec5d97d..6fd97f9 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -13,15 +13,17 @@ sphinx-click_ may be more appropriate and will also work for Typer_ commands. See the github_ repository for issue tracking and source code and install from PyPI_ with ``pip install sphinxcontrib-typer``. -For example, commands and subcommands are renderable separately in three +For example, commands and subcommands are renderable separately in four different formats: * svg * html * text +* png .. typer:: examples.example.app :convert-png: latex + :preferred: html | diff --git a/pyproject.toml b/pyproject.toml index aae594a..4111648 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -68,6 +68,10 @@ typing-extensions = { version = ">=3.7.4.3", python = "<3.9" } scikit-learn = "^1.3.2" beautifulsoup4 = "^4.12.2" pypdf = ">=3.17.3,<5.0.0" +sphinx-autobuild = [ + { version = ">=2024.2.4", python = ">=3.9"}, + { version = "<2024.2.4", python = "<3.9"}, +] [tool.poetry.extras] diff --git a/sphinxcontrib/typer/__init__.py b/sphinxcontrib/typer/__init__.py index 736aa80..c5991b5 100644 --- a/sphinxcontrib/typer/__init__.py +++ b/sphinxcontrib/typer/__init__.py @@ -923,13 +923,29 @@ def setup(app: application.Sphinx) -> t.Dict[str, t.Any]: # Need autodoc to support mocking modules app.add_directive('typer', TyperDirective) + def get_default_render_html(_): + return typer_render_html + + def get_default_get_iframe_height(_): + return typer_get_iframe_height + + def get_default_svg2pdf(_): + return typer_svg2pdf + + def get_default_convert_png(_): + return typer_convert_png + + def get_default_web_driver(_): + return typer_get_web_driver + app.add_config_value( - 'typer_render_html', lambda _: typer_render_html, 'env' + 'typer_render_html', get_default_render_html, 'env' ) + app.add_config_value( - 'typer_get_iframe_height', lambda _: typer_get_iframe_height, 'env' + 'typer_get_iframe_height', get_default_get_iframe_height, 'env' ) - app.add_config_value('typer_svg2pdf', lambda _: typer_svg2pdf, 'env') + app.add_config_value('typer_svg2pdf', get_default_svg2pdf, 'env') app.add_config_value('typer_iframe_height_padding', 30, 'env') app.add_config_value( 'typer_iframe_height_cache_path', @@ -938,10 +954,10 @@ def setup(app: application.Sphinx) -> t.Dict[str, t.Any]: ) app.add_config_value( - 'typer_convert_png', lambda _: typer_convert_png, 'env' + 'typer_convert_png', get_default_convert_png, 'env' ) app.add_config_value( - 'typer_get_web_driver', lambda _: typer_get_web_driver, 'env' + 'typer_get_web_driver', get_default_web_driver, 'env' ) return {