Skip to content
This repository has been archived by the owner on Mar 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #266 from quantmind/master
Browse files Browse the repository at this point in the history
2.3.0
  • Loading branch information
lsbardel committed Apr 24, 2021
2 parents 40e10bb + 01aca3d commit 101d195
Show file tree
Hide file tree
Showing 39 changed files with 339 additions and 411 deletions.
2 changes: 1 addition & 1 deletion .coveragerc
@@ -1,9 +1,9 @@
[run]
source = openapi
concurrency=greenlet
data_file = build/.coverage
omit =
openapi/db/openapi
openapi/_py36.py

[html]
directory = build/coverage/html
Expand Down
2 changes: 1 addition & 1 deletion .vscode/launch.json
Expand Up @@ -13,7 +13,7 @@
"RedirectOutput"
],
"args": [
"tests/ws"
"tests/core/test_db.py::test_db_pool"
]
}
]
Expand Down
13 changes: 6 additions & 7 deletions Makefile
Expand Up @@ -28,9 +28,7 @@ install: ## install packages in virtualenv


lint: ## run linters
isort .
./dev/run-black.sh
flake8
@./dev/lint-code


mypy: ## run mypy
Expand All @@ -49,10 +47,8 @@ test: ## test with coverage
@pytest -v -x --cov --cov-report xml --cov-report html


test-lint: ## run linters
flake8
isort . --check
./dev/run-black.sh --check
test-lint: ## run linters checks
@./dev/lint-code --check


test-docs: ## run docs in CI
Expand All @@ -66,12 +62,15 @@ test-version: ## validate version with pypi
bundle3.7: ## build python 3.7 bundle
@python setup.py bdist_wheel --python-tag py37


bundle3.8: ## build python 3.8 bundle
@python setup.py bdist_wheel --python-tag py38


bundle3.9: ## build python 3.9 bundle
@python setup.py sdist bdist_wheel --python-tag py39


release-github: ## new tag in github
@agilekit git release --yes

Expand Down
6 changes: 6 additions & 0 deletions dev/lint-code
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
set -e

isort . $1
black . --exclude "build|dev|docs|venv" $1
flake8
2 changes: 0 additions & 2 deletions dev/run-black.sh

This file was deleted.

1 change: 1 addition & 0 deletions docs/env.rst
Expand Up @@ -11,6 +11,7 @@ Several environment variables can be configured at application level
* **ERROR_500_MESSSAGE** (Internal Server Error), message displayed when things go wrong
* **DBPOOL_MIN_SIZE** (10), minimum number of connection in postgres connection pool
* **DBPOOL_MAX_SIZE** (10), maximum number of connections in postgres connection pool
* **DBECHO**, if set to `true` or `yes` it will use `echo=True` when setting up sqlalchemy engine
* **MICRO_SERVICE_PORT** (8080), default port when running the `serve` command
* **MICRO_SERVICE_HOST** (0.0.0.0), default host when running the `serve` command
* **MAX_PAGINATION_LIMIT** (100), maximum number of objects displayed at once
Expand Down
11 changes: 0 additions & 11 deletions mypi.ini

This file was deleted.

12 changes: 12 additions & 0 deletions mypy.ini
@@ -0,0 +1,12 @@
[mypy]
warn_return_any = False
warn_unused_configs = False

# Just for the time being
ignore_missing_imports = True

# This needs to be on for the time being. Otherwise
# just get a hellscape of errors.
follow_imports = skip

files = openapi
2 changes: 1 addition & 1 deletion openapi/__init__.py
@@ -1,3 +1,3 @@
"""Minimal OpenAPI asynchronous server application"""

__version__ = "2.2.1"
__version__ = "2.3.0"
Empty file added openapi/data/__init__.py
Empty file.
6 changes: 4 additions & 2 deletions openapi/data/dump.py
@@ -1,5 +1,7 @@
from dataclasses import asdict, fields
from typing import Any, Dict, List, Optional, cast
from typing import Any, Dict, List, Optional, Union, cast

from openapi.types import Record

from ..utils import TypingInfo, iter_items
from .fields import DUMP
Expand Down Expand Up @@ -29,7 +31,7 @@ def dump(schema: Any, data: Any) -> Any:
return data


def dump_dataclass(schema: type, data: Optional[Dict] = None) -> Dict:
def dump_dataclass(schema: type, data: Optional[Union[Dict, Record]] = None) -> Dict:
"""Dump a dictionary of data with a given dataclass dump functions
If the data is not given, the schema object is assumed to be
an instance of a dataclass.
Expand Down
12 changes: 6 additions & 6 deletions openapi/data/fields.py
Expand Up @@ -54,7 +54,7 @@ def data_field(
items: Optional[Field] = None,
post_process: Callable[[Any], Any] = None,
ops: Tuple = (),
meta: Optional[Dict[str, any]] = None,
meta: Optional[Dict[str, Any]] = None,
**kwargs,
) -> Field:
"""Extend a dataclass field with the following metadata
Expand Down Expand Up @@ -97,7 +97,7 @@ def data_field(
return f


def str_field(min_length: int = 0, max_length: Optional[int] = None, **kw) -> Field:
def str_field(min_length: int = 0, max_length: int = 0, **kw) -> Field:
"""A specialized :func:`.data_field` for strings
:param min_length: minim length of string
Expand All @@ -122,8 +122,8 @@ def uuid_field(format: str = "uuid", **kw) -> Field:


def number_field(
min_value: Optional[float] = None,
max_value: Optional[float] = None,
min_value: Optional[Number] = None,
max_value: Optional[Number] = None,
precision: Optional[int] = None,
**kw,
) -> Field:
Expand All @@ -138,8 +138,8 @@ def number_field(


def integer_field(
min_value: Optional[int] = None,
max_value: Optional[int] = None,
min_value: Optional[Number] = None,
max_value: Optional[Number] = None,
**kw,
) -> Field:
"""A specialized :func:`.data_field` for integer values
Expand Down
5 changes: 3 additions & 2 deletions openapi/data/validate.py
Expand Up @@ -4,6 +4,7 @@
from multidict import MultiDict

from openapi import json
from openapi.types import Record

from ..utils import TypingInfo
from .fields import (
Expand Down Expand Up @@ -198,7 +199,7 @@ def validate_dict(

def validate_dataclass(
schema: type,
data: Union[Dict[str, Any], MultiDict],
data: Union[Dict[str, Any], MultiDict, Record],
*,
strict: bool = True,
multiple: bool = False,
Expand All @@ -208,7 +209,7 @@ def validate_dataclass(
errors: Dict = {}
cleaned: Dict = {}
try:
data = MultiDict(data)
data = MultiDict(dict(data) if isinstance(data, Record) else data)
except TypeError:
raise ValidationErrors(OBJECT_EXPECTED)
for field in fields(schema):
Expand Down
5 changes: 2 additions & 3 deletions openapi/db/__init__.py
@@ -1,16 +1,15 @@
import os
import typing as t
from typing import Optional

from aiohttp.web import Application

from .compile import compile_query
from .container import Database
from .dbmodel import CrudDB

__all__ = ["compile_query", "Database", "CrudDB", "get_db"]


def get_db(app: Application, store_url: str = None) -> t.Optional[CrudDB]:
def get_db(app: Application, store_url: Optional[str] = None) -> Optional[CrudDB]:
"""Create an Open API db handler
This function
Expand Down
23 changes: 10 additions & 13 deletions openapi/db/commands.py
@@ -1,5 +1,3 @@
from copy import copy

import click
from sqlalchemy_utils import create_database, database_exists, drop_database

Expand Down Expand Up @@ -33,7 +31,7 @@ def init(ctx):
"--branch-label", help="Specify a branch label to apply to the new revision"
)
@click.pass_context
def migrate(ctx, message, branch_label):
def migrate(ctx, message: str, branch_label: str):
"""Autogenerate a new revision file
alias for 'revision --autogenerate'
Expand All @@ -58,7 +56,7 @@ def migrate(ctx, message, branch_label):
),
)
@click.pass_context
def revision(ctx, message, branch_label, autogenerate):
def revision(ctx, message: str, branch_label: str, autogenerate: bool):
"""Autogenerate a new revision file"""
return migration(ctx).revision(
message, autogenerate=autogenerate, branch_label=branch_label
Expand All @@ -74,7 +72,7 @@ def revision(ctx, message, branch_label, autogenerate):
help="Drop tables before applying migrations",
)
@click.pass_context
def upgrade(ctx, revision, drop_tables):
def upgrade(ctx, revision: str, drop_tables: bool):
"""Upgrade to a later version"""
if drop_tables:
_drop_tables(ctx)
Expand All @@ -85,7 +83,7 @@ def upgrade(ctx, revision, drop_tables):
@db.command()
@click.option("--revision", help="Revision id", required=True)
@click.pass_context
def downgrade(ctx, revision):
def downgrade(ctx, revision: str):
"""Downgrade to a previous version"""
migration(ctx).downgrade(revision)
click.echo(f"downgraded successfully to {revision}")
Expand All @@ -94,7 +92,7 @@ def downgrade(ctx, revision):
@db.command()
@click.option("--revision", default="heads")
@click.pass_context
def show(ctx, revision):
def show(ctx, revision: str):
"""Show revision ID and creation date"""
click.echo(migration(ctx).show(revision))

Expand All @@ -109,7 +107,7 @@ def history(ctx):
@db.command()
@click.option("--verbose/--quiet", default=False)
@click.pass_context
def current(ctx, verbose):
def current(ctx, verbose: bool):
"""Show revision ID and creation date"""
click.echo(migration(ctx).current(verbose))

Expand All @@ -120,11 +118,10 @@ def current(ctx, verbose):
"--force", default=False, is_flag=True, help="Force removal of an existing database"
)
@click.pass_context
def create(ctx, dbname, force):
def create(ctx, dbname: str, force: str):
"""Creates a new database"""
engine = get_db(ctx).engine
url = copy(engine.url)
url.database = dbname
engine = get_db(ctx).sync_engine
url = engine.url.set(database=dbname)
store = str(url)
if database_exists(store):
if force:
Expand All @@ -147,7 +144,7 @@ def tables(ctx, db):
"""List all tables managed by the app"""
d = get_db(ctx)
if db:
tables = d.engine.table_names()
tables = d.sync_engine.table_names()
else:
tables = d.metadata.tables
for name in sorted(tables):
Expand Down
71 changes: 0 additions & 71 deletions openapi/db/compile.py

This file was deleted.

0 comments on commit 101d195

Please sign in to comment.