Skip to content

Commit

Permalink
Merge branch 'release/4.0.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
s3rius committed Feb 5, 2023
2 parents 9e585d8 + 5c2b126 commit 5fad73e
Show file tree
Hide file tree
Showing 8 changed files with 340 additions and 300 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,27 @@ readme = "README.md"

[tool.poetry.dependencies]
python = "^3.9"
fastapi = "^0.85.0"
uvicorn = { version = "^0.18.3", extras = ["standard"] }
pydantic = {version = "^1.10.2", extras = ["dotenv"]}
yarl = "^1.8.1"
ujson = "^5.5.0"
fastapi = "^0.89.1"
uvicorn = { version = "^0.20.0", extras = ["standard"] }
pydantic = {version = "^1.10.4", extras = ["dotenv"]}
yarl = "^1.8.2"
ujson = "^5.7.0"
{%- if cookiecutter.orm == "piccolo" %}
{%- if cookiecutter.db_info.name == "postgresql" %}
piccolo = {version = "^0.91.0", extras = ["postgres"]}
piccolo = {version = "^0.105.0", extras = ["postgres"]}
{%- elif cookiecutter.db_info.name == "sqlite" %}
piccolo = {version = "^0.91.0", extras = ["sqlite"]}
piccolo = {version = "^0.105.0", extras = ["sqlite"]}
{%- endif %}
{%- endif %}
{%- if cookiecutter.orm == "sqlalchemy" %}
SQLAlchemy = {version = "^1.4.41", extras = ["mypy", "asyncio"]}
SQLAlchemy = {version = "^2.0.0", extras = ["asyncio"]}
{%- if cookiecutter.enable_migrations == "True" %}
alembic = "^1.8.1"
alembic = "^1.9.2"
{%- endif %}
{%- if cookiecutter.db_info.name == "postgresql" %}
asyncpg = {version = "^0.26.0", extras = ["sa"]}
asyncpg = {version = "^0.27.0", extras = ["sa"]}
{%- elif cookiecutter.db_info.name == "sqlite" %}
aiosqlite = "^0.17.0"
aiosqlite = "^0.18.0"
{%- elif cookiecutter.db_info.name == "mysql" %}
aiomysql = "^0.1.1"
mysqlclient = "^2.1.1"
Expand All @@ -44,52 +44,52 @@ tortoise-orm = "^0.19.2"
aerich = "^0.7.1"
{%- endif %}
{%- if cookiecutter.db_info.name == "postgresql" %}
asyncpg = "^0.26.0"
asyncpg = "^0.27.0"
{%- elif cookiecutter.db_info.name == "sqlite" %}
aiosqlite = "^0.17.0"
aiosqlite = "<0.18.0"
{%- elif cookiecutter.db_info.name == "mysql" %}
aiomysql = "^0.1.1"
mysqlclient = "^2.1.1"
cryptography = "^38.0.1"
cryptography = "^39.0.0"
{%- endif %}
{%- endif %}
{%- if cookiecutter.orm == "ormar" %}
ormar = "^0.11.3"
ormar = "^0.12.0"
{%- if cookiecutter.enable_migrations == "True" %}
alembic = "^1.8.1"
alembic = "^1.9.2"
{%- endif %}
{%- if cookiecutter.db_info.name == "postgresql" %}
asyncpg = "^0.26.0"
psycopg2-binary = "^2.9.3"
asyncpg = "^0.27.0"
psycopg2-binary = "^2.9.5"
{%- elif cookiecutter.db_info.name == "sqlite" %}
aiosqlite = "^0.17.0"
aiosqlite = "^0.18.0"
{%- elif cookiecutter.db_info.name == "mysql" %}
aiomysql = "^0.1.1"
mysqlclient = "^2.1.1"
{%- endif %}
{%- endif %}
{%- if cookiecutter.enable_redis == "True" %}
redis = {version = "^4.3.4", extras = ["hiredis"]}
redis = {version = "^4.4.2", extras = ["hiredis"]}
{%- endif %}
{%- if cookiecutter.self_hosted_swagger == 'True' %}
aiofiles = "^22.1.0"
{%- endif %}
{%- if cookiecutter.orm == "psycopg" %}
psycopg = { version = "^3.1.2", extras = ["binary", "pool"] }
psycopg = { version = "^3.1.8", extras = ["binary", "pool"] }
{%- endif %}
httptools = "^0.5.0"
{%- if cookiecutter.api_type == "graphql" %}
strawberry-graphql = { version = "^0.133.2", extras = ["fastapi"] }
strawberry-graphql = { version = "^0.155.2", extras = ["fastapi"] }
{%- endif %}
{%- if cookiecutter.enable_rmq == "True" %}
aio-pika = "^8.2.3"
aio-pika = "^8.3.0"
{%- endif %}
{%- if cookiecutter.prometheus_enabled == "True" %}
prometheus-client = "^0.14.1"
prometheus-client = "^0.16.0"
prometheus-fastapi-instrumentator = "5.9.1"
{%- endif %}
{%- if cookiecutter.sentry_enabled == "True" %}
sentry-sdk = "^1.9.9"
sentry-sdk = "^1.14.0"
{%- endif %}
{%- if cookiecutter.otlp_enabled == "True" %}
opentelemetry-api = "^1.15.0"
Expand Down Expand Up @@ -117,32 +117,29 @@ opentelemetry-instrumentation-aio-pika = "^0.36b0"
loguru = "^0.6.0"
{%- endif %}
{%- if cookiecutter.enable_kafka == "True" %}
aiokafka = "^0.7.2"
aiokafka = "^0.8.0"
{%- endif %}

[tool.poetry.dev-dependencies]
pytest = "^7.1.3"
pytest = "^7.2.1"
flake8 = "~4.0.1"
mypy = "^0.981"
isort = "^5.10.1"
pre-commit = "^2.20.0"
mypy = "^0.991"
isort = "^5.11.4"
pre-commit = "^3.0.1"
wemake-python-styleguide = "^0.17.0"
black = "^22.8.0"
black = "^22.12.0"
autoflake = "^1.6.1"
{%- if cookiecutter.orm == "sqlalchemy" %}
SQLAlchemy = {version = "^1.4.41", extras = ["mypy"]}
{%- endif %}
pytest-cov = "^4.0.0"
anyio = "^3.6.1"
pytest-env = "^0.6.2"
anyio = "^3.6.2"
pytest-env = "^0.8.1"
{%- if cookiecutter.enable_redis == "True" %}
fakeredis = "^2.2.0"
fakeredis = "^2.5.0"
{%- endif %}
{%- if cookiecutter.orm == "tortoise" %}
asynctest = "^0.13.0"
nest-asyncio = "^1.5.6"
{%- endif %}
httpx = "^0.23.0"
httpx = "^0.23.3"

[tool.isort]
profile = "black"
Expand All @@ -161,9 +158,6 @@ allow_untyped_decorators = true
warn_unused_ignores = false
warn_return_any = false
namespace_packages = true
{%- if cookiecutter.orm == "sqlalchemy" %}
plugins = ["sqlalchemy.ext.mypy.plugin"]
{%- endif %}

{%- if cookiecutter.enable_redis == "True" %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@


{%- if cookiecutter.orm == "sqlalchemy" %}
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession, AsyncEngine, AsyncConnection
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession, AsyncEngine, AsyncConnection, async_sessionmaker
from {{cookiecutter.project_name}}.db.dependencies import get_db_session
from {{cookiecutter.project_name}}.db.utils import create_database, drop_database
{%- elif cookiecutter.orm == "tortoise" %}
Expand Down Expand Up @@ -114,8 +113,9 @@ async def dbsession(
connection = await _engine.connect()
trans = await connection.begin()

session_maker = sessionmaker(
connection, expire_on_commit=False, class_=AsyncSession,
session_maker = async_sessionmaker(
connection,
expire_on_commit=False,
)
session = session_maker()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
from typing import Any, Tuple

from sqlalchemy import Table
from sqlalchemy.orm import as_declarative
from sqlalchemy.orm import DeclarativeBase

from {{cookiecutter.project_name}}.db.meta import meta


@as_declarative(metadata=meta)
class Base:
"""
Base for all models.
class Base(DeclarativeBase):
"""Base for all models."""

It has some type definitions to
enhance autocompletion.
"""
metadata = meta

__tablename__: str
__table__: Table
__table_args__: Tuple[Any, ...]
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async def get_all_dummies(self, limit: int, offset: int) -> List[DummyModel]:
select(DummyModel).limit(limit).offset(offset),
)

return raw_dummies.scalars().fetchall()
return list(raw_dummies.scalars().fetchall())

async def filter(
self,
Expand All @@ -49,4 +49,4 @@ async def filter(
if name:
query = query.where(DummyModel.name == name)
rows = await self.session.execute(query)
return rows.scalars().fetchall()
return list(rows.scalars().fetchall())
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from sqlalchemy.sql.schema import Column
from sqlalchemy.sql.sqltypes import Integer, String
from sqlalchemy.orm import Mapped, mapped_column
from sqlalchemy.sql.sqltypes import String

from {{cookiecutter.project_name}}.db.base import Base

Expand All @@ -9,5 +9,5 @@ class DummyModel(Base):

__tablename__ = "dummy_model"

id = Column(Integer(), primary_key=True, autoincrement=True)
name = Column(String(length=200)) # noqa: WPS432
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
name: Mapped[str] = mapped_column(String(length=200)) # noqa: WPS432
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ async def _setup_db(app: FastAPI) -> None:
{%- if cookiecutter.orm == "sqlalchemy" %}
from asyncio import current_task
from sqlalchemy.ext.asyncio import (
AsyncSession,
async_scoped_session,
create_async_engine,
async_sessionmaker,
)
from sqlalchemy.orm import sessionmaker

Expand All @@ -103,10 +103,9 @@ def _setup_db(app: FastAPI) -> None: # pragma: no cover
"""
engine = create_async_engine(str(settings.db_url), echo=settings.db_echo)
session_factory = async_scoped_session(
sessionmaker(
async_sessionmaker(
engine,
expire_on_commit=False,
class_=AsyncSession,
),
scopefunc=current_task,
)
Expand Down
Loading

0 comments on commit 5fad73e

Please sign in to comment.