Skip to content

Commit

Permalink
Updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
roll committed Apr 17, 2024
1 parent 8f30ccf commit a59d08c
Show file tree
Hide file tree
Showing 22 changed files with 89 additions and 23 deletions.
29 changes: 25 additions & 4 deletions docs/models/schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ The Table Schema model allows to manipulate a Pydantic model in Python according
## Usage

```python
from dplib.models import Schema, Field
from dplib.models import Schema, IntegerField

schema = Schema()
schema.add_field(Field(name='id', type='integer'))
schema.add_field(IntegerField(name='id'))
schema.missingValues = ['-']
print(schema.to_text(format="json"))
```
Expand All @@ -28,7 +28,28 @@ print(schema.to_text(format="json"))
## Reference

::: dplib.models.Schema
::: dplib.models.Field
::: dplib.models.Constraints
::: dplib.models.IFieldsMatch
::: dplib.models.ForeignKey
::: dplib.models.ForeignKeyReference
::: dplib.models.Field
::: dplib.models.AnyField
::: dplib.models.ArrayField
::: dplib.models.BooleanField
::: dplib.models.DateField
::: dplib.models.DatetimeField
::: dplib.models.DurationField
::: dplib.models.GeojsonField
::: dplib.models.GeopointField
::: dplib.models.IntegerField
::: dplib.models.ListField
::: dplib.models.NumberField
::: dplib.models.ObjectField
::: dplib.models.StringField
::: dplib.models.TimeField
::: dplib.models.YearField
::: dplib.models.YearmonthField
::: dplib.models.BaseConstraints
::: dplib.models.CollectionConstraints
::: dplib.models.JsonConstraints
::: dplib.models.StringConstraints
::: dplib.models.ValueConstraints
2 changes: 1 addition & 1 deletion dplib/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
from .license import License
from .package import Package
from .resource import Resource
from .schema import ForeignKey, ForeignKeyReference, Schema
from .schema import *
from .source import Source
2 changes: 2 additions & 0 deletions dplib/models/field/datatypes/any.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@


class AnyField(BaseField):
"""The field contains values of a unspecified or mixed type."""

type: Literal["any"] = "any"
format: Optional[Literal["default"]] = None
constraints: BaseConstraints = pydantic.Field(default_factory=BaseConstraints)
2 changes: 2 additions & 0 deletions dplib/models/field/datatypes/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@


class ArrayField(BaseField):
"""The field contains a valid JSON array."""

type: Literal["array"] = "array"
format: Optional[Literal["default"]] = None
constraints: JsonConstraints = pydantic.Field(default_factory=JsonConstraints)
2 changes: 1 addition & 1 deletion dplib/models/field/datatypes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


class BaseField(Model):
"""Table Schema Field model"""
"""Base Field"""

name: Optional[str] = None
"""
Expand Down
2 changes: 2 additions & 0 deletions dplib/models/field/datatypes/boolean.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@


class BooleanField(BaseField):
"""The field contains boolean (true/false) data."""

type: Literal["boolean"] = "boolean"
format: Optional[Literal["default"]] = None
constraints: BaseConstraints = pydantic.Field(default_factory=BaseConstraints)
Expand Down
2 changes: 2 additions & 0 deletions dplib/models/field/datatypes/date.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@


class DateField(BaseField):
"""he field contains a date without a time."""

type: Literal["date"] = "date"
format: Optional[str] = None
constraints: ValueConstraints = pydantic.Field(default_factory=ValueConstraints)
2 changes: 2 additions & 0 deletions dplib/models/field/datatypes/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@


class DatetimeField(BaseField):
"""The field contains a date with a time."""

type: Literal["datetime"] = "datetime"
format: Optional[str] = None
constraints: ValueConstraints = pydantic.Field(default_factory=ValueConstraints)
2 changes: 2 additions & 0 deletions dplib/models/field/datatypes/duration.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@


class DurationField(BaseField):
"""The field contains a duration of time."""

type: Literal["duration"] = "duration"
format: Optional[Literal["default"]] = None
constraints: ValueConstraints = pydantic.Field(default_factory=ValueConstraints)
11 changes: 9 additions & 2 deletions dplib/models/field/datatypes/geojson.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
from __future__ import annotations

from typing import Literal, Optional
from typing import Literal, Optional, Union

import pydantic

from ..constraints import BaseConstraints
from .base import BaseField

IGeojsonFormat = Union[
Literal["default"],
Literal["topojson"],
]


class GeojsonField(BaseField):
"""The field contains a JSON object according to GeoJSON or TopoJSON spec."""

type: Literal["geojson"] = "geojson"
format: Optional[Literal["default"]] = None
format: Optional[IGeojsonFormat] = None
constraints: BaseConstraints = pydantic.Field(default_factory=BaseConstraints)
12 changes: 10 additions & 2 deletions dplib/models/field/datatypes/geopoint.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
from __future__ import annotations

from typing import Literal, Optional
from typing import Literal, Optional, Union

import pydantic

from ..constraints import BaseConstraints
from .base import BaseField

IGeojsonFormat = Union[
Literal["default"],
Literal["array"],
Literal["object"],
]


class GeopointField(BaseField):
"""The field contains data describing a geographic point."""

type: Literal["geopoint"] = "geopoint"
format: Optional[Literal["default"]] = None
format: Optional[IGeojsonFormat] = None
constraints: BaseConstraints = pydantic.Field(default_factory=BaseConstraints)
10 changes: 6 additions & 4 deletions dplib/models/field/datatypes/integer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@


class IntegerField(BaseField):
"""The field contains integers - that is whole numbers."""

type: Literal["integer"] = "integer"
format: Optional[Literal["default"]] = None
constraints: ValueConstraints = pydantic.Field(default_factory=ValueConstraints)

bareNumber: Optional[bool] = None
groupChar: Optional[str] = None
"""
If false leading and trailing non numbers will be removed for integer/number fields
String whose value is used to group digits for integer/number fields
"""

groupChar: Optional[str] = None
bareNumber: bool = True
"""
String whose value is used to group digits for integer/number fields
If false leading and trailing non numbers will be removed for integer/number fields
"""
4 changes: 4 additions & 0 deletions dplib/models/field/datatypes/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@


class ListField(BaseField):
"""The field contains data that is an ordered
one-level depth collection of primitive values with a fixed item type.
"""

type: Literal["list"] = "list"
format: Optional[Literal["default"]] = None
constraints: CollectionConstraints = pydantic.Field(
Expand Down
10 changes: 6 additions & 4 deletions dplib/models/field/datatypes/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,23 @@


class NumberField(BaseField):
"""The field contains numbers of any kind including decimals."""

type: Literal["number"] = "number"
format: Optional[Literal["default"]] = None
constraints: ValueConstraints = pydantic.Field(default_factory=ValueConstraints)

bareNumber: Optional[bool] = None
decimalChar: str = "."
"""
If false leading and trailing non numbers will be removed for integer/number fields
String whose value is used to represent a decimal point for number fields
"""

groupChar: Optional[str] = None
"""
String whose value is used to group digits for integer/number fields
"""

decimalChar: Optional[str] = None
bareNumber: bool = True
"""
String whose value is used to represent a decimal point for number fields
If false leading and trailing non numbers will be removed for integer/number fields
"""
2 changes: 2 additions & 0 deletions dplib/models/field/datatypes/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@


class ObjectField(BaseField):
"""The field contains a valid JSON object."""

type: Literal["object"] = "object"
format: Optional[Literal["default"]] = None
constraints: JsonConstraints = pydantic.Field(default_factory=JsonConstraints)
2 changes: 2 additions & 0 deletions dplib/models/field/datatypes/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@


class StringField(BaseField):
"""The field contains strings, that is, sequences of characters."""

type: Literal["string"] = "string"
format: Optional[IStringFormat] = None
constraints: StringConstraints = pydantic.Field(default_factory=StringConstraints)
2 changes: 2 additions & 0 deletions dplib/models/field/datatypes/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@


class TimeField(BaseField):
"""The field contains a time without a date."""

type: Literal["time"] = "time"
format: Optional[str] = None
constraints: ValueConstraints = pydantic.Field(default_factory=ValueConstraints)
2 changes: 2 additions & 0 deletions dplib/models/field/datatypes/year.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@


class YearField(BaseField):
"""The field contains a calendar year."""

type: Literal["year"] = "year"
format: Optional[Literal["default"]] = None
constraints: ValueConstraints = pydantic.Field(default_factory=ValueConstraints)
2 changes: 2 additions & 0 deletions dplib/models/field/datatypes/yearmonth.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@


class YearmonthField(BaseField):
"""The field contains a specific month of a specific year."""

type: Literal["yearmonth"] = "yearmonth"
format: Optional[Literal["default"]] = None
constraints: ValueConstraints = pydantic.Field(default_factory=ValueConstraints)
2 changes: 2 additions & 0 deletions dplib/models/field/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@


class Field(BaseField):
"""Field with unspecified type."""

type: Literal[None] = None
format: Optional[Literal["default"]] = None
constraints: BaseConstraints = pydantic.Field(default_factory=BaseConstraints)
1 change: 1 addition & 0 deletions dplib/models/schema/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from .foreignKey import ForeignKey, ForeignKeyReference
from .schema import Schema
from .types import IFieldsMatch
7 changes: 2 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ dependencies = [
coverage = [
"sensible-browser coverage/index.html",
]
build = [
"mkdocs build",
docs = [
"mkdocs serve",
]
format = [
"ruff check --fix",
Expand All @@ -110,9 +110,6 @@ release = [
git push --follow-tags
"""
]
serve = [
"mkdocs serve",
]
spec = [
"pytest --cov dplib --cov-report term-missing --cov-report html:coverage --cov-fail-under 0 --timeout=300",
]
Expand Down

0 comments on commit a59d08c

Please sign in to comment.