Skip to content

Commit

Permalink
🎨 Automatic addition of styles with extension addition
Browse files Browse the repository at this point in the history
  • Loading branch information
daquinteroflex committed Aug 14, 2024
1 parent d15f641 commit 67c4615
Show file tree
Hide file tree
Showing 22 changed files with 1,870 additions and 170 deletions.
28 changes: 13 additions & 15 deletions autoflex/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,34 @@
"""

from typing import Any, Dict
import pathlib

from .install import install_verification
from autoflex.directives import AutoFlex, FlexTree
from autoflex.styles.setup import copy_autoflex_styles_to_static

__version__ = "0.0.1"
__author__ = "Dario Quintero Dominguez"
__email__ = "dario a quintero at gmail dot com"


def setup(app) -> Dict[str, Any]:
"""Add icon node to the sphinx builder."""
"""
Configure the ``autoflex`` extension onto your project.
"""
print("Started loading `autoflex` extension.")
# DIRECTIVES
app.add_directive("autoflex", AutoFlex)
app.add_directive("flextree", FlexTree)
# load the icon node/role
# app.add_node(icon_node, **_NODE_VISITORS) # type: ignore
# app.add_role("icon", Icon())
#
# # load the font
# font_handler = Fontawesome()
#
# # install html related files
# app.add_css_file(str(font_handler.css_file.resolve()))
# app.add_js_file(str(font_handler.js_file.resolve()))
#
# # install latex files
# app.add_latex_package("fontspec")
# app.connect("config-inited", font_handler.add_latex_font)
# app.connect("config-inited", font_handler.enforce_xelatex)
# app.connect("builder-inited", font_handler.add_latex_font_files)
print("Finished loaded `autoflex` extension.")

# STYLES
app.connect('build-finished', copy_autoflex_styles_to_static)
app.add_css_file("css/autoflex.css")

print("Finished loading `autoflex` extension.")

return {
"version": __version__,
Expand Down
1 change: 1 addition & 0 deletions autoflex/directives/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from .autoflex import AutoFlex
from .flextree import FlexTree
from .flexsummary import FlexSummary
31 changes: 9 additions & 22 deletions autoflex/directives/autoflex.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
from docutils.parsers import rst
from typing import Any

from docutils import nodes
from docutils.parsers.rst import directives
from sphinx.ext.autodoc import ClassDocumenter
from sphinx.util.docutils import SphinxDirective

class AutoFlex(rst.Directive):
class AutoFlex(ClassDocumenter):
"""
Extension of the ``.. automodule::`` directive.
Expand All @@ -26,24 +30,7 @@ class AutoFlex(rst.Directive):
"""

# Directive information
has_content: bool = True

# name: str = "autoflex"
# arguments: Any = None
# options: Any = None
# content: Any = None
# lineno: Any = None
# content_offset: Any = None
# block_text: Any = None
# state: Any = None
# state_machine: Any = None
# reporter: Any = None
#
# required_arguments: int = 1
# optional_arguments: int = 0

def run(self):
print("AutoFlex directive running.")
print(self.name)
return []
has_content = True



1 change: 1 addition & 0 deletions autoflex/directives/flexsummary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FlexSummary = None
Empty file added autoflex/styles/__init__.py
Empty file.
92 changes: 92 additions & 0 deletions autoflex/styles/css/autoflex.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/* FONTS */
@font-face {
font-family: 'autoflex_title';
src: url('ornitons_bold.ttf') format('truetype');
}

@font-face {
font-family: 'autoflex_subtitle';
src: url('inter_var.woff2') format('truetype');
}


.wy-side-nav-search { background-color: #b5445b; }
.wy-nav-top { background-color: #666666; }
.wy-menu > .caption > span.caption-text { color: #b5445b; }

.wy-nav-content { max-width: 900px !important; }
.wy-table-responsive table td { white-space: normal !important; }
.wy-table-responsive { overflow: visible !important; }
body { line-height: 1.42857143; }
.heading-style, h1, h2, h3, h4, h5, h6 {margin: 1.6rem 0 1rem;}
h1 {font-family: 'autoflex_title', sans-serif;}
h2, h3, h4, h5, h6 {font-family: 'autoflex_subtitle', sans-serif;}
p {margin-bottom: 0.5rem; font-family: 'Roboto', sans-serif}
iframe {width: 100%;border: unset}

.toctree-wrapper li[class^=toctree-l1]>a {font-size: 1.4em; text-decoration: none}
.toctree-wrapper li[class^=toctree-l2]>a {font-size: 1em; text-decoration: none}
.toctree-wrapper li[class^=toctree-l3]>a {font-size: 0.9em; text-decoration: none}
.toctree-wrapper li[class^=toctree-l4]>a {font-size: 0.9em; text-decoration: none}

html[data-theme="light"] {
--pst-color-primary: #b5445b;
--pst-color-secondary: #4772ae;
--tab-color: var(--pst-color-secondary);
--pst-color-link: var(--pst-color-muted);
}

html[data-theme="dark"] {
--pst-color-primary: #4772ae;
--pst-color-secondary: #b5445b;
--tab-color: #9647AE; /*#1C2E46;*/
--pst-color-link: var(--pst-color-muted);
--sd-color-info-bg: var(--pst-color-primary);
}

html[data-theme=dark] .bd-content .nboutput .output_area.rendered_html {
background-color: var(--pst-color-background);
}

img {
margin: 0.1em;
}


.sphinx-tabs-panel {
background: var(--sd-color-info-bg);
padding: 1em;
border-radius: 0.25rem;
margin-bottom: 0.5em;
border-top-left-radius: 0;
}

.sphinx-tabs-tab {
background: var(--tab-color);
padding: 0.5em;
padding-right: 2em;
padding-left: 2em;
margin-top: 0.5em;
margin-right: 0.5em;
border-top-left-radius: 1em;
border-top-right-radius: 0.1em;
border: 0;
font-weight: bold;
}

.sphinx-tabs-tab[aria-selected="true"] {
background-color: var(--sd-color-info-bg);
}

html[data-theme=dark] .dataframe {
background-color: var(--pst-color-primary);
}

/* TODO make sure this is only for the API tables */
/*table {*/
/* border: solid;*/
/*}*/

/*th {*/
/* border: thin;*/
/*}*/
Binary file added autoflex/styles/css/inter_var.woff2
Binary file not shown.
Binary file added autoflex/styles/css/ornitons_bold.ttf
Binary file not shown.
21 changes: 21 additions & 0 deletions autoflex/styles/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import shutil
import pathlib


def copy_autoflex_styles_to_static(app, exception):
# Define source directory where your styles are located
source_dir = pathlib.Path(__file__).parent / "css"

# Define destination directory in the build output's _static folder
build_static_dir = pathlib.Path(app.outdir) / '_static' / "css"

# Ensure the destination directory exists
build_static_dir.mkdir(parents=True, exist_ok=True)

# Copy all files from the source to the destination
for item in source_dir.iterdir():
if item.is_file():
shutil.copy(item, build_static_dir / item.name)
elif item.is_dir():
# Copy directories recursively
shutil.copytree(item, build_static_dir / item.name, dirs_exist_ok=True)
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = "sphinx_book_theme"
html_static_path = ['_static']
html_static_path = []
2 changes: 1 addition & 1 deletion docs/directives/autoflex.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
``autoflex``
============
------------

One of the main complexities we have is that managing `rst` code blocks in docstrings is complicated. It involves manually writing and updating parameter descriptions rather than focusing on the actual docstrings.

Expand Down
2 changes: 2 additions & 0 deletions docs/directives/flexsummary.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
``flexsummary``
---------------
4 changes: 4 additions & 0 deletions docs/directives/flextree.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
``flextree``
-------------

This should be a drop in replacement to ``toctree`` with more customizable options.
14 changes: 12 additions & 2 deletions docs/directives/index.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
Directives
==========

.. include:: autoflex.rst
.. include:: flextree.rst
.. include:: flexsummary.rst

.. flextree::
:hidden:

autoflex
flexsummary
flextree

autoflex
flextree
33 changes: 28 additions & 5 deletions docs/directives/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,33 @@ Usage Overview
* - Extension Command
- Brief Description
- Specification
* - ``flextree``
- A customizable toctree directive with options to create links with descriptions, custom formatting, and interactive features.
- https://github.com/flexcompute/autoflex/issues/10
* - ``autoflex``
- Our very extensible, automatic API documentation generator for classes.
-
* - ``flextree``
- A customizable ``toctree`` directive with options to create links with descriptions, custom formatting, and interactive features.
- https://github.com/flexcompute/autoflex/issues/10
* - ``flexsummary``
- A customizable ``autosummary`` directive.
- https://github.com/flexcompute/autoflex/issues/10



Basic ``autoflex`` Usage
^^^^^^^^^^^^^^^^^^^^^^^^^

If you just want to automatically generate the API documentation for a class with the default configuration by the extension.
You need to make sure you've delclared the relevant top path of the module you're in.

.. code:: rst
.. currentmodule:: tidy3d
.. autoflex:: tidy3d.Simulation
Basic ``flextree`` Usage
^^^^^^^^^^^^^^^^^^^^^^^^^

.. code:: rst
Expand All @@ -26,8 +46,11 @@ Usage Overview
:description: This is the description of the page.
Basic Example:
Basic ``flexsummary`` Usage
^^^^^^^^^^^^^^^^^^^^^^^^^^^

Custom ``autosummary`` implementation, based on ``autoflex`` directives.

.. code:: rst
.. autoflex:: somepackage.MyClass
.. flexsummary::
5 changes: 3 additions & 2 deletions docs/examples/demo.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Example
Custom Demo
-----------

.. autoflex::
Let's demonstrate some of the directives functionality with custom classes here.
11 changes: 5 additions & 6 deletions docs/examples/index.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
Examples
========

.. code:: bash
.. flextree::

poetry run python -m sphinx docs/ _docs/
.. include:: demo.rst

.. autoflex::
demo
tidy3d
9 changes: 9 additions & 0 deletions docs/examples/tidy3d.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
``tidy3d``
-----------


.. currentmodule:: tidy3d

.. autoflex:: tidy3d.Simulation

hey
24 changes: 23 additions & 1 deletion docs/get_started.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
Get Started
===========
=============

Install
--------

``autoflex`` is designed to be intentionally easy to install via ``pip`` and use within your project

.. code::
pip install autoflex
In your documentation project ``conf.py``:

.. code::
extensions = [
...
"autoflex",
...
]
That's it!

7 changes: 4 additions & 3 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
**************
``autoflex``
**************
**********************
autoflex
**********************

A flexible, nicer way of generating API docs without requiring custom docstrings.

Expand Down Expand Up @@ -33,6 +33,7 @@ Indices and tables

get_started
directives/index
examples/index
development


Expand Down
Loading

0 comments on commit 67c4615

Please sign in to comment.