Skip to content

Commit

Permalink
Fix ModuleNotFoundError if attrs is not installed
Browse files Browse the repository at this point in the history
  • Loading branch information
jayqi committed Apr 10, 2024
1 parent 8b4ea8a commit b34fa5c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 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

Check warning on line 18 in erdantic/examples/__init__.py

View check run for this annotation

Codecov / codecov/patch

erdantic/examples/__init__.py#L16-L18

Added lines #L16 - L18 were not covered by tests
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

0 comments on commit b34fa5c

Please sign in to comment.