Skip to content

Commit

Permalink
Fix errors reported by ruff and numpydoc
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremyMcCormick committed Feb 27, 2025
1 parent 42b0e39 commit 1c12af5
Show file tree
Hide file tree
Showing 17 changed files with 114 additions and 54 deletions.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This configuration only affects single-package Sphinx documenation builds.
"""

from documenteer.conf.guide import * # noqa: F403,F401
from documenteer.conf.guide import * # noqa: F403

autodoc_pydantic_model_show_config_summary = False
autodoc_pydantic_settings_show_config_summary = False
Expand Down
87 changes: 77 additions & 10 deletions python/felis/datamodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@
import sys
from collections.abc import Sequence
from enum import StrEnum, auto
from typing import IO, Annotated, Any, Generic, Literal, TypeAlias, TypeVar, Union
from typing import IO, Annotated, Any, Generic, Literal, TypeAlias, TypeVar

import yaml
from astropy import units as units # type: ignore
from astropy.io.votable import ucd # type: ignore
from lsst.resources import ResourcePath, ResourcePathExpression
from pydantic import (
BaseModel,
ConfigDict,
Expand All @@ -44,6 +43,8 @@
model_validator,
)

from lsst.resources import ResourcePath, ResourcePathExpression

from .db.dialects import get_supported_dialects
from .db.sqltypes import get_type_func
from .db.utils import string_to_typeengine
Expand All @@ -53,8 +54,8 @@

__all__ = (
"BaseObject",
"Column",
"CheckConstraint",
"Column",
"Constraint",
"DataType",
"ForeignKeyConstraint",
Expand Down Expand Up @@ -472,13 +473,35 @@ def check_votable_arraysize(cls, values: dict[str, Any]) -> dict[str, Any]:

@field_serializer("datatype")
def serialize_datatype(self, value: DataType) -> str:
"""Convert `DataType` to string when serializing to JSON/YAML."""
"""Convert `DataType` to string when serializing to JSON/YAML.
Parameters
----------
value
The `DataType` value to serialize.
Returns
-------
`str`
The serialized `DataType` value.
"""
return str(value)

@field_validator("datatype", mode="before")
@classmethod
def deserialize_datatype(cls, value: str) -> DataType:
"""Convert string back into `DataType` when loading from JSON/YAML."""
"""Convert string back into `DataType` when loading from JSON/YAML.
Parameters
----------
value
The string value to deserialize.
Returns
-------
`DataType`
The deserialized `DataType` value.
"""
return DataType(value)


Expand Down Expand Up @@ -518,7 +541,18 @@ class CheckConstraint(Constraint):

@field_serializer("type")
def serialize_type(self, value: str) -> str:
"""Ensure '@type' is included in serialized output."""
"""Ensure '@type' is included in serialized output.
Parameters
----------
value
The value to serialize.
Returns
-------
`str`
The serialized value.
"""
return value


Expand All @@ -533,7 +567,18 @@ class UniqueConstraint(Constraint):

@field_serializer("type")
def serialize_type(self, value: str) -> str:
"""Ensure '@type' is included in serialized output."""
"""Ensure '@type' is included in serialized output.
Parameters
----------
value
The value to serialize.
Returns
-------
`str`
The serialized value.
"""
return value


Expand All @@ -560,12 +605,23 @@ class ForeignKeyConstraint(Constraint):

@field_serializer("type")
def serialize_type(self, value: str) -> str:
"""Ensure '@type' is included in serialized output."""
"""Ensure '@type' is included in serialized output.
Parameters
----------
value
The value to serialize.
Returns
-------
`str`
The serialized value.
"""
return value


_ConstraintType = Annotated[
Union[CheckConstraint, ForeignKeyConstraint, UniqueConstraint], Field(discriminator="type")
CheckConstraint | ForeignKeyConstraint | UniqueConstraint, Field(discriminator="type")
]
"""Type alias for a constraint type."""

Expand Down Expand Up @@ -675,7 +731,18 @@ def _dereference_columns(self) -> None:

@field_serializer("columns")
def serialize_columns(self, columns: list[ColumnRef | Column]) -> list[str]:
"""Serialize columns as their IDs."""
"""Serialize columns as their IDs.
Parameters
----------
columns
The columns to serialize.
Returns
-------
`list` [ `str` ]
The serialized column IDs.
"""
return [col if isinstance(col, str) else col.id for col in columns]


Expand Down
2 changes: 1 addition & 1 deletion python/felis/db/dialects.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

from .sqltypes import MYSQL, POSTGRES, SQLITE

__all__ = ["get_supported_dialects", "get_dialect_module"]
__all__ = ["get_dialect_module", "get_supported_dialects"]

_DIALECT_NAMES = (MYSQL, POSTGRES, SQLITE)
"""List of supported dialect names.
Expand Down
14 changes: 7 additions & 7 deletions python/felis/db/sqltypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,20 @@
from sqlalchemy.ext.compiler import compiles

__all__ = [
"binary",
"boolean",
"byte",
"short",
"char",
"double",
"float",
"get_type_func",
"int",
"long",
"float",
"double",
"char",
"short",
"string",
"unicode",
"text",
"binary",
"timestamp",
"get_type_func",
"unicode",
]

MYSQL = "mysql"
Expand Down
2 changes: 1 addition & 1 deletion python/felis/db/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

from .dialects import get_dialect_module

__all__ = ["string_to_typeengine", "SQLWriter", "ConnectionWrapper", "DatabaseContext"]
__all__ = ["ConnectionWrapper", "DatabaseContext", "SQLWriter", "string_to_typeengine"]

logger = logging.getLogger("felis")

Expand Down
2 changes: 1 addition & 1 deletion python/felis/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from .datamodel import Schema
from .metadata import MetaDataBuilder

__all__ = ["SchemaDiff", "DatabaseDiff"]
__all__ = ["DatabaseDiff", "SchemaDiff"]

logger = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion python/felis/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import logging
from typing import Any, Literal

from lsst.utils.iteration import ensure_iterable
from sqlalchemy import (
CheckConstraint,
Column,
Expand All @@ -45,6 +44,7 @@

from felis.datamodel import Schema
from felis.db.variants import make_variant_dict
from lsst.utils.iteration import ensure_iterable

from . import datamodel
from .db import sqltypes
Expand Down
4 changes: 2 additions & 2 deletions python/felis/tap_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import re
from typing import Any

from lsst.resources import ResourcePath
from sqlalchemy import MetaData, Table, text
from sqlalchemy.engine import Connection, Engine
from sqlalchemy.engine.mock import MockConnection
Expand All @@ -38,10 +37,11 @@
from felis.datamodel import Schema
from felis.db.utils import is_valid_engine
from felis.metadata import MetaDataBuilder
from lsst.resources import ResourcePath

from .types import FelisType

__all__ = ["TableManager", "DataLoader"]
__all__ = ["DataLoader", "TableManager"]

logger = logging.getLogger(__name__)

Expand Down
14 changes: 7 additions & 7 deletions python/felis/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@
from typing import Any

__all__ = [
"FelisType",
"Binary",
"Boolean",
"Byte",
"Short",
"Char",
"Double",
"FelisType",
"Float",
"Int",
"Long",
"Float",
"Double",
"Char",
"Short",
"String",
"Unicode",
"Text",
"Binary",
"Timestamp",
"Unicode",
]


Expand Down
5 changes: 2 additions & 3 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@
import tempfile
import unittest

from click.testing import CliRunner
from sqlalchemy import create_engine

import felis.tap_schema as tap_schema
from click.testing import CliRunner
from felis.cli import cli
from felis.datamodel import Schema
from felis.metadata import MetaDataBuilder
from sqlalchemy import create_engine

TESTDIR = os.path.abspath(os.path.dirname(__file__))
TEST_YAML = os.path.join(TESTDIR, "data", "test.yml")
Expand Down
6 changes: 3 additions & 3 deletions tests/test_datamodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
from collections import defaultdict

import yaml
from lsst.resources import ResourcePath
from pydantic import ValidationError

from felis.datamodel import (
CheckConstraint,
Column,
Expand All @@ -43,6 +40,9 @@
Table,
UniqueConstraint,
)
from pydantic import ValidationError

from lsst.resources import ResourcePath

TEST_DIR = os.path.abspath(os.path.dirname(__file__))
TEST_YAML = os.path.join(TEST_DIR, "data", "test.yml")
Expand Down
3 changes: 1 addition & 2 deletions tests/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@
import tempfile
from unittest import TestCase

from sqlalchemy import MetaData, create_engine

from felis import Schema
from felis.db.schema import create_database
from felis.db.utils import DatabaseContext
from sqlalchemy import MetaData, create_engine

TESTDIR = os.path.abspath(os.path.dirname(__file__))
TESTFILE = os.path.join(TESTDIR, "data", "sales.yaml")
Expand Down
3 changes: 1 addition & 2 deletions tests/test_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@

import unittest

from sqlalchemy import create_engine

from felis import datamodel as dm
from felis.diff import DatabaseDiff, FormattedSchemaDiff, SchemaDiff
from felis.metadata import MetaDataBuilder
from sqlalchemy import create_engine


class TestSchemaDiff(unittest.TestCase):
Expand Down
9 changes: 4 additions & 5 deletions tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
import unittest

import yaml
from felis import datamodel as dm
from felis.datamodel import Schema
from felis.db.utils import DatabaseContext
from felis.metadata import MetaDataBuilder, get_datatype_with_variants
from sqlalchemy import (
CheckConstraint,
Constraint,
Expand All @@ -34,11 +38,6 @@
create_engine,
)

from felis import datamodel as dm
from felis.datamodel import Schema
from felis.db.utils import DatabaseContext
from felis.metadata import MetaDataBuilder, get_datatype_with_variants

TESTDIR = os.path.abspath(os.path.dirname(__file__))
TEST_YAML = os.path.join(TESTDIR, "data", "sales.yaml")

Expand Down
3 changes: 1 addition & 2 deletions tests/test_postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@
import unittest

import yaml
from sqlalchemy import text

from felis.datamodel import Schema
from felis.db.utils import DatabaseContext
from felis.metadata import MetaDataBuilder
from felis.tests.postgresql import TemporaryPostgresInstance, setup_postgres_test_db # type: ignore
from sqlalchemy import text

TESTDIR = os.path.abspath(os.path.dirname(__file__))
TEST_YAML = os.path.join(TESTDIR, "data", "sales.yaml")
Expand Down
3 changes: 1 addition & 2 deletions tests/test_tap_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@
import unittest
from typing import Any

from sqlalchemy import Engine, MetaData, create_engine, select

from felis.datamodel import Schema
from felis.tap_schema import DataLoader, TableManager
from sqlalchemy import Engine, MetaData, create_engine, select

TEST_DIR = os.path.dirname(__file__)
TEST_SALES = os.path.join(TEST_DIR, "data", "sales.yaml")
Expand Down
Loading

0 comments on commit 1c12af5

Please sign in to comment.