Skip to content

Commit

Permalink
fix: pydantic and faust-streaming optional dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosschroh committed Apr 21, 2023
1 parent da2a328 commit e821fa3
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 92 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
python -m pip install -U pip poetry
poetry --version
poetry config --local virtualenvs.in-project true
poetry install
poetry install --extras "pydantic faust"
- name: Test
run: ./scripts/test
Expand Down
42 changes: 30 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
Generate [Avro](https://avro.apache.org/docs/1.8.2/spec.html) Schemas from a Python class

[![Tests](https://github.com/marcosschroh/dataclasses-avroschema/actions/workflows/tests.yaml/badge.svg)](https://github.com/marcosschroh/dataclasses-avroschema/actions/workflows/tests.yaml)
[![Build Status](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fmarcosschroh%2Fdataclasses-avroschema%2Fbadge%3Fref%3Dmaster&style=flat)](https://actions-badge.atrox.dev/marcosschroh/dataclasses-avroschema/goto?ref=master)
[![GitHub license](https://img.shields.io/github/license/marcosschroh/dataclasses-avroschema.svg)](https://github.com/marcosschroh/dataclasses-avroschema/blob/master/LICENSE)
[![codecov](https://codecov.io/gh/marcosschroh/dataclasses-avroschema/branch/master/graph/badge.svg)](https://codecov.io/gh/marcosschroh/dataclasses-avroschema)
![python version](https://img.shields.io/badge/python-3.7%2B-yellowgreen)
Expand All @@ -14,21 +13,22 @@ Generate [Avro](https://avro.apache.org/docs/1.8.2/spec.html) Schemas from a Pyt

## Installation

```bash
pip install dataclasses-avroschema
```
with `pip` or `poetry`:

or with `pydantic` funcionalities
`pip install dataclasses-avroschema` or `poetry install`

```bash
pip install 'dataclasses-avroschema[pydantic]'
```
### Extras

or with command line [dc-avro](https://marcosschroh.github.io/dc-avro/)
[pydantic](https://docs.pydantic.dev/): `pip install 'dataclasses-avroschema[pydantic]'` or `poetry install --extras "pydantic"`
[faust-streaming](https://github.com/faust-streaming/faust): `pip install 'dataclasses-avroschema[faust]'` or `poetry install --extras "faust"`

```bash
pip install 'dataclasses-avroschema[cli]'
```
*Note*: You can install all extra dependencies with `pip install dataclasses-avroschema ".[extras]"` or `poetry install --extras "pydantic faust"`

### CLI

To add `avro schemas cli` install [dc-avro](https://marcosschroh.github.io/dc-avro/)

`pip install 'dataclasses-avroschema[cli]'` or `poetry install --with cli`

## Documentation

Expand Down Expand Up @@ -262,6 +262,24 @@ UserAdvance.avro_schema()
]
}'

# Json schema
UserAdvance.json_schema()

{
"title": "UserAdvance",
"description": "UserAdvance(*, name: str, age: int, pets: List[str] = None, ...",
"type": "object",
"properties": {
"name": {"title": "Name", "type": "string"},
"age": {"title": "Age", "type": "integer"},
"pets": {"title": "Pets", "type": "array", "items": {"type": "string"}},
"accounts": {"title": "Accounts", "type": "object", "additionalProperties": {"type": "integer"}},
"has_car": {"title": "Has Car", "default": false, "type": "boolean"},
"favorite_colors": {"default": "BLUE", "allOf": [{"$ref": "#/definitions/FavoriteColor"}]},
"country": {"title": "Country", "default": "Argentina", "type": "string"},
"address": {"title": "Address", "type": "string"}}, "required": ["name", "age"], "definitions": {"FavoriteColor": {"title": "FavoriteColor", "description": "An enumeration.", "enum": ["BLUE", "YELLOW", "GREEN"], "type": "string"}}
}

user = UserAdvance(name="bond", age=50)

# pydantic
Expand Down
12 changes: 3 additions & 9 deletions dataclasses_avroschema/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import uuid
from collections import OrderedDict

import inflect
from faker import Faker
from inflector import Inflector
from pytz import utc
from typing_extensions import get_args, get_origin

Expand All @@ -32,7 +32,7 @@
logger = logging.getLogger(__name__)

fake = Faker()
p = inflect.engine()
p = Inflector()


@dataclasses.dataclass # type: ignore
Expand Down Expand Up @@ -66,13 +66,7 @@ def _get_self_reference_type(a_type: typing.Any) -> str:

@staticmethod
def get_singular_name(name: str) -> str:
singular = p.singular_noun(name)

# do the check because of mypy.
# p.singular_noun returns Union[str, bool]
if isinstance(singular, str):
return singular
return name
return p.singularize(name)

def get_metadata(self) -> typing.List[typing.Tuple[str, str]]:
meta_data_for_template = []
Expand Down
23 changes: 12 additions & 11 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,22 @@ Generate [Avro](https://avro.apache.org/docs/1.8.2/spec.html) Schemas from a Pyt

## Installation

```bash
pip install dataclasses-avroschema
```
with `pip` or `poetry`:

or with `pydantic` funcionalities
`pip install dataclasses-avroschema` or `poetry install`

```bash
pip install 'dataclasses-avroschema[pydantic]'
```
### Extras

or with command line [dc-avro](https://marcosschroh.github.io/dc-avro/)
[pydantic](https://docs.pydantic.dev/): `pip install 'dataclasses-avroschema[pydantic]'` or `poetry install --extras "pydantic"`
[faust-streaming](https://github.com/faust-streaming/faust): `pip install 'dataclasses-avroschema[faust]'` or `poetry install --extras "faust"`

```bash
pip install 'dataclasses-avroschema[cli]'
```
*Note*: You can install all extra dependencies with `pip install dataclasses-avroschema ".[extras]"` or `poetry install --extras "pydantic faust"`

### CLI

To add `avro schemas cli` install [dc-avro](https://marcosschroh.github.io/dc-avro/)

`pip install 'dataclasses-avroschema[cli]'` or `poetry install --with cli`

## Usage

Expand Down
Loading

0 comments on commit e821fa3

Please sign in to comment.