Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "packages/tidy3d"]
path = packages/tidy3d
url = git@github.com:flexcompute/tidy3d.git
[submodule "packages/sphinx"]
path = packages/sphinx
url = git@github.com:daquintero/sphinx.git
3 changes: 3 additions & 0 deletions autoflex/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from autoflex.directives import AutoFlex
from autoflex.styles.setup import copy_autoflex_styles_to_static
from autoflex.extractors import determine_pydantic_version_from_base_model, get_field_infos
from autoflex.constructors.documenter import AutoflexDocumenter

__version__ = "0.0.1"
__author__ = "Dario Quintero Dominguez"
Expand All @@ -28,6 +29,8 @@ def setup(app) -> Dict[str, Any]:
print("Started loading `autoflex` extension.")
# DIRECTIVES
app.add_directive("autoflex", AutoFlex)

app.add_autodocumenter(AutoflexDocumenter)
# load the icon node/role
# app.add_node(icon_node, **_NODE_VISITORS) # type: ignore
# app.add_role("icon", Icon())
Expand Down
38 changes: 38 additions & 0 deletions autoflex/constructors/documenter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from autoflex.types.core import AutoflexBaseModel
from sphinx.ext.autodoc import ClassDocumenter

from sphinx.util import inspect, logging


logger = logging.getLogger(__name__)

class AutoflexDocumenter(ClassDocumenter):
objtype = 'flex'
# Optionally set a priority to override standard documenters if necessary
priority = 10 # higher priority wins if multiple documenters match

@classmethod
def can_document_member(cls, member, membername, isattr, parent):
# Determine if this documenter should handle the given member
logger.error(f"cls: {cls}")
return isinstance(member, AutoflexBaseModel)

def add_directive_header(self, sig):
# Customize the directive header if necessary
self.add_line(f".. autoflex:: {self.name}", self.get_sourcename())
super().add_directive_header(sig)


def add_content(self, more_content, no_docstring=False):
# Handle content based on the no_docstring flag if necessary
if not no_docstring:
# Add additional content if no_docstring is False
super().add_content(more_content)

def generate(self, *args, **kwargs):
# Customize generation logic if necessary
logger.error(f"self: {self}")
logger.error(f"*args: {args}")
logger.error(f"**kwargs: {kwargs}")
# super().generate(*args, **kwargs)

18 changes: 13 additions & 5 deletions autoflex/directives/autoflex.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from docutils import nodes
from docutils.parsers.rst import directives
from sphinx.util.docutils import SphinxDirective
from sphinx.ext.autodoc.directive import AutodocDirective
from sphinx.util.logging import getLogger
from pydantic import BaseModel
from pydantic.v1 import BaseModel as BaseModelV1
Expand All @@ -15,7 +16,7 @@

class AutoFlex(SphinxDirective):
"""
Extension of the ``.. autoflex::`` directive.
Extension of the ``.. autodoc::`` directive in a directly compatible format.

In order to maintain compatibility and extensibility with all versions of Pydantic,
this tool uses the interconnected JSON definition of the data structure instead of the
Expand Down Expand Up @@ -51,6 +52,8 @@ class AutoFlex(SphinxDirective):
}

def run(self) -> List[nodes.Node]:
# original_autodoc_result = super().run()

import_path = self.arguments[0]
logger.debug(f"AutoFlex processing import path: {import_path}")

Expand All @@ -71,6 +74,9 @@ def run(self) -> List[nodes.Node]:
# return [error]
pass


# return original_autodoc_result

# Generate documentation nodes from the schema
nodes_list = []

Expand All @@ -84,10 +90,10 @@ def run(self) -> List[nodes.Node]:
section_node += title_node

# Description
description = self.options.get('description', cls.__doc__)
if description:
description_node = nodes.paragraph(text=description)
section_node += description_node
# description = self.options.get('description', cls.__doc__)
# if description:
# description_node = nodes.paragraph(text=description)
# section_node += description_node
#
# # JSON Schema as a literal block
# try:
Expand Down Expand Up @@ -124,3 +130,5 @@ def run(self) -> List[nodes.Node]:
nodes_list.append(section_node)

return nodes_list


2 changes: 1 addition & 1 deletion autoflex/extractors/physical.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def field_info_to_property(field: pd.fields.FieldInfo, field_name: str) -> Prope
Returns:
Property: The corresponding Property instance.
"""
description = field.description or ""
description = ""
default = field.default if field.default is not None else ""
types = str(field.outer_type_) if hasattr(field, 'outer_type_') else ""

Expand Down
1 change: 1 addition & 0 deletions autoflex/types/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from autoflex.types.input import AutoflexInputClassTypes
from autoflex.types.property import PhysicalProperty, Property, PropertyTypes
from autoflex.types.descriptors import Symbolic, SymbolicTypes, Unit, UnitTypes
from autoflex.types.field_info import PhysicalFieldInfo, FieldTypes
Expand Down
11 changes: 11 additions & 0 deletions autoflex/types/input.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from typing import Union
import pydantic as pd
import pydantic.v1 as pd1

AutoflexInputClassTypes = Union[
pd._internal._model_construction.ModelMetaclass,
pd.BaseModel,
pd1.BaseModel
]


1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

extensions = [
"autoflex",
"sphinx.ext.autodoc"
]

templates_path = [
Expand Down
7 changes: 7 additions & 0 deletions docs/examples/flow360.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
``flow360``
-----------


.. currentmodule:: flow360

.. autoflex:: flow360.RotorDisk
1 change: 1 addition & 0 deletions docs/examples/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ Examples

demo
tidy3d
flow360
5 changes: 5 additions & 0 deletions docs/examples/tidy3d.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@

.. currentmodule:: tidy3d


.. autoflex:: tidy3d.Simulation


.. autoclass:: tidy3d.Simulation
Loading