diff options
Diffstat (limited to 'setup.py')
-rwxr-xr-x | setup.py | 57 |
1 files changed, 55 insertions, 2 deletions
@@ -9,6 +9,7 @@ import setuptools from setuptools.command.build_py import build_py from setuptools.command.sdist import sdist +from setuptools import Command from pathlib import Path @@ -43,7 +44,59 @@ class CustomSdistCommand(sdist): for path, contents in locale_files.items(): path.write_bytes(contents) +class BuildDocCommand(Command): + """ + Command to create an `htmldoc/` catalog with Haketilo documentation inside + as standalone .html files. + """ + user_options = [] + + def run (self, *args, **kwargs): + """Generate the .html files""" + import jinja2 + import shutil + import sys + + htmldoc_dir = here / 'htmldoc' + if htmldoc_dir.exists(): + shutil.rmtree(htmldoc_dir) + + proxy_doc_dir = htmldoc_dir / 'haketilo' + + sys.path.insert(0, str(here / 'src')) + + from hydrilla.proxy import self_doc + from hydrilla import common_jinja_templates + + loader = common_jinja_templates.combine_with_loaders([self_doc.loader]) + jinja_env = jinja2.Environment( + loader = loader, + autoescape = jinja2.select_autoescape(['html.jinja']), + lstrip_blocks = True, + extensions = ['jinja2.ext.do'] + ) + + for locale in self_doc.available_locales: + doc_dir = proxy_doc_dir / locale + doc_dir.mkdir(parents=True) + + for page_name in self_doc.page_names: + file_name = f'{locale}/{page_name}.html.jinja' + template = jinja_env.get_template(file_name) + html_text = template.render(doc_output='html') + + out_name = 'index' if page_name == 'doc_index' else page_name + + (doc_dir / f'{out_name}.html').write_text(html_text) + + def initialize_options(self): + pass + + def finalize_options(self): + pass + setuptools.setup(cmdclass = { - 'build_py': CustomBuildCommand, - 'sdist': CustomSdistCommand + 'build_py': CustomBuildCommand, + 'sdist': CustomSdistCommand, + 'build_htmldoc': BuildDocCommand }) |