Skip to content

Commit

Permalink
Swap to ruff for formatting and linting
Browse files Browse the repository at this point in the history
  • Loading branch information
jayqi committed Feb 10, 2024
1 parent 1758aba commit 6e19b6f
Show file tree
Hide file tree
Showing 20 changed files with 45 additions and 52 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ help:
@python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST)

lint: ## run linting and code quality checks
black --check erdantic tests docs
flake8 erdantic tests docs
ruff format --check erdantic tests docs
ruff check erdantic tests docs

pypitest: dist
twine upload --repository testpypi dist/*
Expand Down
4 changes: 2 additions & 2 deletions erdantic/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from erdantic.erd import create, draw, EntityRelationshipDiagram, to_dot
import erdantic.pydantic # noqa: F401
import erdantic.dataclasses # noqa: F401
from erdantic.erd import EntityRelationshipDiagram, create, draw, to_dot
import erdantic.pydantic # noqa: F401
from erdantic.version import __version__

__version__
Expand Down
1 change: 0 additions & 1 deletion erdantic/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from erdantic.exceptions import InvalidModelAdapterError, ModelAdapterNotFoundError
from erdantic.typing import Final, GenericAlias, repr_type


_row_template = """<tr><td>{name}</td><td port="{name}">{type_name}</td></tr>"""


Expand Down
3 changes: 1 addition & 2 deletions erdantic/cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import Enum
from importlib import import_module
from pathlib import Path
from typing import List, Optional, TYPE_CHECKING
from typing import TYPE_CHECKING, List, Optional

import typer

Expand All @@ -10,7 +10,6 @@
from erdantic.exceptions import ModelOrModuleNotFoundError
from erdantic.version import __version__


app = typer.Typer()


Expand Down
1 change: 0 additions & 1 deletion erdantic/dataclasses.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import dataclasses
from typing import Any, List, Union


from erdantic.base import Field, Model, register_model_adapter
from erdantic.exceptions import InvalidFieldError, InvalidModelError
from erdantic.typing import GenericAlias, is_many, is_nullable
Expand Down
6 changes: 3 additions & 3 deletions erdantic/erd.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

import pygraphviz as pgv

from erdantic.base import Field, get_model_adapter, Model, model_adapter_registry
from erdantic.base import Field, Model, get_model_adapter, model_adapter_registry
from erdantic.exceptions import (
NotATypeError,
_StringForwardRefError,
StringForwardRefError,
_UnevaluatedForwardRefError,
UnevaluatedForwardRefError,
UnknownFieldError,
UnknownModelTypeError,
_StringForwardRefError,
_UnevaluatedForwardRefError,
)
from erdantic.typing import get_recursive_args
from erdantic.version import __version__
Expand Down
3 changes: 1 addition & 2 deletions erdantic/examples/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Example data model classes."""

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

__all__ = [
"dataclasses",
Expand Down
10 changes: 6 additions & 4 deletions erdantic/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from typing import Optional, TYPE_CHECKING

from typing import ForwardRef # docs claim Python >= 3.7.4 but actually it's in Python 3.7.0+
from typing import (
TYPE_CHECKING,
ForwardRef, # docs claim Python >= 3.7.4 but actually it's in Python 3.7.0+
Optional,
)

if TYPE_CHECKING:
from erdantic.base import Model, Field
from erdantic.base import Field, Model

Check warning on line 8 in erdantic/exceptions.py

View check run for this annotation

Codecov / codecov/patch

erdantic/exceptions.py#L8

Added line #L8 was not covered by tests


class ErdanticException(Exception):
Expand Down
4 changes: 2 additions & 2 deletions erdantic/pydantic.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from typing import Any, List, Union, Type
from typing import Any, List, Type, Union

import pydantic
import pydantic.fields
import pydantic_core

from erdantic.base import Field, Model, register_model_adapter
from erdantic.exceptions import InvalidFieldError, InvalidModelError
from erdantic.typing import GenericAlias, repr_type_with_mro, is_many, is_nullable
from erdantic.typing import GenericAlias, is_many, is_nullable, repr_type_with_mro


class PydanticField(Field[pydantic.fields.FieldInfo]):
Expand Down
1 change: 0 additions & 1 deletion erdantic/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

from erdantic.exceptions import _StringForwardRefError, _UnevaluatedForwardRefError


try:
from typing import get_args, get_origin # type: ignore # Python 3.8+
except ImportError:
Expand Down
27 changes: 14 additions & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,21 @@ erdantic = "erdantic.cli:app"
"Bug Tracker" = "https://github.com/drivendataorg/erdantic/issues"
"Changelog" = "https://erdantic.drivendata.org/stable/changelog/"

[tool.black]
[tool.ruff]
line-length = 99
include = '\.pyi?$'
exclude = '''
/(
\.eggs
| \.git
| \.mypy_cache
| \.tox
| \.venv
| build
| dist
)/
'''
src = ["erdantic/**/*.py", "tests/**/*.py"]

[tool.ruff.lint]
select = [
"E", # Pyflakes
"F", # Pycodestyle
"I", # isort
]
unfixable = ["F"]

[tool.ruff.lint.isort]
known-first-party = ["erdantic"]
force-sort-within-sections = true

[tool.mypy]
ignore_missing_imports = true
Expand Down
3 changes: 1 addition & 2 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
-e .

black
build
flake8
jupyterlab
mdx_truly_sane_lists==1.3
mike
Expand All @@ -15,5 +13,6 @@ nbconvert<6.5
pytest<8
pytest-cases
pytest-cov
ruff>=0.1.14
twine
wheel
3 changes: 0 additions & 3 deletions setup.cfg

This file was deleted.

1 change: 0 additions & 1 deletion tests/scripts/generate_static_assets.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from pathlib import Path
from types import ModuleType


import erdantic as erd
import erdantic.erd
import erdantic.examples.dataclasses
Expand Down
4 changes: 1 addition & 3 deletions tests/test_adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@
from pytest_cases import param_fixtures

import erdantic as erd
from erdantic.dataclasses import DataClassField, DataClassModel
import erdantic.erd
import erdantic.examples.dataclasses
import erdantic.examples.pydantic
from erdantic.dataclasses import DataClassField, DataClassModel
from erdantic.pydantic import PydanticField, PydanticModel

from tests.utils import assert_dot_equals


ASSETS_DIR = Path(__file__).parent / "assets"

# key, model class, field class, examples module
Expand Down
2 changes: 1 addition & 1 deletion tests/test_base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

import erdantic as erd
from erdantic.base import Field, get_model_adapter, Model, register_model_adapter
from erdantic.base import Field, Model, get_model_adapter, register_model_adapter
from erdantic.examples.pydantic import Party
from erdantic.exceptions import InvalidModelAdapterError, ModelAdapterNotFoundError
from erdantic.pydantic import PydanticModel
Expand Down
1 change: 0 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from erdantic.exceptions import ModelOrModuleNotFoundError
from erdantic.version import __version__


runner = CliRunner()


Expand Down
10 changes: 7 additions & 3 deletions tests/test_dataclasses.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import dataclasses
from typing import Dict, List, Tuple, get_type_hints

from typing import ForwardRef # docs claim Python >= 3.7.4 but actually it's in Python 3.7.0+
from typing import (
Dict,
ForwardRef, # docs claim Python >= 3.7.4 but actually it's in Python 3.7.0+
List,
Tuple,
get_type_hints,
)

import pytest

Expand Down
8 changes: 4 additions & 4 deletions tests/test_erd.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

import erdantic as erd
from erdantic.erd import Edge, find_models
import erdantic.examples.dataclasses as examples_dataclasses
import erdantic.examples.pydantic as examples_pydantic
from erdantic.examples.pydantic import Adventurer, Party, Quest, QuestGiver
from erdantic.exceptions import (
NotATypeError,
InvalidModelAdapterError,
ModelAdapterNotFoundError,
NotATypeError,
UnknownModelTypeError,
)
from erdantic.examples.pydantic import Party, Adventurer, Quest, QuestGiver
import erdantic.examples.pydantic as examples_pydantic
import erdantic.examples.dataclasses as examples_dataclasses
from erdantic.pydantic import PydanticModel


Expand Down
1 change: 0 additions & 1 deletion tests/test_typing.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from enum import Enum, IntFlag
import sys
import typing

from typing import ForwardRef # docs claim Python >= 3.7.4 but actually it's in Python 3.7.0+

try:
Expand Down

0 comments on commit 6e19b6f

Please sign in to comment.