From 9b1938c45049febd4f8fd8c9e7c7a72dda2d0f04 Mon Sep 17 00:00:00 2001 From: Jakub Miazek Date: Mon, 12 Sep 2022 13:24:15 +0200 Subject: [PATCH] refactor --- Dockerfile | 2 +- Makefile | 2 +- alembic/env.py | 2 +- {the_app => app}/__init__.py | 0 {the_app => app}/api/__init__.py | 0 {the_app => app}/api/nonsense.py | 6 +++--- {the_app => app}/api/shakespeare.py | 4 ++-- {the_app => app}/api/stuff.py | 8 ++++---- {the_app => app}/config.py | 2 +- {the_app => app}/database.py | 2 +- {the_app => app}/exceptions.py | 0 {the_app => app}/main.py | 8 ++++---- app/models/__init__.py | 4 ++++ {the_app => app}/models/base.py | 0 {the_app => app}/models/nonsense.py | 2 +- {the_app => app}/models/shakespeare.py | 2 +- {the_app => app}/models/stuff.py | 2 +- {the_app => app}/schemas/__init__.py | 0 {the_app => app}/schemas/nnonsense.py | 0 {the_app => app}/schemas/shakespeare.py | 0 {the_app => app}/schemas/stuff.py | 0 {the_app => app}/utils.py | 0 docker-compose.yml | 2 +- tests/app/api/nonsense.py | 6 +++--- tests/app/api/shakespeare.py | 4 ++-- tests/app/api/stuff.py | 8 ++++---- tests/app/config.py | 2 +- tests/app/database.py | 2 +- tests/app/main.py | 8 ++++---- tests/app/models/__init__.py | 6 +++--- tests/app/models/nonsense.py | 2 +- tests/app/models/shakespeare.py | 2 +- tests/app/models/stuff.py | 2 +- tests/conftest.py | 6 +++--- the_app/models/__init__.py | 4 ---- 35 files changed, 50 insertions(+), 50 deletions(-) rename {the_app => app}/__init__.py (100%) rename {the_app => app}/api/__init__.py (100%) rename {the_app => app}/api/nonsense.py (88%) rename {the_app => app}/api/shakespeare.py (79%) rename {the_app => app}/api/stuff.py (91%) rename {the_app => app}/config.py (96%) rename {the_app => app}/database.py (97%) rename {the_app => app}/exceptions.py (100%) rename {the_app => app}/main.py (65%) create mode 100644 app/models/__init__.py rename {the_app => app}/models/base.py (100%) rename {the_app => app}/models/nonsense.py (97%) rename {the_app => app}/models/shakespeare.py (99%) rename {the_app => app}/models/stuff.py (97%) rename {the_app => app}/schemas/__init__.py (100%) rename {the_app => app}/schemas/nnonsense.py (100%) rename {the_app => app}/schemas/shakespeare.py (100%) rename {the_app => app}/schemas/stuff.py (100%) rename {the_app => app}/utils.py (100%) delete mode 100644 the_app/models/__init__.py diff --git a/Dockerfile b/Dockerfile index c27c112..ac5ec94 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ RUN set -ex && pip install -r requirements.txt FROM builder as final WORKDIR /code -COPY ./the_app/ /code/ +COPY app/ /code/ COPY ./tests/ /code/ COPY .env /code/ diff --git a/Makefile b/Makefile index 0429534..eaf3be2 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,7 @@ migrate-create: ## create new alembic migration .PHONY: requirements requirements: ## Refresh requirements.txt from pipfile.lock - pipenv run pip freeze >> requirements.txt + pipenv lock --requirements --dev >| requirements.txt .PHONY: test test: ## Run project tests diff --git a/alembic/env.py b/alembic/env.py index afe8edb..d8bd7a2 100644 --- a/alembic/env.py +++ b/alembic/env.py @@ -8,7 +8,7 @@ from sqlalchemy.ext.asyncio import create_async_engine parent_dir = os.path.abspath(os.path.join(os.getcwd())) sys.path.append(parent_dir) -from the_app.models.base import Base as app_base +from app.models.base import Base as app_base target_metadata = app_base.metadata diff --git a/the_app/__init__.py b/app/__init__.py similarity index 100% rename from the_app/__init__.py rename to app/__init__.py diff --git a/the_app/api/__init__.py b/app/api/__init__.py similarity index 100% rename from the_app/api/__init__.py rename to app/api/__init__.py diff --git a/the_app/api/nonsense.py b/app/api/nonsense.py similarity index 88% rename from the_app/api/nonsense.py rename to app/api/nonsense.py index 410cb40..5597043 100644 --- a/the_app/api/nonsense.py +++ b/app/api/nonsense.py @@ -1,9 +1,9 @@ from fastapi import APIRouter, Depends, status from sqlalchemy.ext.asyncio import AsyncSession -from the_app.database import get_db -from the_app.models.nonsense import Nonsense -from the_app.schemas.nnonsense import NonsenseResponse, NonsenseSchema +from app.database import get_db +from app.models.nonsense import Nonsense +from app.schemas.nnonsense import NonsenseResponse, NonsenseSchema router = APIRouter(prefix="/v1/nonsense") diff --git a/the_app/api/shakespeare.py b/app/api/shakespeare.py similarity index 79% rename from the_app/api/shakespeare.py rename to app/api/shakespeare.py index 4a89fc0..95528a6 100644 --- a/the_app/api/shakespeare.py +++ b/app/api/shakespeare.py @@ -1,8 +1,8 @@ from fastapi import APIRouter, Depends, status from sqlalchemy.ext.asyncio import AsyncSession -from the_app.database import get_db -from the_app.models.shakespeare import Paragraph +from app.database import get_db +from app.models.shakespeare import Paragraph router = APIRouter(prefix="/v1/shakespeare") diff --git a/the_app/api/stuff.py b/app/api/stuff.py similarity index 91% rename from the_app/api/stuff.py rename to app/api/stuff.py index 93b8acf..509f131 100644 --- a/the_app/api/stuff.py +++ b/app/api/stuff.py @@ -2,10 +2,10 @@ from fastapi import APIRouter, Depends, HTTPException, status from sqlalchemy.exc import SQLAlchemyError from sqlalchemy.ext.asyncio import AsyncSession -from the_app.database import get_db -from the_app.models.stuff import Stuff -from the_app.schemas.stuff import StuffResponse, StuffSchema -from the_app.utils import get_logger +from app.database import get_db +from app.models.stuff import Stuff +from app.schemas.stuff import StuffResponse, StuffSchema +from app.utils import get_logger router = APIRouter(prefix="/v1/stuff") diff --git a/the_app/config.py b/app/config.py similarity index 96% rename from the_app/config.py rename to app/config.py index efab465..c299105 100644 --- a/the_app/config.py +++ b/app/config.py @@ -3,7 +3,7 @@ from functools import lru_cache from pydantic import BaseSettings -from the_app.utils import get_logger +from app.utils import get_logger logger = get_logger(__name__) diff --git a/the_app/database.py b/app/database.py similarity index 97% rename from the_app/database.py rename to app/database.py index 3186318..6c46d25 100644 --- a/the_app/database.py +++ b/app/database.py @@ -5,7 +5,7 @@ from sqlalchemy.exc import SQLAlchemyError from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine from sqlalchemy.orm import sessionmaker -from the_app import config +from app import config global_settings = config.get_settings() url = global_settings.asyncpg_url diff --git a/the_app/exceptions.py b/app/exceptions.py similarity index 100% rename from the_app/exceptions.py rename to app/exceptions.py diff --git a/the_app/main.py b/app/main.py similarity index 65% rename from the_app/main.py rename to app/main.py index 1242bc9..e40a153 100644 --- a/the_app/main.py +++ b/app/main.py @@ -1,9 +1,9 @@ from fastapi import FastAPI -from the_app.api.nonsense import router as nonsense_router -from the_app.api.stuff import router as stuff_router -from the_app.api.shakespeare import router as shakespeare_router -from the_app.utils import get_logger +from app.api.nonsense import router as nonsense_router +from app.api.stuff import router as stuff_router +from app.api.shakespeare import router as shakespeare_router +from app.utils import get_logger logger = get_logger(__name__) diff --git a/app/models/__init__.py b/app/models/__init__.py new file mode 100644 index 0000000..d61f6ad --- /dev/null +++ b/app/models/__init__.py @@ -0,0 +1,4 @@ +# for Alembic and unit tests +from app.models.stuff import * # noqa +from app.models.nonsense import * # noqa +from app.models.shakespeare import * # noqa \ No newline at end of file diff --git a/the_app/models/base.py b/app/models/base.py similarity index 100% rename from the_app/models/base.py rename to app/models/base.py diff --git a/the_app/models/nonsense.py b/app/models/nonsense.py similarity index 97% rename from the_app/models/nonsense.py rename to app/models/nonsense.py index 9dd449f..929fc98 100644 --- a/the_app/models/nonsense.py +++ b/app/models/nonsense.py @@ -5,7 +5,7 @@ from sqlalchemy import Column, String, select from sqlalchemy.dialects.postgresql import UUID from sqlalchemy.ext.asyncio import AsyncSession -from the_app.models.base import Base +from app.models.base import Base class Nonsense(Base): diff --git a/the_app/models/shakespeare.py b/app/models/shakespeare.py similarity index 99% rename from the_app/models/shakespeare.py rename to app/models/shakespeare.py index 902caf1..b7acb64 100644 --- a/the_app/models/shakespeare.py +++ b/app/models/shakespeare.py @@ -13,7 +13,7 @@ from sqlalchemy import ( from sqlalchemy.ext.asyncio import AsyncSession from sqlalchemy.orm import relationship -from the_app.models.base import Base +from app.models.base import Base metadata = Base.metadata diff --git a/the_app/models/stuff.py b/app/models/stuff.py similarity index 97% rename from the_app/models/stuff.py rename to app/models/stuff.py index 0305cba..ea1a2a2 100644 --- a/the_app/models/stuff.py +++ b/app/models/stuff.py @@ -5,7 +5,7 @@ from sqlalchemy import Column, String, select from sqlalchemy.dialects.postgresql import UUID from sqlalchemy.ext.asyncio import AsyncSession -from the_app.models.base import Base +from app.models.base import Base class Stuff(Base): diff --git a/the_app/schemas/__init__.py b/app/schemas/__init__.py similarity index 100% rename from the_app/schemas/__init__.py rename to app/schemas/__init__.py diff --git a/the_app/schemas/nnonsense.py b/app/schemas/nnonsense.py similarity index 100% rename from the_app/schemas/nnonsense.py rename to app/schemas/nnonsense.py diff --git a/the_app/schemas/shakespeare.py b/app/schemas/shakespeare.py similarity index 100% rename from the_app/schemas/shakespeare.py rename to app/schemas/shakespeare.py diff --git a/the_app/schemas/stuff.py b/app/schemas/stuff.py similarity index 100% rename from the_app/schemas/stuff.py rename to app/schemas/stuff.py diff --git a/the_app/utils.py b/app/utils.py similarity index 100% rename from the_app/utils.py rename to app/utils.py diff --git a/docker-compose.yml b/docker-compose.yml index d2af3f3..304c886 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,7 +8,7 @@ services: - .env - .secrets command: bash -c " - alembic upgrade head && uvicorn the_app.main:app + alembic upgrade head && uvicorn app.main:app --host 0.0.0.0 --port 8080 --lifespan=on --use-colors --loop uvloop --http httptools --reload --log-level debug diff --git a/tests/app/api/nonsense.py b/tests/app/api/nonsense.py index 410cb40..5597043 100644 --- a/tests/app/api/nonsense.py +++ b/tests/app/api/nonsense.py @@ -1,9 +1,9 @@ from fastapi import APIRouter, Depends, status from sqlalchemy.ext.asyncio import AsyncSession -from the_app.database import get_db -from the_app.models.nonsense import Nonsense -from the_app.schemas.nnonsense import NonsenseResponse, NonsenseSchema +from app.database import get_db +from app.models.nonsense import Nonsense +from app.schemas.nnonsense import NonsenseResponse, NonsenseSchema router = APIRouter(prefix="/v1/nonsense") diff --git a/tests/app/api/shakespeare.py b/tests/app/api/shakespeare.py index 4a89fc0..95528a6 100644 --- a/tests/app/api/shakespeare.py +++ b/tests/app/api/shakespeare.py @@ -1,8 +1,8 @@ from fastapi import APIRouter, Depends, status from sqlalchemy.ext.asyncio import AsyncSession -from the_app.database import get_db -from the_app.models.shakespeare import Paragraph +from app.database import get_db +from app.models.shakespeare import Paragraph router = APIRouter(prefix="/v1/shakespeare") diff --git a/tests/app/api/stuff.py b/tests/app/api/stuff.py index 93b8acf..509f131 100644 --- a/tests/app/api/stuff.py +++ b/tests/app/api/stuff.py @@ -2,10 +2,10 @@ from fastapi import APIRouter, Depends, HTTPException, status from sqlalchemy.exc import SQLAlchemyError from sqlalchemy.ext.asyncio import AsyncSession -from the_app.database import get_db -from the_app.models.stuff import Stuff -from the_app.schemas.stuff import StuffResponse, StuffSchema -from the_app.utils import get_logger +from app.database import get_db +from app.models.stuff import Stuff +from app.schemas.stuff import StuffResponse, StuffSchema +from app.utils import get_logger router = APIRouter(prefix="/v1/stuff") diff --git a/tests/app/config.py b/tests/app/config.py index efab465..c299105 100644 --- a/tests/app/config.py +++ b/tests/app/config.py @@ -3,7 +3,7 @@ from functools import lru_cache from pydantic import BaseSettings -from the_app.utils import get_logger +from app.utils import get_logger logger = get_logger(__name__) diff --git a/tests/app/database.py b/tests/app/database.py index 3186318..6c46d25 100644 --- a/tests/app/database.py +++ b/tests/app/database.py @@ -5,7 +5,7 @@ from sqlalchemy.exc import SQLAlchemyError from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine from sqlalchemy.orm import sessionmaker -from the_app import config +from app import config global_settings = config.get_settings() url = global_settings.asyncpg_url diff --git a/tests/app/main.py b/tests/app/main.py index 1242bc9..e40a153 100644 --- a/tests/app/main.py +++ b/tests/app/main.py @@ -1,9 +1,9 @@ from fastapi import FastAPI -from the_app.api.nonsense import router as nonsense_router -from the_app.api.stuff import router as stuff_router -from the_app.api.shakespeare import router as shakespeare_router -from the_app.utils import get_logger +from app.api.nonsense import router as nonsense_router +from app.api.stuff import router as stuff_router +from app.api.shakespeare import router as shakespeare_router +from app.utils import get_logger logger = get_logger(__name__) diff --git a/tests/app/models/__init__.py b/tests/app/models/__init__.py index 578857f..d61f6ad 100644 --- a/tests/app/models/__init__.py +++ b/tests/app/models/__init__.py @@ -1,4 +1,4 @@ # for Alembic and unit tests -from the_app.models.stuff import * # noqa -from the_app.models.nonsense import * # noqa -from the_app.models.shakespeare import * # noqa \ No newline at end of file +from app.models.stuff import * # noqa +from app.models.nonsense import * # noqa +from app.models.shakespeare import * # noqa \ No newline at end of file diff --git a/tests/app/models/nonsense.py b/tests/app/models/nonsense.py index 9dd449f..929fc98 100644 --- a/tests/app/models/nonsense.py +++ b/tests/app/models/nonsense.py @@ -5,7 +5,7 @@ from sqlalchemy import Column, String, select from sqlalchemy.dialects.postgresql import UUID from sqlalchemy.ext.asyncio import AsyncSession -from the_app.models.base import Base +from app.models.base import Base class Nonsense(Base): diff --git a/tests/app/models/shakespeare.py b/tests/app/models/shakespeare.py index 902caf1..b7acb64 100644 --- a/tests/app/models/shakespeare.py +++ b/tests/app/models/shakespeare.py @@ -13,7 +13,7 @@ from sqlalchemy import ( from sqlalchemy.ext.asyncio import AsyncSession from sqlalchemy.orm import relationship -from the_app.models.base import Base +from app.models.base import Base metadata = Base.metadata diff --git a/tests/app/models/stuff.py b/tests/app/models/stuff.py index 0305cba..ea1a2a2 100644 --- a/tests/app/models/stuff.py +++ b/tests/app/models/stuff.py @@ -5,7 +5,7 @@ from sqlalchemy import Column, String, select from sqlalchemy.dialects.postgresql import UUID from sqlalchemy.ext.asyncio import AsyncSession -from the_app.models.base import Base +from app.models.base import Base class Stuff(Base): diff --git a/tests/conftest.py b/tests/conftest.py index 1e1f627..3532e3b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2,9 +2,9 @@ import pytest import pytest_asyncio from httpx import AsyncClient -from the_app.database import engine -from the_app.main import app -from the_app.models.base import Base +from app.database import engine +from app.main import app +from app.models.base import Base @pytest.fixture( diff --git a/the_app/models/__init__.py b/the_app/models/__init__.py deleted file mode 100644 index 578857f..0000000 --- a/the_app/models/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -# for Alembic and unit tests -from the_app.models.stuff import * # noqa -from the_app.models.nonsense import * # noqa -from the_app.models.shakespeare import * # noqa \ No newline at end of file