lint code + format

This commit is contained in:
Jakub Miazek 2023-01-17 21:00:45 +01:00
parent efadedaab0
commit f0ae471c39
13 changed files with 239 additions and 149 deletions

View File

@ -14,10 +14,12 @@ target_metadata = app_base.metadata
def do_run_migrations(connection): def do_run_migrations(connection):
context.configure(connection=connection, context.configure(
target_metadata=target_metadata, connection=connection,
include_schemas=True, target_metadata=target_metadata,
version_table_schema=target_metadata.schema) include_schemas=True,
version_table_schema=target_metadata.schema,
)
with context.begin_transaction(): with context.begin_transaction():
context.run_migrations() context.run_migrations()

View File

@ -10,7 +10,7 @@ import sqlalchemy as sa
from sqlalchemy.dialects import postgresql from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '957232a5b7ee' revision = "957232a5b7ee"
down_revision = None down_revision = None
branch_labels = None branch_labels = None
depends_on = None depends_on = None
@ -18,104 +18,143 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.create_table('nonsense', op.create_table(
sa.Column('id', postgresql.UUID(as_uuid=True), autoincrement=True, nullable=True), "nonsense",
sa.Column('name', sa.String(), nullable=False), sa.Column(
sa.Column('description', sa.String(), nullable=False), "id", postgresql.UUID(as_uuid=True), autoincrement=True, nullable=True
sa.PrimaryKeyConstraint('name'), ),
sa.UniqueConstraint('id'), sa.Column("name", sa.String(), nullable=False),
sa.UniqueConstraint('name'), sa.Column("description", sa.String(), nullable=False),
schema='happy_hog' sa.PrimaryKeyConstraint("name"),
sa.UniqueConstraint("id"),
sa.UniqueConstraint("name"),
schema="happy_hog",
) )
op.create_table('stuff', op.create_table(
sa.Column('id', postgresql.UUID(as_uuid=True), autoincrement=True, nullable=True), "stuff",
sa.Column('name', sa.String(), nullable=False), sa.Column(
sa.Column('description', sa.String(), nullable=False), "id", postgresql.UUID(as_uuid=True), autoincrement=True, nullable=True
sa.PrimaryKeyConstraint('name'), ),
sa.UniqueConstraint('id'), sa.Column("name", sa.String(), nullable=False),
sa.UniqueConstraint('name'), sa.Column("description", sa.String(), nullable=False),
schema='happy_hog' sa.PrimaryKeyConstraint("name"),
sa.UniqueConstraint("id"),
sa.UniqueConstraint("name"),
schema="happy_hog",
) )
op.create_table('character', op.create_table(
sa.Column('id', sa.String(length=32), nullable=False), "character",
sa.Column('name', sa.String(length=64), nullable=False), sa.Column("id", sa.String(length=32), nullable=False),
sa.Column('speech_count', sa.Integer(), nullable=False), sa.Column("name", sa.String(length=64), nullable=False),
sa.Column('abbrev', sa.String(length=32), nullable=True), sa.Column("speech_count", sa.Integer(), nullable=False),
sa.Column('description', sa.String(length=2056), nullable=True), sa.Column("abbrev", sa.String(length=32), nullable=True),
sa.PrimaryKeyConstraint('id', name='character_pkey'), sa.Column("description", sa.String(length=2056), nullable=True),
schema='shakespeare' sa.PrimaryKeyConstraint("id", name="character_pkey"),
schema="shakespeare",
) )
op.create_table('wordform', op.create_table(
sa.Column('id', sa.Integer(), nullable=False), "wordform",
sa.Column('plain_text', sa.String(length=64), nullable=False), sa.Column("id", sa.Integer(), nullable=False),
sa.Column('phonetic_text', sa.String(length=64), nullable=False), sa.Column("plain_text", sa.String(length=64), nullable=False),
sa.Column('stem_text', sa.String(length=64), nullable=False), sa.Column("phonetic_text", sa.String(length=64), nullable=False),
sa.Column('occurences', sa.Integer(), nullable=False), sa.Column("stem_text", sa.String(length=64), nullable=False),
sa.PrimaryKeyConstraint('id', name='wordform_pkey'), sa.Column("occurences", sa.Integer(), nullable=False),
schema='shakespeare' sa.PrimaryKeyConstraint("id", name="wordform_pkey"),
schema="shakespeare",
) )
op.create_table('work', op.create_table(
sa.Column('id', sa.String(length=32), nullable=False), "work",
sa.Column('title', sa.String(length=32), nullable=False), sa.Column("id", sa.String(length=32), nullable=False),
sa.Column('long_title', sa.String(length=64), nullable=False), sa.Column("title", sa.String(length=32), nullable=False),
sa.Column('year', sa.Integer(), nullable=False), sa.Column("long_title", sa.String(length=64), nullable=False),
sa.Column('genre_type', sa.String(length=1), nullable=False), sa.Column("year", sa.Integer(), nullable=False),
sa.Column('source', sa.String(length=16), nullable=False), sa.Column("genre_type", sa.String(length=1), nullable=False),
sa.Column('total_words', sa.Integer(), nullable=False), sa.Column("source", sa.String(length=16), nullable=False),
sa.Column('total_paragraphs', sa.Integer(), nullable=False), sa.Column("total_words", sa.Integer(), nullable=False),
sa.Column('notes', sa.Text(), nullable=True), sa.Column("total_paragraphs", sa.Integer(), nullable=False),
sa.PrimaryKeyConstraint('id', name='work_pkey'), sa.Column("notes", sa.Text(), nullable=True),
schema='shakespeare' sa.PrimaryKeyConstraint("id", name="work_pkey"),
schema="shakespeare",
) )
op.create_table('chapter', op.create_table(
sa.Column('id', sa.Integer(), nullable=False), "chapter",
sa.Column('work_id', sa.String(length=32), nullable=False), sa.Column("id", sa.Integer(), nullable=False),
sa.Column('section_number', sa.Integer(), nullable=False), sa.Column("work_id", sa.String(length=32), nullable=False),
sa.Column('chapter_number', sa.Integer(), nullable=False), sa.Column("section_number", sa.Integer(), nullable=False),
sa.Column('description', sa.String(length=256), nullable=False), sa.Column("chapter_number", sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['work_id'], ['shakespeare.work.id'], name='chapter_work_id_fkey'), sa.Column("description", sa.String(length=256), nullable=False),
sa.PrimaryKeyConstraint('id', name='chapter_pkey'), sa.ForeignKeyConstraint(
sa.UniqueConstraint('work_id', 'section_number', 'chapter_number', name='chapter_work_id_section_number_chapter_number_key'), ["work_id"], ["shakespeare.work.id"], name="chapter_work_id_fkey"
schema='shakespeare' ),
sa.PrimaryKeyConstraint("id", name="chapter_pkey"),
sa.UniqueConstraint(
"work_id",
"section_number",
"chapter_number",
name="chapter_work_id_section_number_chapter_number_key",
),
schema="shakespeare",
) )
op.create_table('character_work', op.create_table(
sa.Column('character_id', sa.String(length=32), nullable=False), "character_work",
sa.Column('work_id', sa.String(length=32), nullable=False), sa.Column("character_id", sa.String(length=32), nullable=False),
sa.ForeignKeyConstraint(['character_id'], ['shakespeare.character.id'], name='character_work_character_id_fkey'), sa.Column("work_id", sa.String(length=32), nullable=False),
sa.ForeignKeyConstraint(['work_id'], ['shakespeare.work.id'], name='character_work_work_id_fkey'), sa.ForeignKeyConstraint(
sa.PrimaryKeyConstraint('character_id', 'work_id', name='character_work_pkey'), ["character_id"],
schema='shakespeare' ["shakespeare.character.id"],
name="character_work_character_id_fkey",
),
sa.ForeignKeyConstraint(
["work_id"], ["shakespeare.work.id"], name="character_work_work_id_fkey"
),
sa.PrimaryKeyConstraint("character_id", "work_id", name="character_work_pkey"),
schema="shakespeare",
) )
op.create_table('paragraph', op.create_table(
sa.Column('id', sa.Integer(), nullable=False), "paragraph",
sa.Column('work_id', sa.String(length=32), nullable=False), sa.Column("id", sa.Integer(), nullable=False),
sa.Column('paragraph_num', sa.Integer(), nullable=False), sa.Column("work_id", sa.String(length=32), nullable=False),
sa.Column('character_id', sa.String(length=32), nullable=False), sa.Column("paragraph_num", sa.Integer(), nullable=False),
sa.Column('plain_text', sa.Text(), nullable=False), sa.Column("character_id", sa.String(length=32), nullable=False),
sa.Column('phonetic_text', sa.Text(), nullable=False), sa.Column("plain_text", sa.Text(), nullable=False),
sa.Column('stem_text', sa.Text(), nullable=False), sa.Column("phonetic_text", sa.Text(), nullable=False),
sa.Column('paragraph_type', sa.String(length=1), nullable=False), sa.Column("stem_text", sa.Text(), nullable=False),
sa.Column('section_number', sa.Integer(), nullable=False), sa.Column("paragraph_type", sa.String(length=1), nullable=False),
sa.Column('chapter_number', sa.Integer(), nullable=False), sa.Column("section_number", sa.Integer(), nullable=False),
sa.Column('char_count', sa.Integer(), nullable=False), sa.Column("chapter_number", sa.Integer(), nullable=False),
sa.Column('word_count', sa.Integer(), nullable=False), sa.Column("char_count", sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['character_id'], ['shakespeare.character.id'], name='paragraph_character_id_fkey'), sa.Column("word_count", sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['work_id', 'section_number', 'chapter_number'], ['shakespeare.chapter.work_id', 'shakespeare.chapter.section_number', 'shakespeare.chapter.chapter_number'], name='paragraph_chapter_fkey'), sa.ForeignKeyConstraint(
sa.ForeignKeyConstraint(['work_id'], ['shakespeare.work.id'], name='paragraph_work_id_fkey'), ["character_id"],
sa.PrimaryKeyConstraint('id', name='paragraph_pkey'), ["shakespeare.character.id"],
schema='shakespeare' name="paragraph_character_id_fkey",
),
sa.ForeignKeyConstraint(
["work_id", "section_number", "chapter_number"],
[
"shakespeare.chapter.work_id",
"shakespeare.chapter.section_number",
"shakespeare.chapter.chapter_number",
],
name="paragraph_chapter_fkey",
),
sa.ForeignKeyConstraint(
["work_id"], ["shakespeare.work.id"], name="paragraph_work_id_fkey"
),
sa.PrimaryKeyConstraint("id", name="paragraph_pkey"),
schema="shakespeare",
) )
# ### end Alembic commands ### # ### end Alembic commands ###
def downgrade(): def downgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.drop_table('paragraph', schema='shakespeare') op.drop_table("paragraph", schema="shakespeare")
op.drop_table('character_work', schema='shakespeare') op.drop_table("character_work", schema="shakespeare")
op.drop_table('chapter', schema='shakespeare') op.drop_table("chapter", schema="shakespeare")
op.drop_table('work', schema='shakespeare') op.drop_table("work", schema="shakespeare")
op.drop_table('wordform', schema='shakespeare') op.drop_table("wordform", schema="shakespeare")
op.drop_table('character', schema='shakespeare') op.drop_table("character", schema="shakespeare")
op.drop_table('stuff', schema='happy_hog') op.drop_table("stuff", schema="happy_hog")
op.drop_table('nonsense', schema='happy_hog') op.drop_table("nonsense", schema="happy_hog")
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -9,7 +9,9 @@ router = APIRouter(prefix="/v1/nonsense")
@router.post("/", status_code=status.HTTP_201_CREATED, response_model=NonsenseResponse) @router.post("/", status_code=status.HTTP_201_CREATED, response_model=NonsenseResponse)
async def create_nonsense(payload: NonsenseSchema, db_session: AsyncSession = Depends(get_db)): async def create_nonsense(
payload: NonsenseSchema, db_session: AsyncSession = Depends(get_db)
):
nonsense = Nonsense(**payload.dict()) nonsense = Nonsense(**payload.dict())
await nonsense.save(db_session) await nonsense.save(db_session)
return nonsense return nonsense

View File

@ -13,21 +13,31 @@ logger = get_logger(__name__)
@router.post("/add_many", status_code=status.HTTP_201_CREATED) @router.post("/add_many", status_code=status.HTTP_201_CREATED)
async def create_multi_stuff(payload: list[StuffSchema], db_session: AsyncSession = Depends(get_db)): async def create_multi_stuff(
payload: list[StuffSchema], db_session: AsyncSession = Depends(get_db)
):
try: try:
stuff_instances = [Stuff(name=stuf.name, description=stuf.description) for stuf in payload] stuff_instances = [
Stuff(name=stuf.name, description=stuf.description) for stuf in payload
]
db_session.add_all(stuff_instances) db_session.add_all(stuff_instances)
await db_session.commit() await db_session.commit()
except SQLAlchemyError as ex: except SQLAlchemyError as ex:
# logger.exception(ex) # logger.exception(ex)
raise HTTPException(status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail=repr(ex)) from ex raise HTTPException(
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail=repr(ex)
) from ex
else: else:
logger.info(f"{len(stuff_instances)} instances of Stuff inserted into database.") logger.info(
f"{len(stuff_instances)} instances of Stuff inserted into database."
)
return True return True
@router.post("", status_code=status.HTTP_201_CREATED, response_model=StuffResponse) @router.post("", status_code=status.HTTP_201_CREATED, response_model=StuffResponse)
async def create_stuff(payload: StuffSchema, db_session: AsyncSession = Depends(get_db)): async def create_stuff(
payload: StuffSchema, db_session: AsyncSession = Depends(get_db)
):
stuff = Stuff(name=payload.name, description=payload.description) stuff = Stuff(name=payload.name, description=payload.description)
await stuff.save(db_session) await stuff.save(db_session)
return stuff return stuff

View File

@ -31,7 +31,9 @@ class Settings(BaseSettings):
pg_pass: str = os.getenv("POSTGRES_PASSWORD", "") pg_pass: str = os.getenv("POSTGRES_PASSWORD", "")
pg_host: str = os.getenv("SQL_HOST", "") pg_host: str = os.getenv("SQL_HOST", "")
pg_database: str = os.getenv("SQL_DB", "") pg_database: str = os.getenv("SQL_DB", "")
asyncpg_url: str = f"postgresql+asyncpg://{pg_user}:{pg_pass}@{pg_host}:5432/{pg_database}" asyncpg_url: str = (
f"postgresql+asyncpg://{pg_user}:{pg_pass}@{pg_host}:5432/{pg_database}"
)
jwt_secret_key: str = os.getenv("SECRET_KEY", "") jwt_secret_key: str = os.getenv("SECRET_KEY", "")
jwt_algorithm: str = os.getenv("ALGORITHM", "") jwt_algorithm: str = os.getenv("ALGORITHM", "")

View File

@ -1,8 +1,6 @@
from collections.abc import AsyncGenerator from collections.abc import AsyncGenerator
from http.client import HTTPException
from fastapi.encoders import jsonable_encoder from fastapi.encoders import jsonable_encoder
from sqlalchemy.exc import SQLAlchemyError
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
from sqlalchemy.orm import sessionmaker from sqlalchemy.orm import sessionmaker
@ -23,7 +21,9 @@ engine = create_async_engine(
# expire_on_commit=False will prevent attributes from being expired # expire_on_commit=False will prevent attributes from being expired
# after commit. # after commit.
AsyncSessionFactory = sessionmaker(engine, autoflush=False, expire_on_commit=False, class_=AsyncSession) AsyncSessionFactory = sessionmaker(
engine, autoflush=False, expire_on_commit=False, class_=AsyncSession
)
# Dependency # Dependency
@ -31,4 +31,3 @@ async def get_db() -> AsyncGenerator:
async with AsyncSessionFactory() as session: async with AsyncSessionFactory() as session:
logger.debug(f"ASYNC Pool: {engine.pool.status()}") logger.debug(f"ASYNC Pool: {engine.pool.status()}")
yield session yield session

View File

@ -37,7 +37,9 @@ class Base:
db_session.add(self) db_session.add(self)
return await db_session.commit() return await db_session.commit()
except SQLAlchemyError as ex: except SQLAlchemyError as ex:
raise HTTPException(status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail=repr(ex)) from ex raise HTTPException(
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail=repr(ex)
) from ex
async def delete(self, db_session: AsyncSession): async def delete(self, db_session: AsyncSession):
""" """
@ -50,7 +52,9 @@ class Base:
await db_session.commit() await db_session.commit()
return True return True
except SQLAlchemyError as ex: except SQLAlchemyError as ex:
raise HTTPException(status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail=repr(ex)) from ex raise HTTPException(
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail=repr(ex)
) from ex
async def update(self, db_session: AsyncSession, **kwargs): async def update(self, db_session: AsyncSession, **kwargs):
""" """

View File

@ -29,7 +29,9 @@ class Nonsense(Base):
if instance is None: if instance is None:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND, status_code=status.HTTP_404_NOT_FOUND,
detail={"Record not found": f"There is no record for requested name value : {name}"}, detail={
"Record not found": f"There is no record for requested name value : {name}"
},
) )
else: else:
return instance return instance

View File

@ -20,7 +20,10 @@ metadata = Base.metadata
class Character(Base): class Character(Base):
__tablename__ = "character" __tablename__ = "character"
__table_args__ = (PrimaryKeyConstraint("id", name="character_pkey"), {"schema": "shakespeare"}) __table_args__ = (
PrimaryKeyConstraint("id", name="character_pkey"),
{"schema": "shakespeare"},
)
id = Column(String(32)) id = Column(String(32))
name = Column(String(64), nullable=False) name = Column(String(64), nullable=False)
@ -28,13 +31,18 @@ class Character(Base):
abbrev = Column(String(32)) abbrev = Column(String(32))
description = Column(String(2056)) description = Column(String(2056))
work = relationship("Work", secondary="shakespeare.character_work", back_populates="character") work = relationship(
"Work", secondary="shakespeare.character_work", back_populates="character"
)
paragraph = relationship("Paragraph", back_populates="character") paragraph = relationship("Paragraph", back_populates="character")
class Wordform(Base): class Wordform(Base):
__tablename__ = "wordform" __tablename__ = "wordform"
__table_args__ = (PrimaryKeyConstraint("id", name="wordform_pkey"), {"schema": "shakespeare"}) __table_args__ = (
PrimaryKeyConstraint("id", name="wordform_pkey"),
{"schema": "shakespeare"},
)
id = Column(Integer) id = Column(Integer)
plain_text = Column(String(64), nullable=False) plain_text = Column(String(64), nullable=False)
@ -45,7 +53,10 @@ class Wordform(Base):
class Work(Base): class Work(Base):
__tablename__ = "work" __tablename__ = "work"
__table_args__ = (PrimaryKeyConstraint("id", name="work_pkey"), {"schema": "shakespeare"}) __table_args__ = (
PrimaryKeyConstraint("id", name="work_pkey"),
{"schema": "shakespeare"},
)
id = Column(String(32)) id = Column(String(32))
title = Column(String(32), nullable=False) title = Column(String(32), nullable=False)
@ -57,7 +68,9 @@ class Work(Base):
total_paragraphs = Column(Integer, nullable=False) total_paragraphs = Column(Integer, nullable=False)
notes = Column(Text) notes = Column(Text)
character = relationship("Character", secondary="shakespeare.character_work", back_populates="work") character = relationship(
"Character", secondary="shakespeare.character_work", back_populates="work"
)
chapter = relationship("Chapter", back_populates="work") chapter = relationship("Chapter", back_populates="work")
paragraph = relationship("Paragraph", back_populates="work") paragraph = relationship("Paragraph", back_populates="work")
@ -65,10 +78,15 @@ class Work(Base):
class Chapter(Base): class Chapter(Base):
__tablename__ = "chapter" __tablename__ = "chapter"
__table_args__ = ( __table_args__ = (
ForeignKeyConstraint(["work_id"], ["shakespeare.work.id"], name="chapter_work_id_fkey"), ForeignKeyConstraint(
["work_id"], ["shakespeare.work.id"], name="chapter_work_id_fkey"
),
PrimaryKeyConstraint("id", name="chapter_pkey"), PrimaryKeyConstraint("id", name="chapter_pkey"),
UniqueConstraint( UniqueConstraint(
"work_id", "section_number", "chapter_number", name="chapter_work_id_section_number_chapter_number_key" "work_id",
"section_number",
"chapter_number",
name="chapter_work_id_section_number_chapter_number_key",
), ),
{"schema": "shakespeare"}, {"schema": "shakespeare"},
) )
@ -88,8 +106,14 @@ t_character_work = Table(
metadata, metadata,
Column("character_id", ForeignKey("shakespeare.character.id"), nullable=False), Column("character_id", ForeignKey("shakespeare.character.id"), nullable=False),
Column("work_id", ForeignKey("shakespeare.work.id"), nullable=False), Column("work_id", ForeignKey("shakespeare.work.id"), nullable=False),
ForeignKeyConstraint(["character_id"], ["shakespeare.character.id"], name="character_work_character_id_fkey"), ForeignKeyConstraint(
ForeignKeyConstraint(["work_id"], ["shakespeare.work.id"], name="character_work_work_id_fkey"), ["character_id"],
["shakespeare.character.id"],
name="character_work_character_id_fkey",
),
ForeignKeyConstraint(
["work_id"], ["shakespeare.work.id"], name="character_work_work_id_fkey"
),
PrimaryKeyConstraint("character_id", "work_id", name="character_work_pkey"), PrimaryKeyConstraint("character_id", "work_id", name="character_work_pkey"),
schema="shakespeare", schema="shakespeare",
) )
@ -98,13 +122,23 @@ t_character_work = Table(
class Paragraph(Base): class Paragraph(Base):
__tablename__ = "paragraph" __tablename__ = "paragraph"
__table_args__ = ( __table_args__ = (
ForeignKeyConstraint(["character_id"], ["shakespeare.character.id"], name="paragraph_character_id_fkey"), ForeignKeyConstraint(
["character_id"],
["shakespeare.character.id"],
name="paragraph_character_id_fkey",
),
ForeignKeyConstraint( ForeignKeyConstraint(
["work_id", "section_number", "chapter_number"], ["work_id", "section_number", "chapter_number"],
["shakespeare.chapter.work_id", "shakespeare.chapter.section_number", "shakespeare.chapter.chapter_number"], [
"shakespeare.chapter.work_id",
"shakespeare.chapter.section_number",
"shakespeare.chapter.chapter_number",
],
name="paragraph_chapter_fkey", name="paragraph_chapter_fkey",
), ),
ForeignKeyConstraint(["work_id"], ["shakespeare.work.id"], name="paragraph_work_id_fkey"), ForeignKeyConstraint(
["work_id"], ["shakespeare.work.id"], name="paragraph_work_id_fkey"
),
PrimaryKeyConstraint("id", name="paragraph_pkey"), PrimaryKeyConstraint("id", name="paragraph_pkey"),
{"schema": "shakespeare"}, {"schema": "shakespeare"},
) )
@ -128,7 +162,13 @@ class Paragraph(Base):
@classmethod @classmethod
async def find(cls, db_session: AsyncSession, character: str): async def find(cls, db_session: AsyncSession, character: str):
stmt = select(cls).join(Character).join(Chapter).join(Work).where(Character.name == character) stmt = (
select(cls)
.join(Character)
.join(Chapter)
.join(Work)
.where(Character.name == character)
)
result = await db_session.execute(stmt) result = await db_session.execute(stmt)
instance = result.scalars().all() instance = result.scalars().all()
return instance return instance

View File

@ -10,8 +10,12 @@ console = Console(color_system="256", width=200, style="blue")
@lru_cache @lru_cache
def get_logger(module_name): def get_logger(module_name):
logger = logging.getLogger(module_name) logger = logging.getLogger(module_name)
handler = RichHandler(rich_tracebacks=True, console=console, tracebacks_show_locals=True) handler = RichHandler(
handler.setFormatter(logging.Formatter("[ %(threadName)s:%(funcName)s:%(lineno)d ] - %(message)s")) rich_tracebacks=True, console=console, tracebacks_show_locals=True
)
handler.setFormatter(
logging.Formatter("[ %(threadName)s:%(funcName)s:%(lineno)d ] - %(message)s")
)
logger.addHandler(handler) logger.addHandler(handler)
logger.setLevel(logging.DEBUG) logger.setLevel(logging.DEBUG)
return logger return logger

34
poetry.lock generated
View File

@ -430,14 +430,11 @@ python-versions = "*"
[[package]] [[package]]
name = "packaging" name = "packaging"
version = "21.3" version = "23.0"
description = "Core utilities for Python packages" description = "Core utilities for Python packages"
category = "main" category = "main"
optional = false optional = false
python-versions = ">=3.6" python-versions = ">=3.7"
[package.dependencies]
pyparsing = ">=2.0.2,<3.0.5 || >3.0.5"
[[package]] [[package]]
name = "parso" name = "parso"
@ -558,17 +555,6 @@ python-versions = ">=3.6"
[package.extras] [package.extras]
plugins = ["importlib-metadata"] plugins = ["importlib-metadata"]
[[package]]
name = "pyparsing"
version = "3.0.9"
description = "pyparsing module - Classes and methods to define and execute parsing grammars"
category = "main"
optional = false
python-versions = ">=3.6.8"
[package.extras]
diagrams = ["jinja2", "railroad-diagrams"]
[[package]] [[package]]
name = "pytest" name = "pytest"
version = "7.2.1" version = "7.2.1"
@ -729,7 +715,7 @@ python-versions = ">=3.7"
[[package]] [[package]]
name = "safety" name = "safety"
version = "2.3.5" version = "2.3.4"
description = "Checks installed dependencies for known vulnerabilities and licenses." description = "Checks installed dependencies for known vulnerabilities and licenses."
category = "main" category = "main"
optional = false optional = false
@ -738,7 +724,7 @@ python-versions = "*"
[package.dependencies] [package.dependencies]
Click = ">=8.0.2" Click = ">=8.0.2"
dparse = ">=0.6.2" dparse = ">=0.6.2"
packaging = ">=21.0,<22.0" packaging = ">=21.0"
requests = "*" requests = "*"
"ruamel.yaml" = ">=0.17.21" "ruamel.yaml" = ">=0.17.21"
setuptools = ">=19.3" setuptools = ">=19.3"
@ -1433,8 +1419,8 @@ mypy-extensions = [
{file = "mypy_extensions-0.4.3.tar.gz", hash = "sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8"}, {file = "mypy_extensions-0.4.3.tar.gz", hash = "sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8"},
] ]
packaging = [ packaging = [
{file = "packaging-21.3-py3-none-any.whl", hash = "sha256:ef103e05f519cdc783ae24ea4e2e0f508a9c99b2d4969652eed6a2e1ea5bd522"}, {file = "packaging-23.0-py3-none-any.whl", hash = "sha256:714ac14496c3e68c99c29b00845f7a2b85f3bb6f1078fd9f72fd20f0570002b2"},
{file = "packaging-21.3.tar.gz", hash = "sha256:dd47c42927d89ab911e606518907cc2d3a1f38bbd026385970643f9c5b8ecfeb"}, {file = "packaging-23.0.tar.gz", hash = "sha256:b6ad297f8907de0fa2fe1ccbd26fdaf387f5f47c7275fedf8cce89f99446cf97"},
] ]
parso = [ parso = [
{file = "parso-0.8.3-py2.py3-none-any.whl", hash = "sha256:c001d4636cd3aecdaf33cbb40aebb59b094be2a74c556778ef5576c175e19e75"}, {file = "parso-0.8.3-py2.py3-none-any.whl", hash = "sha256:c001d4636cd3aecdaf33cbb40aebb59b094be2a74c556778ef5576c175e19e75"},
@ -1514,10 +1500,6 @@ Pygments = [
{file = "Pygments-2.14.0-py3-none-any.whl", hash = "sha256:fa7bd7bd2771287c0de303af8bfdfc731f51bd2c6a47ab69d117138893b82717"}, {file = "Pygments-2.14.0-py3-none-any.whl", hash = "sha256:fa7bd7bd2771287c0de303af8bfdfc731f51bd2c6a47ab69d117138893b82717"},
{file = "Pygments-2.14.0.tar.gz", hash = "sha256:b3ed06a9e8ac9a9aae5a6f5dbe78a8a58655d17b43b93c078f094ddc476ae297"}, {file = "Pygments-2.14.0.tar.gz", hash = "sha256:b3ed06a9e8ac9a9aae5a6f5dbe78a8a58655d17b43b93c078f094ddc476ae297"},
] ]
pyparsing = [
{file = "pyparsing-3.0.9-py3-none-any.whl", hash = "sha256:5026bae9a10eeaefb61dab2f09052b9f4307d44aee4eda64b309723d8d206bbc"},
{file = "pyparsing-3.0.9.tar.gz", hash = "sha256:2b020ecf7d21b687f219b71ecad3631f644a47f01403fa1d1036b0c6416d70fb"},
]
pytest = [ pytest = [
{file = "pytest-7.2.1-py3-none-any.whl", hash = "sha256:c7c6ca206e93355074ae32f7403e8ea12163b1163c976fee7d4d84027c162be5"}, {file = "pytest-7.2.1-py3-none-any.whl", hash = "sha256:c7c6ca206e93355074ae32f7403e8ea12163b1163c976fee7d4d84027c162be5"},
{file = "pytest-7.2.1.tar.gz", hash = "sha256:d45e0952f3727241918b8fd0f376f5ff6b301cc0777c6f9a556935c92d8a7d42"}, {file = "pytest-7.2.1.tar.gz", hash = "sha256:d45e0952f3727241918b8fd0f376f5ff6b301cc0777c6f9a556935c92d8a7d42"},
@ -1650,8 +1632,8 @@ ruff = [
{file = "ruff-0.0.224.tar.gz", hash = "sha256:3b07c2e8da29605a8577b1aef90f8ca0c34a66683b77b06007f1970bc0689003"}, {file = "ruff-0.0.224.tar.gz", hash = "sha256:3b07c2e8da29605a8577b1aef90f8ca0c34a66683b77b06007f1970bc0689003"},
] ]
safety = [ safety = [
{file = "safety-2.3.5-py3-none-any.whl", hash = "sha256:2227fcac1b22b53c1615af78872b48348661691450aa25d6704a5504dbd1f7e2"}, {file = "safety-2.3.4-py3-none-any.whl", hash = "sha256:6224dcd9b20986a2b2c5e7acfdfba6bca42bb11b2783b24ed04f32317e5167ea"},
{file = "safety-2.3.5.tar.gz", hash = "sha256:a60c11f8952f412cbb165d70cb1f673a3b43a2ba9a93ce11f97e6a4de834aa3a"}, {file = "safety-2.3.4.tar.gz", hash = "sha256:b9e74e794e82f54d11f4091c5d820c4d2d81de9f953bf0b4f33ac8bc402ae72c"},
] ]
setuptools = [ setuptools = [
{file = "setuptools-66.0.0-py3-none-any.whl", hash = "sha256:a78d01d1e2c175c474884671dde039962c9d74c7223db7369771fcf6e29ceeab"}, {file = "setuptools-66.0.0-py3-none-any.whl", hash = "sha256:a78d01d1e2c175c474884671dde039962c9d74c7223db7369771fcf6e29ceeab"},

View File

@ -37,7 +37,7 @@ build-backend = "poetry.core.masonry.api"
[tool.ruff] [tool.ruff]
line-length = 120 line-length = 120
select = ["E", "F", "U", "N", "C", "B"] select = ["E", "F", "UP", "N", "C", "B"]
# Exclude a variety of commonly ignored directories. # Exclude a variety of commonly ignored directories.
exclude = ["alembic",] exclude = ["alembic",]

View File

@ -75,7 +75,11 @@ async def test_delete_stuff(client: AsyncClient, payload: dict, status_code: int
), ),
) )
async def test_update_stuff( async def test_update_stuff(
client: AsyncClient, payload: dict, status_code: int, patch_payload: dict, patch_status_code: int client: AsyncClient,
payload: dict,
status_code: int,
patch_payload: dict,
patch_status_code: int,
): ):
await client.post("/stuff", json=payload) await client.post("/stuff", json=payload)
name = payload["name"] name = payload["name"]