From dcb16ef913e519eee820d81e77491be1d7392814 Mon Sep 17 00:00:00 2001 From: Ad Thiers Date: Mon, 6 Nov 2023 17:58:20 +0100 Subject: [PATCH 01/11] Theme fix - use style sources from theme instead from built-in --- sphinx_simplepdf/builders/simplepdf.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/sphinx_simplepdf/builders/simplepdf.py b/sphinx_simplepdf/builders/simplepdf.py index c4576dd..6953f95 100644 --- a/sphinx_simplepdf/builders/simplepdf.py +++ b/sphinx_simplepdf/builders/simplepdf.py @@ -2,6 +2,7 @@ import re from typing import Any, Dict import subprocess +from importlib import import_module import weasyprint import sass @@ -44,7 +45,7 @@ def __init__(self, *args, **kwargs): debug_sphinx = { "version": __version__, - "confidr": self.app.confdir, + "confdir": self.app.confdir, "srcdir": self.app.srcdir, "outdir": self.app.outdir, "extensions": self.app.config.extensions, @@ -55,9 +56,19 @@ def __init__(self, *args, **kwargs): # Generate main.css logger.info("Generating css files from scss-templates") css_folder = os.path.join(self.app.outdir, f"_static") - scss_folder = os.path.join( - os.path.dirname(__file__), "..", "themes", "simplepdf_theme", "static", "styles", "sources" - ) + + theme_folder = os.path.join(os.path.dirname(__file__), "..", "themes", "simplepdf_theme") + + if self.app.config.simplepdf_theme is not None: + try: + theme_folder = os.path.dirname(import_module(self.app.config.html_theme).__file__) + except ImportError: + logger.warning(f"Could not import {self.app.config.html_theme}") + # use built-in theme + pass + + scss_folder = os.path.join(theme_folder, "static", "styles", "sources") + sass.compile( dirname=(scss_folder, css_folder), output_style="nested", From e9d6085528bc564cd68a08c7e2edb365530c0764 Mon Sep 17 00:00:00 2001 From: Ad Thiers Date: Tue, 7 Nov 2023 14:13:48 +0100 Subject: [PATCH 02/11] add ci pipeline --- .gitlab-ci.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..5ed4513 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,30 @@ +default: + image: python:3.9 + +stages: + - test + - publish + +before_script: + - pip install poetry + - poetry install + - source $(poetry env info --path)/bin/activate + +testing: + stage: test + script: + - echo "This is the test stage" + +publishing: + stage: publish + rules: + - if: '$CI_COMMIT_REF_NAME == "main"' + - when: manual + script: + - echo "This is the publish stage" + - poetry config repositories.gitlab ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi + - echo "Repository gitlab configured..." + - poetry build + - echo "Build done..." + - poetry publish --repository gitlab -u gitlab-ci-token -p "$CI_JOB_TOKEN" + - echo "Publish done..." From f79caf3d49bc1f9e4b2f637bae39dedb0f82da4d Mon Sep 17 00:00:00 2001 From: Ad Thiers Date: Tue, 7 Nov 2023 14:32:09 +0100 Subject: [PATCH 03/11] Fix pipeline (from poetry to setuptools+twine) --- .gitlab-ci.yml | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5ed4513..0ee5a98 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,9 +6,8 @@ stages: - publish before_script: - - pip install poetry - - poetry install - - source $(poetry env info --path)/bin/activate + - echo "This is the before script" + - pip install twine testing: stage: test @@ -22,9 +21,7 @@ publishing: - when: manual script: - echo "This is the publish stage" - - poetry config repositories.gitlab ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi - - echo "Repository gitlab configured..." - - poetry build + - python setup.py sdist - echo "Build done..." - - poetry publish --repository gitlab -u gitlab-ci-token -p "$CI_JOB_TOKEN" + - twine upload --repository-url ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi -u gitlab-ci-token -p "$CI_JOB_TOKEN" dist/* - echo "Publish done..." From 97d1362370bcbb70886af3b2896b14d93735a2fb Mon Sep 17 00:00:00 2001 From: Ad Thiers Date: Tue, 7 Nov 2023 14:35:04 +0100 Subject: [PATCH 04/11] Bump version: 1.6.0 -> 1.6.1a1 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 7c46b3c..c013ce3 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ setup( name='sphinx-simplepdf', - version='1.6.0', + version='1.6.1a1', url='https://sphinx-simplepdf.readthedocs.io', download_url='https://github.com/useblocks/sphinx-simplepdf', license='MIT', From 1921ef20f72b778951744ca308029e0c1915f5ea Mon Sep 17 00:00:00 2001 From: Ad Thiers Date: Mon, 13 Nov 2023 07:55:32 +0100 Subject: [PATCH 05/11] Move SASS css generation to the theme --- docs/conf.py | 3 +- sphinx_simplepdf/builders/simplepdf.py | 70 ++++++------------- .../themes/simplepdf_theme/__init__.py | 31 +++++++- 3 files changed, 52 insertions(+), 52 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index cfd2f6a..2970232 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -20,7 +20,8 @@ extensions = [ 'sphinx_simplepdf', 'sphinxcontrib.plantuml', - 'sphinxcontrib.needs', +# 'sphinxcontrib.needs', + 'sphinx_needs', 'sphinx_copybutton', ] diff --git a/sphinx_simplepdf/builders/simplepdf.py b/sphinx_simplepdf/builders/simplepdf.py index 6953f95..f616bf5 100644 --- a/sphinx_simplepdf/builders/simplepdf.py +++ b/sphinx_simplepdf/builders/simplepdf.py @@ -5,8 +5,6 @@ from importlib import import_module import weasyprint -import sass - from bs4 import BeautifulSoup from sphinx import __version__ @@ -32,6 +30,8 @@ def __init__(self, *args, **kwargs): if self.app.config.simplepdf_theme is not None: logger.info(f"Setting theme to {self.app.config.simplepdf_theme}") self.app.config.html_theme = self.app.config.simplepdf_theme + else: + logger.error('The simplepdf_theme is not set') # We need to overwrite some config values, as they are set for the normal html build, but # simplepdf can normally not handle them. @@ -57,58 +57,28 @@ def __init__(self, *args, **kwargs): logger.info("Generating css files from scss-templates") css_folder = os.path.join(self.app.outdir, f"_static") - theme_folder = os.path.join(os.path.dirname(__file__), "..", "themes", "simplepdf_theme") - if self.app.config.simplepdf_theme is not None: try: - theme_folder = os.path.dirname(import_module(self.app.config.html_theme).__file__) + theme_mod = import_module(name=self.app.config.simplepdf_theme) + logger.warning(f"Loaded theme {self.app.config.simplepdf_theme}") except ImportError: - logger.warning(f"Could not import {self.app.config.html_theme}") + logger.warning(f"Could not load theme {self.app.config.simplepdf_theme}") # use built-in theme - pass - - scss_folder = os.path.join(theme_folder, "static", "styles", "sources") - - sass.compile( - dirname=(scss_folder, css_folder), - output_style="nested", - custom_functions={ - sass.SassFunction("config", ("$a", "$b"), self.get_config_var), - sass.SassFunction("theme_option", ("$a", "$b"), self.get_theme_option_var), - }, - ) - - def get_config_var(self, name, default): - """ - Gets a config variables for scss out of the Sphinx configuration. - If name is not found in config, the specified default var is returned. - - Args: - name: Name of the config var to use - default: Default value, if name can not be found in config - - Returns: Value - """ - simplepdf_vars = self.app.config.simplepdf_vars - if name not in simplepdf_vars: - return default - return simplepdf_vars[name] - - def get_theme_option_var(self, name, default): - """ - Gets a option variables for scss out of the Sphinx theme options. - If name is not found in theme options, the specified default var is returned. - - Args: - name: Name of the option var to use - default: Default value, if name can not be found in config - - Returns: Value - """ - simplepdf_theme_options = self.app.config.simplepdf_theme_options - if name not in simplepdf_theme_options: - return default - return simplepdf_theme_options[name] + # theme_mod = import_module(name='sphinx_simplepdf.themes.simplepdf_theme') + theme_mod = import_module( + name='..themes.simplepdf_theme', + package=__package__ + ) + logger.warning("Loaded builtin theme .themes.simplepdf_theme") + + try: + theme_mod.gen_dynamic_style( + css_folder, + self.app.config.simplepdf_vars, + self.app.config.simplepdf_theme_options + ) + except AttributeError: + pass # theme is not parametrized def finish(self) -> None: super().finish() diff --git a/sphinx_simplepdf/themes/simplepdf_theme/__init__.py b/sphinx_simplepdf/themes/simplepdf_theme/__init__.py index 9837ce8..237d7fa 100644 --- a/sphinx_simplepdf/themes/simplepdf_theme/__init__.py +++ b/sphinx_simplepdf/themes/simplepdf_theme/__init__.py @@ -3,8 +3,10 @@ """ from os import path +import sass -__version__ = '0.1.0' + +__version__ = '0.2.0' __version_full__ = __version__ @@ -14,6 +16,33 @@ def get_html_theme_path(): return cur_dir +def gen_dynamic_style(dest, config_vars, theme_vars): + """Generate css dynamically + Args: + dest: destination folder to store generated css + config_vars: dictionary with config variables + theme_vars: dictionary with theme variables + """ + + here = path.abspath(path.dirname(__file__)) + scss_folder = path.join(here, "static", "styles", "sources") + + def get_config_var(name, default): + return config_vars.get(name, default) + + def get_theme_var(name, default): + return theme_vars.get(name, default) + + sass.compile( + dirname=(scss_folder, dest), + output_style="nested", + custom_functions={ + sass.SassFunction("config", ("$a", "$b"), get_config_var), + sass.SassFunction("theme_option", ("$a", "$b"), get_theme_var), + }, + ) + + # See http://www.sphinx-doc.org/en/stable/theming.html#distribute-your-theme-as-a-python-package def setup(app): app.add_html_theme('simplepdf_theme', path.abspath(path.dirname(__file__))) From d010690f29b263d0aa1f1bb6bc56b5f23d5bb8ac Mon Sep 17 00:00:00 2001 From: Ad Thiers Date: Mon, 13 Nov 2023 17:14:16 +0100 Subject: [PATCH 06/11] Move CSS generation to theme --- docs/conf.py | 3 +-- sphinx_simplepdf/builders/simplepdf.py | 27 ------------------- .../themes/simplepdf_theme/__init__.py | 26 ++++++++---------- 3 files changed, 12 insertions(+), 44 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 2970232..cfd2f6a 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -20,8 +20,7 @@ extensions = [ 'sphinx_simplepdf', 'sphinxcontrib.plantuml', -# 'sphinxcontrib.needs', - 'sphinx_needs', + 'sphinxcontrib.needs', 'sphinx_copybutton', ] diff --git a/sphinx_simplepdf/builders/simplepdf.py b/sphinx_simplepdf/builders/simplepdf.py index f616bf5..d72306b 100644 --- a/sphinx_simplepdf/builders/simplepdf.py +++ b/sphinx_simplepdf/builders/simplepdf.py @@ -53,33 +53,6 @@ def __init__(self, *args, **kwargs): } self.app.config.html_context["spd"] = debug_sphinx - # Generate main.css - logger.info("Generating css files from scss-templates") - css_folder = os.path.join(self.app.outdir, f"_static") - - if self.app.config.simplepdf_theme is not None: - try: - theme_mod = import_module(name=self.app.config.simplepdf_theme) - logger.warning(f"Loaded theme {self.app.config.simplepdf_theme}") - except ImportError: - logger.warning(f"Could not load theme {self.app.config.simplepdf_theme}") - # use built-in theme - # theme_mod = import_module(name='sphinx_simplepdf.themes.simplepdf_theme') - theme_mod = import_module( - name='..themes.simplepdf_theme', - package=__package__ - ) - logger.warning("Loaded builtin theme .themes.simplepdf_theme") - - try: - theme_mod.gen_dynamic_style( - css_folder, - self.app.config.simplepdf_vars, - self.app.config.simplepdf_theme_options - ) - except AttributeError: - pass # theme is not parametrized - def finish(self) -> None: super().finish() diff --git a/sphinx_simplepdf/themes/simplepdf_theme/__init__.py b/sphinx_simplepdf/themes/simplepdf_theme/__init__.py index 237d7fa..a5ca0a3 100644 --- a/sphinx_simplepdf/themes/simplepdf_theme/__init__.py +++ b/sphinx_simplepdf/themes/simplepdf_theme/__init__.py @@ -6,7 +6,7 @@ import sass -__version__ = '0.2.0' +__version__ = '0.3.0' __version_full__ = __version__ @@ -16,25 +16,21 @@ def get_html_theme_path(): return cur_dir -def gen_dynamic_style(dest, config_vars, theme_vars): - """Generate css dynamically - Args: - dest: destination folder to store generated css - config_vars: dictionary with config variables - theme_vars: dictionary with theme variables - """ - - here = path.abspath(path.dirname(__file__)) - scss_folder = path.join(here, "static", "styles", "sources") +def create_custom_css(app): def get_config_var(name, default): - return config_vars.get(name, default) + return app.config.simplepdf_vars.get(name, default) def get_theme_var(name, default): - return theme_vars.get(name, default) + return app.config.simplepdf_theme_options.get(name, default) + + here = path.abspath(path.dirname(__file__)) + scss_folder = path.join(here, "static", "styles", "sources") + + staticdir = path.join(app.builder.outdir, "_static") sass.compile( - dirname=(scss_folder, dest), + dirname=(scss_folder, staticdir), output_style="nested", custom_functions={ sass.SassFunction("config", ("$a", "$b"), get_config_var), @@ -46,7 +42,7 @@ def get_theme_var(name, default): # See http://www.sphinx-doc.org/en/stable/theming.html#distribute-your-theme-as-a-python-package def setup(app): app.add_html_theme('simplepdf_theme', path.abspath(path.dirname(__file__))) - # app.add_css_file('styles/main.css') + app.connect('builder-inited', create_custom_css) return { "parallel_read_safe": True, From 50538e690c7209ba02089ac4834a1de5edc1acb9 Mon Sep 17 00:00:00 2001 From: Ad Thiers Date: Mon, 13 Nov 2023 20:15:30 +0100 Subject: [PATCH 07/11] Cleanup code --- setup.py | 2 +- sphinx_simplepdf/builders/simplepdf.py | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index c013ce3..cec475a 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ setup( name='sphinx-simplepdf', - version='1.6.1a1', + version='1.6.2a1', url='https://sphinx-simplepdf.readthedocs.io', download_url='https://github.com/useblocks/sphinx-simplepdf', license='MIT', diff --git a/sphinx_simplepdf/builders/simplepdf.py b/sphinx_simplepdf/builders/simplepdf.py index d72306b..8c3c8b0 100644 --- a/sphinx_simplepdf/builders/simplepdf.py +++ b/sphinx_simplepdf/builders/simplepdf.py @@ -2,7 +2,6 @@ import re from typing import Any, Dict import subprocess -from importlib import import_module import weasyprint from bs4 import BeautifulSoup @@ -30,8 +29,6 @@ def __init__(self, *args, **kwargs): if self.app.config.simplepdf_theme is not None: logger.info(f"Setting theme to {self.app.config.simplepdf_theme}") self.app.config.html_theme = self.app.config.simplepdf_theme - else: - logger.error('The simplepdf_theme is not set') # We need to overwrite some config values, as they are set for the normal html build, but # simplepdf can normally not handle them. @@ -110,7 +107,7 @@ def finish(self) -> None: success = True break except subprocess.TimeoutExpired: - logger.warning(f"TimeoutExpired in weasyprint, retrying") + logger.warning("TimeoutExpired in weasyprint, retrying") except subprocess.CalledProcessError as e: logger.warning(f"CalledProcessError in weasyprint, retrying\n{str(e)}") finally: From 94278e946c9696dc79feb5ab75d4c7e824b0a157 Mon Sep 17 00:00:00 2001 From: Ad Thiers Date: Mon, 13 Nov 2023 20:16:58 +0100 Subject: [PATCH 08/11] Cleanup artifacts --- .gitlab-ci.yml | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index 0ee5a98..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,27 +0,0 @@ -default: - image: python:3.9 - -stages: - - test - - publish - -before_script: - - echo "This is the before script" - - pip install twine - -testing: - stage: test - script: - - echo "This is the test stage" - -publishing: - stage: publish - rules: - - if: '$CI_COMMIT_REF_NAME == "main"' - - when: manual - script: - - echo "This is the publish stage" - - python setup.py sdist - - echo "Build done..." - - twine upload --repository-url ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi -u gitlab-ci-token -p "$CI_JOB_TOKEN" dist/* - - echo "Publish done..." From 4f3d2cebde3bfc757de5f237c618cc365ef70d86 Mon Sep 17 00:00:00 2001 From: Ad Thiers Date: Mon, 13 Nov 2023 20:43:16 +0100 Subject: [PATCH 09/11] Reset version to 1.6.0 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index cec475a..7c46b3c 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ setup( name='sphinx-simplepdf', - version='1.6.2a1', + version='1.6.0', url='https://sphinx-simplepdf.readthedocs.io', download_url='https://github.com/useblocks/sphinx-simplepdf', license='MIT', From 868f54f2c73700ef44a0cb27fec9dce1766ffaab Mon Sep 17 00:00:00 2001 From: Ad Thiers Date: Thu, 16 Nov 2023 20:48:49 +0100 Subject: [PATCH 10/11] Theme version back to 0.1.0 --- sphinx_simplepdf/themes/simplepdf_theme/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sphinx_simplepdf/themes/simplepdf_theme/__init__.py b/sphinx_simplepdf/themes/simplepdf_theme/__init__.py index a5ca0a3..35a409b 100644 --- a/sphinx_simplepdf/themes/simplepdf_theme/__init__.py +++ b/sphinx_simplepdf/themes/simplepdf_theme/__init__.py @@ -6,7 +6,7 @@ import sass -__version__ = '0.3.0' +__version__ = '0.1.0' __version_full__ = __version__ From 9faded6f58bf55f73f8d9ae6813e083c55951b45 Mon Sep 17 00:00:00 2001 From: Ad Thiers Date: Thu, 23 Nov 2023 13:22:49 +0100 Subject: [PATCH 11/11] Put docstring back in get_config_var and get_theme_var --- .../themes/simplepdf_theme/__init__.py | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/sphinx_simplepdf/themes/simplepdf_theme/__init__.py b/sphinx_simplepdf/themes/simplepdf_theme/__init__.py index 35a409b..18de630 100644 --- a/sphinx_simplepdf/themes/simplepdf_theme/__init__.py +++ b/sphinx_simplepdf/themes/simplepdf_theme/__init__.py @@ -18,11 +18,36 @@ def get_html_theme_path(): def create_custom_css(app): + try: + simplepdf_vars = app.config.simplepdf_vars + except AttributeError: + simplepdf_vars = {} + def get_config_var(name, default): - return app.config.simplepdf_vars.get(name, default) + """ + Gets a config variables for scss out of the Sphinx configuration. + If name is not found in config, the specified default var is returned. + + Args: + name: Name of the config var to use + default: Default value, if name can not be found in config + + Returns: Value + """ + return simplepdf_vars.get(name, default) def get_theme_var(name, default): - return app.config.simplepdf_theme_options.get(name, default) + """ + Gets a option variables for scss out of the Sphinx theme options. + If name is not found in theme options, the specified default var is returned. + + Args: + name: Name of the option var to use + default: Default value, if name can not be found in config + + Returns: Value + """ + return app.config.html_theme_options.get(name, default) here = path.abspath(path.dirname(__file__)) scss_folder = path.join(here, "static", "styles", "sources")