Skip to content

Commit

Permalink
Docs stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
jayqi committed Mar 25, 2024
1 parent 6e5ff7e commit f49a0ff
Show file tree
Hide file tree
Showing 11 changed files with 734 additions and 651 deletions.
26 changes: 25 additions & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,40 @@

This release features significant changes to erdantic, primarily to how data is represented in the backend. If you have been primarily using the CLI or the convenience functions `create`, `draw`, and `to_dot`, then your should not be majorly impacted.

### Rendering changes
### CLI changes

- Deprecated `--termini` option. Use the new `--terminal-model` option instead. The shorthand option `-t` remains the same.

### Convenience function changes

- Deprecated `termini` argument for `create`, `draw`, and `to_dot` functions. Use the new `terminal_models` argument instead.
- Added `graph_attr`, `node_attr`, and `edge_attr` arguments to the `draw` and `to_dot` functions that allow you to override attributes on the generated pygraphviz object for the diagram.

### Rendered content changes

A few changes have been made to the content of rendered diagrams.

- Changed the extraction of type names to use the [typenames](https://github.com/jayqi/typenames) library. This should generally produce with same rendered outputs, with the following exception:
- Removed the special case behavior for rendering enum classes. Enums now just show the class name without inheritance information.
- Changed collection fields (e.g., `List[TargetModel]`) to display as a "many" relationship (crow) instead of a "zero-or-many" relationship (odot + crow), treating the modality of the field as unspecified. A field will only be displayed as "zero-or-many" (odot + crow) if it is explicitly optional, like `Optional[List[TargetModel]]`.

### Support for attrs

- Added support for [attrs](https://www.attrs.org/en/stable/index.html) classes, i.e., classes decorated by `attrs.define`. The source code for attrs support can be found in the new module `erdantic.plugins.attrs`.
- Added new example module `erdantic.examples.attrs`.

### Backend changes

Significant changes have been made to the library backend to facilitate customizing diagrams and to more clearly structure the steps in creating a diagram from input models. Please see the new documentation pages ["Customizing diagrams"](http://erdantic.drivendata.org/stable/customizing/) and ["Plugins for model frameworks"](http://erdantic.drivendata.org/stable/customizing/) for details on the new design.

A summary of some key changes is below:

- Removed the adapter base classes `Model` and `Field`, and the implemented adapters `DataClassModel`, `DataClassField`, `PydanticModel`, and `PydanticField`.
- Added new Pydantic models `ModelInfo` and `FieldInfo` to replace the adapter system. These new models hold static data that have been extracted from models that erdantic analyzed.
- Removed the adapter system and associated objects such as `model_adapter_registry` and `register_model_adapter`.
- Added new plugin system to replace the adapter system as the way that modeling frameworks are supported. Plugins must implement two functions—a predicate function and a field extractor function—and be registered using `register_plugin`. All objects related to plugins can be found in the new `erdantic.plugins` module and its submodules.


## v0.8.0 (Unreleased)

- Removed support for Python 3.7. ([PR #102](https://github.com/drivendataorg/erdantic/pull/102))
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/api-reference/plugins/attrs.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# erdantic.plugins.pydantic
# erdantic.plugins.attrs

::: erdantic.plugins.pydantic
::: erdantic.plugins.attrs
4 changes: 2 additions & 2 deletions docs/docs/api-reference/plugins/pydantic.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# erdantic.plugins.dataclasses
# erdantic.plugins.pydantic

::: erdantic.plugins.dataclasses
::: erdantic.plugins.pydantic
477 changes: 246 additions & 231 deletions docs/docs/examples/dataclasses.ipynb

Large diffs are not rendered by default.

186 changes: 96 additions & 90 deletions docs/docs/examples/dataclasses.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
486 changes: 253 additions & 233 deletions docs/docs/examples/pydantic.ipynb

Large diffs are not rendered by default.

186 changes: 96 additions & 90 deletions docs/docs/examples/pydantic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def _inject_cli_help(markdown: str):


def _inject_model_predicate_source(markdown: str):
logger.info("Injecting ModelPRedicate source code into page markdown")
logger.info("Injecting ModelPredicate source code into page markdown")
source = inspect.getsource(erdantic.plugins.ModelPredicate)
code_block = textwrap.dedent("""\
```python
Expand Down
3 changes: 2 additions & 1 deletion docs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ markdown_extensions:

plugins:
- search
- mkdocs-jupyter
- mkdocs-jupyter:
execute: false
- mkdocstrings:
default_handler: python
handlers:
Expand Down
8 changes: 8 additions & 0 deletions erdantic/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,3 +617,11 @@ def to_dot(
node_attr=node_attr,
edge_attr=edge_attr,
).string()

def _repr_png_(self) -> bytes:
graph = self.to_graphviz()
return graph.draw(prog="dot", format="png")

def _repr_svg_(self) -> str:
graph = self.to_graphviz()
return graph.draw(prog="dot", format="svg").decode(graph.encoding)
3 changes: 3 additions & 0 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
-e .[attrs]

-r lint.txt

ipython
ipykernel

0 comments on commit f49a0ff

Please sign in to comment.