diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md index d0838ff..d53e4a5 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@
+ Enjoying the library? Give us a + + on + GitHub. +
+{% endblock %} + +{% block outdated %} +You're not viewing the latest version. + + Click here to go to latest. + +{% endblock %} diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 0000000..9a922ab --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,148 @@ +# Configuration file for the Sphinx documentation builder. +# +# This file only contains a selection of the most common options. For a full +# list see the documentation: +# https://www.sphinx-doc.org/en/master/usage/configuration.html + +# -- Path setup -------------------------------------------------------------- + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +# +import os +import sys + +sys.path.insert(0, os.path.abspath(".")) +sys.path.insert(0, os.path.abspath("..")) + + +# -- Project information ----------------------------------------------------- + +project = "Zmodn" +copyright = "2023, Alejandro Sánchez Yalí" +author = "Alejandro Sánchez Yalí" + + +# -- General configuration --------------------------------------------------- + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ + "sphinx.ext.autodoc", + "sphinx.ext.napoleon", + "sphinx.ext.mathjax", + "sphinx.ext.intersphinx", + "sphinx_last_updated_by_git", + "sphinx_immaterial", + "sphinx_immaterial.apidoc.python.apigen", + "sphinx_math_dollar", + "myst_parser", + "sphinx_design", + "IPython.sphinxext.ipython_console_highlighting", + "IPython.sphinxext.ipython_directive", + "ipython_with_reprs", +] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ["_templates"] + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This pattern also affects html_static_path and html_extra_path. +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] + + +# -- Options for HTML output ------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +# +html_theme = "sphinx_immaterial" + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ["_static"] + + +html_css_files = [ + "extra.css", +] + +# Define a custom inline Python syntax highlighting literal +rst_prolog = """ +.. role:: python(code) + :language: python + :class: highlight +""" +# Sets the default role of `content` to :python:`content`, which uses the custom Python syntax highlighting inline literal +default_role = "python" + +html_title = "Zmodn" +html_favicon = "../logo/favicon.png" +html_logo = "../logo/favicon.png" + +# Sphinx Immaterial theme options +html_theme_options = { + "icon": { + "repo": "fontawesome/brands/github", + }, + "repo_url": "https://github.com/asanchezyali/Zmodn", + "repo_name": "asanchezyali/Zmodn", + "social": [ + { + "icon": "fontawesome/brands/github", + "link": "https://github.com/asanchezyali/Zmodn", + }, + { + "icon": "fontawesome/brands/twitter", + "link": "https://twitter.com/asanchezyali", + }, + ], + "edit_uri": "", + "globaltoc_collapse": False, + "features": [ + # "navigation.expand", + "navigation.tabs", + # "toc.integrate", + # "navigation.sections", + # "navigation.instant", + # "header.autohide", + "navigation.top", + "navigation.tracking", + "toc.follow", + "toc.sticky", + "content.tabs.link", + "announce.dismiss", + ], + "palette": [ + { + "media": "(prefers-color-scheme: light)", + "scheme": "default", + "toggle": { + "icon": "material/weather-night", + "name": "Switch to dark mode", + }, + }, + { + "media": "(prefers-color-scheme: dark)", + "scheme": "slate", + "toggle": { + "icon": "material/weather-sunny", + "name": "Switch to light mode", + }, + }, + ], + "analytics": { + "provider": "google", + "property": "G-4FW9NCNFZH", + }, + "version_dropdown": True, + "version_json": "../versions.json", +} + +html_last_updated_fmt = "" +html_use_index = True +html_domain_indices = True diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 0000000..9b8f97b --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,20 @@ +.. Zmodn documentation master file, created by + sphinx-quickstart on Thu Nov 23 16:31:16 2023. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +Welcome to Zmodn's documentation! +================================= + +.. toctree:: + :maxdepth: 2 + :caption: Contents: + + + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` diff --git a/docs/ipython_with_reprs.py b/docs/ipython_with_reprs.py new file mode 100644 index 0000000..10f9b47 --- /dev/null +++ b/docs/ipython_with_reprs.py @@ -0,0 +1,96 @@ +""" +Sphinx extension that adds `ipython-with-element_reprs` directive. +""" +from typing import List + +import docutils.nodes +import sphinx.addnodes +import sphinx.application +import sphinx.util.docutils +import sphinx.util.logging + +logger = sphinx.util.logging.getLogger(__name__) + +ELEMENT_REPR_TO_TITLE = { + "int": "Integer", + "poly": "Polynomial", + "power": "Power", +} + + +class IPythonWithReprsDirective(sphinx.util.docutils.SphinxDirective): + has_content = True + required_arguments = 1 + optional_arguments = 1 + option_spec = { + "name": str, + } + + def run(self) -> List[docutils.nodes.Node]: + self.assert_has_content() + + # Parse input parameters + element_reprs = self.arguments[0].split(",") + titles = [ELEMENT_REPR_TO_TITLE[element_repr] for element_repr in element_reprs] + field = self.options.get("name", "GF") + + ws = " " + new_lines = [ + ".. md-tab-set::", + "", + ] + + for element_repr, title in zip(element_reprs, titles): + new_lines += [ + f"{ws}.. md-tab-item:: {title}", + "", + f"{ws}{ws}.. ipython:: python", + "", + ] + + # Set the Galois field element representation + first_code_line = self.content[0] + if first_code_line.startswith(f"{field} = "): + assert "repr=" not in first_code_line + if element_repr == "int": + new_first_code_line = first_code_line + else: + items = first_code_line.rsplit(")", 1) + assert len(items) == 2 + items.insert(1, f', repr="{element_repr}")') + new_first_code_line = "".join(items) + new_lines += [ + f"{ws}{ws}{ws}{new_first_code_line}", + ] + else: + new_lines += [ + f"{ws}{ws}{ws}@suppress", + f'{ws}{ws}{ws}{field}.repr("{element_repr}")', + f"{ws}{ws}{ws}{first_code_line}", + ] + + # Add the raw python code + for code_line in self.content[1:]: + new_lines += [ + f"{ws}{ws}{ws}{code_line}", + ] + + # Reset the element representation + new_lines += [ + f"{ws}{ws}{ws}@suppress", + f"{ws}{ws}{ws}{field}.repr()", + "", + ] + + self.state_machine.insert_input(new_lines, self.state_machine.input_lines.source(0)) + + return [] + + +def setup(app: sphinx.application.Sphinx): + app.add_directive("ipython-with-reprs", IPythonWithReprsDirective) + + return { + "parallel_read_safe": True, + "parallel_write_safe": True, + } diff --git a/docs/make.bat b/docs/make.bat new file mode 100644 index 0000000..32bb245 --- /dev/null +++ b/docs/make.bat @@ -0,0 +1,35 @@ +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set SOURCEDIR=. +set BUILDDIR=_build + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.https://www.sphinx-doc.org/ + exit /b 1 +) + +if "%1" == "" goto help + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% + +:end +popd diff --git a/logo/.DS_Store b/logo/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/logo/.DS_Store differ diff --git a/logo/favicon.drawio b/logo/favicon.drawio new file mode 100644 index 0000000..fe52c9a --- /dev/null +++ b/logo/favicon.drawio @@ -0,0 +1,13 @@ +