Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
mferrera committed Jun 24, 2024
1 parent b8e21e5 commit 3951750
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ coverage.xml
# Sphinx documentation
docs/_build/
docs/src/apiref/
docs/src/datamodel/generated
docs/src/datamodel/model

# PyBuilder
target/
Expand Down
39 changes: 1 addition & 38 deletions docs/ext/pydantic_autosummary/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import pydoc
import re
import sys
import typing
from enum import Enum
from os import path
from typing import TYPE_CHECKING, Any, NamedTuple

Expand All @@ -50,6 +48,7 @@
import_by_name,
import_ivar_by_name,
)
from .pydantic import _set_pydantic_model_fields

# ----------/ pydantic_autosummary change

Expand Down Expand Up @@ -398,42 +397,6 @@ def generate_autosummary_content(
return template.render(template_name or doc.objtype, ns)


# ----------- pydantic_autosummary change


def _resolve_pydantic_field_type(annotation: Any) -> Any:
origin = typing.get_origin(annotation)
res = annotation
if origin is typing.Literal:
res = annotation.__args__[0]
elif origin is typing.Optional or origin is typing.Union:
print("AAAAAAAAAAAA", annotation.__args__, file=sys.stderr)
elif origin is list:
res = annotation.__args__[0]

if isinstance(res, (str, Enum)):
return None
if not res.__module__.startswith("fmu.dataio.datastructure.meta"):
return None
return f"{res.__module__}.{res.__qualname__}"


def _set_pydantic_model_fields(ns: dict[str, Any], obj: Any) -> None:
ns["obj"] = obj
ns["is_int"] = issubclass(obj, int)
ns["is_str"] = issubclass(obj, str)
annotations = [
_resolve_pydantic_field_type(field.annotation)
for field in obj.model_fields.values()
]
annotations = list(filter(None, annotations))
ns["model_fields"] = annotations
print("#########", ns["model_fields"])


# ----------/ pydantic_autosummary change


def _skip_member(app: Sphinx, obj: Any, name: str, objtype: str) -> bool:
try:
return app.emit_firstresult(
Expand Down
33 changes: 33 additions & 0 deletions docs/ext/pydantic_autosummary/pydantic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from __future__ import annotations

import sys
import typing
from enum import Enum


def _set_pydantic_model_fields(ns: dict[str, typing.Any], obj: typing.Any) -> None:
ns["obj"] = obj
ns["is_int"] = issubclass(obj, int)
ns["is_str"] = issubclass(obj, str)

annotations = [
_resolve_pydantic_field_type(field.annotation)
for field in obj.model_fields.values()
]
ns["model_fields"] = list(filter(None, annotations))

print("#########", ns["model_fields"])


def _resolve_pydantic_field_type(annotation: typing.Any) -> typing.Any:
origin = typing.get_origin(annotation)
if origin is typing.Literal or origin is list:
annotation = annotation.__args__[0]
elif origin is typing.Optional or origin is typing.Union:
print("AAAAAAAAAAAA", annotation.__args__, file=sys.stderr)

if isinstance(annotation, (str, Enum)):
return None
if not annotation.__module__.startswith("fmu.dataio.datastructure.meta"):
return None
return f"{annotation.__module__}.{annotation.__qualname__}"
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,26 @@
.. currentmodule:: {{ module }}

.. autosummary::
:toctree: generated/
:toctree: {{ name }}
:recursive:

.. toctree::
:maxdepth: -1

{% block model_fields %}
{% for type in model_fields %}
{{ type }}
{% for field in model_fields %}
~{{ field }}
{% endfor %}
{% endblock %}

.. autopydantic_model:: {{ objname }}
:members:
:show-inheritance:
:inherited-members: BaseModel
:model-show-config-summary: False
:model-show-json: False
:model-show-validator-members: False
:model-show-validator-summary: False
:field-list-validators: False
:special-members: __call__, __add__, __mul__

{% block methods %}
Expand Down
13 changes: 7 additions & 6 deletions docs/src/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
import sys
from pathlib import Path

sys.path.insert(0, os.path.abspath("../../src/fmu"))
sys.path.insert(1, os.path.abspath("../ext"))
print(sys.path)

from datetime import date

import fmu.dataio
import fmu.dataio.dataio

sys.path.insert(0, os.path.abspath("../../src/fmu"))
sys.path.insert(1, os.path.abspath("../ext"))


# -- General configuration ---------------------------------------------

Expand Down Expand Up @@ -68,16 +67,18 @@
autodoc_default_flags = ["members", "show_inheritance"]

# Mocking ert module
autodoc_mock_imports = ["ert"]
autodoc_mock_imports = ["ert", "pydantic"]

exclude_patterns = ["_build"]

pygments_style = "sphinx"

html_theme = "sphinx_rtd_theme"

html_theme_options = {
"style_nav_header_background": "#C0C0C0",
"navigation_depth": -1,
"collapse_navigation": False,
"titles_only": True,
}


Expand Down
14 changes: 9 additions & 5 deletions docs/src/datamodel/modules.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
fmu-dataio data model
=====================
The FMU results data model
##########################

.. autosummary::
:toctree: generated/
:toctree: model/
:recursive:

fmu.dataio.datastructure.meta.meta.FMUDataClassMeta
fmu.dataio.datastructure.meta.meta.FMUCaseClassMeta

.. toctree::
:maxdepth: -1

fmu.dataio.datastructure.meta.meta.FMUDataClassMeta
fmu.dataio.datastructure.meta.meta.FMUCaseClassMeta
2 changes: 1 addition & 1 deletion docs/src/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Press + to see generated YAML files for metadata.

.. toggle::

.. literalinclude:: ../../examples/s/d/nn/xcase/realization-0/iter-0/share/results/grids/.facies.roff.yml
.. literalinclude:: ../../examples/s/d/nn/xcase/realization-0/iter-0/share/results/grids/.geogrid--facies.roff.yml
:language: yaml

|
Expand Down
6 changes: 6 additions & 0 deletions docs/src/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,10 @@ post-processing services, new and improved cloud-only version of Webviz and much
examples
apiref/modules
datamodel

.. toctree::
:maxdepth: -1
:hidden:
:caption: Data Model

datamodel/modules

0 comments on commit 3951750

Please sign in to comment.