Skip to content

Commit

Permalink
Adjust to src layout
Browse files Browse the repository at this point in the history
  • Loading branch information
hrimov committed Mar 11, 2024
1 parent 6bd61dd commit 08dc208
Show file tree
Hide file tree
Showing 96 changed files with 95 additions and 96 deletions.
9 changes: 4 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,21 @@ RUN apt-get update \

WORKDIR $PYSETUP_PATH

COPY ./pyproject.toml .
# due to the installation of the project itself, it should contain all the files
COPY . .

RUN pip install --no-cache-dir --upgrade pip \
&& pip install --no-cache-dir setuptools wheel \
&& pip install --no-cache-dir poetry

RUN poetry install --no-root --only main
RUN poetry install --only main

FROM python-base as production

COPY --from=builder-base $PYSETUP_PATH $PYSETUP_PATH

RUN apt-get update && apt-get install -y curl

WORKDIR decision-making-app/

COPY . /decision-making-app/

CMD ["python", "-Om", "src.app"]
CMD ["python", "-Om", "dma"]
2 changes: 1 addition & 1 deletion alembic.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[alembic]
# path to migration scripts
script_location = ./src/app/infrastructure/database/migrations
script_location = ./src/dma/infrastructure/database/migrations

# template used to generate migration file names; The default value is %%(rev)s_%%(slug)s
# Uncomment the line below if you want the files to be prepended with date and time
Expand Down
18 changes: 11 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ services:
- ./config:/decision_making_app/config:ro
environment:
CONFIG_PATH: ${CONFIG_PATH:-./config/local.ini}
command: [ "python", "-Om", "src.app" ]
command: [ "python", "-Om", "dma" ]
healthcheck:
test: [ "CMD-SHELL", "curl -fsSL http://localhost:5000/healthcheck/" ]
interval: 10s
Expand Down Expand Up @@ -73,10 +73,10 @@ services:
volumes:
- ./config:/decision_making_app/config:ro
- ./alembic.ini:/decision_making_app/alembic.ini:ro
- ./src/app/infrastructure/database/migrations:/decision_making_app/src/app/infrastructure/database/migrations:ro
- ./src/dma/infrastructure/database/migrations:/decision_making_app/src/dma/infrastructure/database/migrations:ro
environment:
CONFIG_PATH: ${CONFIG_PATH:-./config/local.ini}
command: [ "python", "-m", "alembic", "upgrade", "head" ]
command: [ "python", "-Om", "alembic", "upgrade", "head" ]

minio:
profiles: [ "api" ]
Expand All @@ -94,11 +94,15 @@ services:
MINIO_ROOT_USER: ${MINIO_ROOT_USER:-decision_making_app_admin}
MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD:-decision_making_app_admin}
healthcheck:
test: [ "CMD-SHELL", "curl -I http://localhost:9000/minio/health/live" ]
interval: 10s
timeout: 60s
test: [ "CMD", "mc", "ready", "local" ]
interval: 5s
timeout: 5s
retries: 5
start_period: 10s
# test: [ "CMD-SHELL", "curl -I http://localhost:9000/minio/health/live" ]
# interval: 10s
# timeout: 60s
# retries: 5
# start_period: 10s

rabbitmq:
profiles: [ "api" ]
Expand Down
10 changes: 3 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ description = ""
authors = ["hrimov <andrew.hrimov@gmail.com>"]
readme = "README.md"
packages = [
{ include = "app", from = "src" }
{ include = "dma", from = "src" }
]

[tool.poetry.scripts]
api = "src.app.__main__:run"
api = "src.dma.__main__:run"

[tool.poetry.dependencies]
python = "^3.11"
Expand Down Expand Up @@ -50,16 +50,12 @@ asyncio_mode = "auto"
addopts = "-vv --order-scope=module"


[tool.mypy]
explicit_package_bases = true


[tool.ruff]
select = ["ALL"]
ignore = ["A003", "ANN", "D", "FA100", "FA102", "FIX", "I", "PGH003", "PGH004", "TD"]

[tool.ruff.extend-per-file-ignores]
"src/app/infrastructure/database/migrations/versions/*" = ["ALL"]
"src/dma/infrastructure/database/migrations/versions/*" = ["ALL"]
"tests/*" = ["ARG001", "F401", "PT003", "PT004", "S"]


Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/app/__main__.py → src/dma/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from src.app.presentation.api import v1
from dma.presentation.api import v1


def run() -> None:
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
from datetime import datetime
from typing import List, TYPE_CHECKING

from src.app.application.common.dto import DTO
from dma.application.common.dto import DTO

if TYPE_CHECKING:
from src.app.application.problem.dto import ProblemMember, ProblemStatement
from src.app.application.stage.dto import Result, Suggestion
from dma.application.problem.dto import ProblemMember, ProblemStatement
from dma.application.stage.dto import Result, Suggestion


@dataclass(frozen=True)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from enum import Enum
from typing import Generic, List, TypeVar

from src.app.application.common.dto import DTO
from dma.application.common.dto import DTO


Item = TypeVar("Item")
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from dataclasses import dataclass
from typing import List, TypeAlias, TYPE_CHECKING

from src.app.application.common.dto import DTO
from src.app.application.common.pagination import PaginatedItems
from dma.application.common.dto import DTO
from dma.application.common.pagination import PaginatedItems


if TYPE_CHECKING:
from src.app.application.comment.dto import Comment, ProblemStatementComment
from src.app.application.stage.dto import Suggestion, SuggestionStage, VotingStage
from src.app.application.user.dto import User
from dma.application.comment.dto import Comment, ProblemStatementComment
from dma.application.stage.dto import Suggestion, SuggestionStage, VotingStage
from dma.application.user.dto import User


@dataclass(frozen=True)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from dataclasses import dataclass

from src.app.application.common.exceptions import DatabaseGatewayError
from dma.application.common.exceptions import DatabaseGatewayError


class ProblemDatabaseGatewayError(DatabaseGatewayError):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from dataclasses import dataclass

from src.app.application.common.filters import Filters
from dma.application.common.filters import Filters


@dataclass(frozen=True)
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from dataclasses import dataclass
from typing import List, TYPE_CHECKING

from src.app.application.common.dto import DTO, StartedEndedAtMixin
from dma.application.common.dto import DTO, StartedEndedAtMixin


if TYPE_CHECKING:
from src.app.application.comment.dto import ResultComment, SuggestionComment
from src.app.application.problem.dto import Problem
from dma.application.comment.dto import ResultComment, SuggestionComment
from dma.application.problem.dto import Problem


@dataclass(frozen=True)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from dataclasses import dataclass
from typing import List, TypeAlias, TYPE_CHECKING

from src.app.application.common.dto import DTO
from src.app.application.common.pagination import PaginatedItems
from dma.application.common.dto import DTO
from dma.application.common.pagination import PaginatedItems


if TYPE_CHECKING:
from src.app.application.problem.dto import Problem, ProblemMember
from dma.application.problem.dto import Problem, ProblemMember


@dataclass(frozen=True)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from dataclasses import dataclass

from src.app.application.common.exceptions import DatabaseGatewayError
from dma.application.common.exceptions import DatabaseGatewayError


class UserDatabaseGatewayError(DatabaseGatewayError):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from dataclasses import dataclass

from src.app.application.common.filters import Filters
from dma.application.common.filters import Filters


@dataclass(frozen=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from typing import Protocol

from src.app.application.common.pagination import Pagination
from src.app.application.user import dto
from src.app.application.user.filters import UserFilters
from dma.application.common.pagination import Pagination
from dma.application.user import dto
from dma.application.user.filters import UserFilters


class UserGateway(Protocol):
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import configparser
import os

from src.app.infrastructure.config.models import (
from dma.infrastructure.config.models import (
AppConfig,
Config,
DatabaseConfig,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from dataclasses import fields

from src.app.application.problem import dto
from src.app.infrastructure.database.models.problem import (
from dma.application.problem import dto
from dma.infrastructure.database.models.problem import (
Problem as ProblemModel,
ProblemState as ProblemStateModel,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from dataclasses import fields

from src.app.application.user import dto
from src.app.infrastructure.database.models.user import User as UserModel
from dma.application.user import dto
from dma.infrastructure.database.models.user import User as UserModel


def convert_db_model_to_user_dto(user_model: UserModel) -> dto.User:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from sqlalchemy.exc import SQLAlchemyError

from src.app.application.common.exceptions import DatabaseGatewayError
from dma.application.common.exceptions import DatabaseGatewayError


Param = ParamSpec("Param")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
create_async_engine,
)

from src.app.infrastructure.config.models.database import DatabaseConfig
from dma.infrastructure.config.models.database import DatabaseConfig


async def build_sa_engine(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@
from sqlalchemy.exc import DBAPIError, IntegrityError
from sqlalchemy.ext.asyncio import AsyncSession

from src.app.application.common.pagination import (
from dma.application.common.pagination import (
LimitOffsetPagination,
LimitOffsetPaginationResult,
SortOrder,
)
from src.app.application.common.exceptions import DatabaseGatewayError
from src.app.application.problem import dto
from src.app.application.problem.filters import ProblemFilters, ProblemStateFilters
from src.app.application.problem.exceptions import (
from dma.application.common.exceptions import DatabaseGatewayError
from dma.application.problem import dto
from dma.application.problem.filters import ProblemFilters, ProblemStateFilters
from dma.application.problem.exceptions import (
ProblemIdNotExists,
ProblemStateIdNotExists,
ProblemStateNameNotExists,
)
from src.app.infrastructure.database.converters.problem import (
from dma.infrastructure.database.converters.problem import (
convert_db_model_to_problem_dto,
convert_db_model_to_problem_state_dto,
convert_problem_create_dto_to_db_model,
convert_problem_state_create_dto_to_db_model,
update_problem_fields,
)
from src.app.infrastructure.database.exception_mapper import exception_mapper
from src.app.infrastructure.database.models.problem import (
from dma.infrastructure.database.exception_mapper import exception_mapper
from dma.infrastructure.database.models.problem import (
Problem as ProblemModel,
ProblemState as ProblemStateModel,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@
from sqlalchemy import func, select, Select
from sqlalchemy.exc import DBAPIError, IntegrityError

from src.app.application.common.pagination import (
from dma.application.common.pagination import (
LimitOffsetPagination,
LimitOffsetPaginationResult,
SortOrder,
)
from src.app.application.common.exceptions import DatabaseGatewayError
from src.app.application.user import dto
from src.app.application.user.exceptions import (
from dma.application.common.exceptions import DatabaseGatewayError
from dma.application.user import dto
from dma.application.user.exceptions import (
UserIdNotExists,
UserNicknameNotExists,
)
from src.app.application.user.filters import UserFilters
from src.app.infrastructure.database.converters.user import (
from dma.application.user.filters import UserFilters
from dma.infrastructure.database.converters.user import (
convert_db_model_to_user_dto,
convert_user_create_dto_to_db_model,
update_user_fields,
)
from src.app.infrastructure.database.exception_mapper import exception_mapper
from src.app.infrastructure.database.models.user import User as UserModel
from dma.infrastructure.database.exception_mapper import exception_mapper
from dma.infrastructure.database.models.user import User as UserModel

from .base import SQLAlchemyGateway

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

from alembic import context

from src.app.infrastructure.config.parsers.main import load_config
from src.app.infrastructure.database.models.base import BaseModel
from dma.infrastructure.config.parsers.main import load_config
from dma.infrastructure.database.models.base import BaseModel

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging

from src.app.infrastructure.config.models.application import AppConfig
from src.app.infrastructure.log.formatters import MainConsoleFormatter
from dma.infrastructure.config.models.application import AppConfig
from dma.infrastructure.log.formatters import MainConsoleFormatter


DEFAULT_LOGGING_LEVEL: int = logging.INFO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
)
from aio_pika.pool import Pool

from src.app.infrastructure.config.models import MessageQueueConfig
from src.app.application.common.interfaces import MessageQueueGateway
from dma.infrastructure.config.models import MessageQueueConfig
from dma.application.common.interfaces import MessageQueueGateway

from .iterables import batched

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from types_aiobotocore_s3.service_resource import Bucket, S3ServiceResource
from types_aiobotocore_s3.client import S3Client

from src.app.infrastructure.base import AIOBotoGateway
from dma.infrastructure.base import AIOBotoGateway


class ObjectStorageGatewayImpl(AIOBotoGateway):
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 08dc208

Please sign in to comment.