Skip to content

Commit

Permalink
Fix ModuleNotFoundError if attrs is not installed when importing exam…
Browse files Browse the repository at this point in the history
…ples (#113)

* Fix ModuleNotFoundError if attrs is not installed

* Bump version

---------

Co-authored-by: Jay Qi <[email protected]>
  • Loading branch information
jayqi and jayqi committed Apr 10, 2024
1 parent 8b4ea8a commit e712754
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# erdantic Changelog

## v1.0.1 (2024-04-10)

- Fixed `ModuleNotFoundError` when importing from `erdantic.examples` without attrs installed.

## v1.0.0.post2 (2024-04-10)

- Fixed missing LICENSE file in sdist.
Expand Down
12 changes: 10 additions & 2 deletions erdantic/examples/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
"""Example data model classes."""

from erdantic.examples import attrs, dataclasses, pydantic, pydantic_v1
from erdantic.examples import dataclasses, pydantic, pydantic_v1

__all__ = [
"attrs",
"dataclasses",
"pydantic",
"pydantic_v1",
]

try:
from erdantic.examples import attrs

attrs
__all__.append("attrs")
except ModuleNotFoundError as e:
if e.name != "attrs":
raise
7 changes: 6 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ def test_wheel(session, extras):
else:
session.install(str(wheel_path) + extras)
session.run("python", "-m", "erdantic", "--version")
session.run("python", "-c", "import erdantic; print(erdantic.list_plugins())")
session.run(
"python", "-c", "import erdantic; import erdantic.examples; print(erdantic.list_plugins())"
)


@nox.session(venv_backend="mamba|conda", python="3.12", reuse_venv=False)
Expand All @@ -120,6 +122,9 @@ def test_sdist(session):
else:
session.install(sdist_path)
session.run("python", "-m", "erdantic", "--version")
session.run(
"python", "-c", "import erdantic; import erdantic.examples; print(erdantic.list_plugins())"
)


def _docs_base(session):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "erdantic"
version = "1.0.0.post2"
version = "1.0.1"
description = "Entity relationship diagrams for Python data model classes like Pydantic."
readme = "README.md"
authors = [{ name = "DrivenData", email = "[email protected]" }, { name = "Jay Qi" }]
Expand Down

0 comments on commit e712754

Please sign in to comment.