Skip to content
This repository has been archived by the owner on Dec 26, 2023. It is now read-only.

Commit

Permalink
feat: add isort to fix import to be PEP8 compliant (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgebodega authored Nov 16, 2022
1 parent f7e13c9 commit 64689ca
Show file tree
Hide file tree
Showing 40 changed files with 76 additions and 33 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ jobs:
run: poetry install
- name: Check code format (PEP8)
run: poe format:check
- name: Check import order (PEP8)
run: poe isort:check
- name: Analysing the code with pylint
run: poe lint:check

Expand Down
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
[tool.isort]
profile = "black"
skip_glob = ["src/config/**/*.py"]

[tool.poe.tasks]
format = "black ."
"format:check" = "black --check ."
isort = "isort ."
"isort:check" = "isort --check ."
lint = "pylint --output-format colorized src/**/*.py"
"lint:check" = "pylint src/**/*.py"
"migration:up" = { "cmd" = "alembic upgrade head", "envfile" = ".env" }
"migration:down" = { "cmd" = "alembic downgrade head-1", "envfile" = ".env" }
"migration:test:up" = { "cmd" = "alembic upgrade head", "env" = { DATABASE_NAME = "oipie_tests" } }
"migration:test:down" = { "cmd" = "alembic downgrade head-1", "env" = { DATABASE_NAME = "oipie_tests" } }
"run:checks" = ["format:check", "lint:check"]
"run:checks" = ["format:check", "lint:check", "isort:check"]
"start:dev" = "uvicorn src.main:app --reload"
test = "pytest"
"test:cov" = "pytest --cov=src"
Expand Down Expand Up @@ -44,6 +50,7 @@ SQLAlchemy = { extras = ["postgresql_psycopg2binary"], version = "1.4.44" }

[tool.poetry.group.dev.dependencies]
black = "22.10.0"
isort = "5.10.1"
pylint = "2.15.5"
pytest = "7.2.0"
pytest-cov = "4.0.0"
Expand Down
2 changes: 1 addition & 1 deletion src/api/routers/health/health.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"""
from fastapi import APIRouter, Depends
from sqlalchemy.orm import Session
from src.dependencies.database import get_database

from src.dependencies.database import get_database

router = APIRouter(tags=["health"])

Expand Down
1 change: 1 addition & 0 deletions src/api/routers/recipes/models/recipe_create_dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

from typing import Optional

from pydantic import BaseModel


Expand Down
2 changes: 2 additions & 0 deletions src/api/routers/recipes/models/recipe_response_dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"""

from typing import Optional

from pydantic import BaseModel

from src.core.recipes.domain.recipe import Recipe


Expand Down
2 changes: 1 addition & 1 deletion src/api/routers/recipes/recipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
"""

from fastapi import APIRouter, Depends

from src.api.routers.recipes.models.recipe_create_dto import RecipeCreateDto
from src.api.routers.recipes.models.recipe_response_dto import RecipeResponseDto
from src.core.recipes.application.recipes_creator import RecipesCreator
from src.core.recipes.application.recipes_lister import RecipesLister
from src.core.recipes.infrastructure.dependencies import recipes_creator, recipes_lister
from src.shared.models.paginated_model import PaginatedModel


router = APIRouter(prefix="/recipes", tags=["recipes"])


Expand Down
4 changes: 3 additions & 1 deletion src/api/routers/users/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
Routes file for Recipes
"""
from http import HTTPStatus

from fastapi import APIRouter, Depends

from src.api.routers.users.models.user_create_dto import UserCreateDto
from src.api.routers.users.models.user_response_dto import UserResponseDto
from src.api.routers.users.models.user_login_in import UserLoginIn
from src.api.routers.users.models.user_login_out import UserLoginOut
from src.api.routers.users.models.user_response_dto import UserResponseDto
from src.core.users.application.users_login import UsersLogin
from src.core.users.application.users_registerer import UsersRegisterer
from src.core.users.infrastructure.dependencies import users_login, users_registerer
Expand Down
1 change: 0 additions & 1 deletion src/config/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import os
from typing import Optional


DATABASE_CONFIG = {
"host": os.environ.get("DATABASE_HOST", "localhost"),
"port": int(
Expand Down
4 changes: 3 additions & 1 deletion src/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
# pylint: disable=redefined-outer-name, unused-argument

from typing import Iterable

import pytest
from fastapi.testclient import TestClient
from sqlalchemy import create_engine
from sqlalchemy.engine import Connection
from sqlalchemy.orm import sessionmaker, Session
from sqlalchemy.orm import Session, sessionmaker

from src.dependencies.database import (
database_connection,
get_database,
Expand Down
1 change: 1 addition & 0 deletions src/core/recipes/application/recipes_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Recipies Creator use case
"""
from typing import Optional, TypedDict

from src.core.recipes.domain.recipe import Recipe
from src.core.recipes.domain.recipes_repository import RecipesRepository

Expand Down
2 changes: 1 addition & 1 deletion src/core/recipes/application/test_recipes_lister.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""
Tests recipes lister
"""
from src.core.recipes.application.recipes_lister import RecipesLister
from src.core.recipes.domain.recipe import Recipe
from src.core.recipes.infrastructure.recipes_repository_fake import (
RecipesRepositoryFake,
)
from src.tests.fixtures.recipe_fixture import PANCAKE, STRAWBERRY_SMOOTHIE
from src.core.recipes.application.recipes_lister import RecipesLister


def test_serialize_is_ok():
Expand Down
1 change: 1 addition & 0 deletions src/core/recipes/domain/recipes_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Domain recipes repository interface module
"""
import abc

from src.core.recipes.domain.recipe import Recipe


Expand Down
1 change: 1 addition & 0 deletions src/core/recipes/domain/test_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# pylint: disable=redefined-outer-name, unused-argument

import pytest

from .recipe import Recipe, RecipeAttributes


Expand Down
1 change: 1 addition & 0 deletions src/core/recipes/infrastructure/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from fastapi import Depends
from sqlalchemy.orm import Session

from src.core.recipes.application.recipes_creator import RecipesCreator
from src.core.recipes.application.recipes_lister import RecipesLister
from src.core.recipes.domain.recipes_repository import RecipesRepository
Expand Down
6 changes: 4 additions & 2 deletions src/core/recipes/infrastructure/recipe_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
Recipe Database Model
"""
import uuid

from sqlalchemy import Column, Integer, String
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy import Column, String, Integer
from src.dependencies.database import BaseModel

from src.core.recipes.domain.recipe import Recipe
from src.dependencies.database import BaseModel


class RecipeModel(BaseModel):
Expand Down
3 changes: 2 additions & 1 deletion src/core/recipes/infrastructure/recipes_repository_fake.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
Recipes repository fake module
"""
from typing import Optional
from src.core.recipes.domain.recipes_repository import RecipesRepository

from src.core.recipes.domain.recipe import Recipe
from src.core.recipes.domain.recipes_repository import RecipesRepository


class RecipesRepositoryFake(RecipesRepository):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
SQLAlchemy repository for Recipes
"""
from sqlalchemy.orm import Session

from src.core.recipes.domain.recipe import Recipe
from src.core.recipes.domain.recipes_repository import RecipesRepository
from src.core.recipes.infrastructure.recipe_model import RecipeModel
from src.core.recipes.domain.recipe import Recipe


class RecipesRepositorySQLAlchemy(RecipesRepository):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
import pytest
from sqlalchemy.orm import Session

from src.core.recipes.domain.recipe import Recipe
from src.core.recipes.infrastructure.recipe_model import RecipeModel
from src.core.recipes.infrastructure.recipes_repository_sqlalchemy import (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Mapping

from fastapi import status

from src.core.shared.infrastructure.domain_exception_category import (
Expand Down
1 change: 1 addition & 0 deletions src/core/shared/services/password/argon2_password.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
from argon2 import PasswordHasher
from argon2.exceptions import VerificationError

from src.core.shared.services.password.password import Password


Expand Down
2 changes: 1 addition & 1 deletion src/core/shared/services/tokenizer/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
todo
"""

from src.config.jwt import JWT_SECRET_KEY
from src.core.shared.services.tokenizer.jwt_tokenizer import JwtTokenizer
from src.core.shared.services.tokenizer.tokenizer import Tokenizer
from src.config.jwt import JWT_SECRET_KEY


def tokenizer() -> Tokenizer:
Expand Down
3 changes: 2 additions & 1 deletion src/core/shared/services/tokenizer/jwt_tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
JwtTokenizer
"""
import jwt
from src.core.shared.services.tokenizer.tokenizer import Tokenizer

from src.core.shared.services.tokenizer.errors.invalid_token_error import (
InvalidTokenError,
)
from src.core.shared.services.tokenizer.tokenizer import Tokenizer


class JwtTokenizer(Tokenizer):
Expand Down
9 changes: 4 additions & 5 deletions src/core/users/application/test_users_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
UsersLogin tests
"""
import pytest

from src.core.shared.services.password.plain_text_password import PlainTextPassword
from src.core.shared.services.tokenizer.jwt_tokenizer import JwtTokenizer
from src.core.users.application.users_login import UsersLogin
from src.core.users.domain.errors.user_credentials_error import (
UserCredentialsError,
)
from src.core.users.domain.errors.user_credentials_error import UserCredentialsError
from src.core.users.domain.user import User
from src.core.users.infrastructure.user_repository_fake import UsersRepositoryFake
from src.core.shared.services.password.plain_text_password import PlainTextPassword
from src.core.shared.services.tokenizer.jwt_tokenizer import JwtTokenizer
from src.tests.fixtures.user_fixture import JANE, JOHN

# pylint: disable=redefined-outer-name
Expand Down
3 changes: 2 additions & 1 deletion src/core/users/application/test_users_registerer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
UsersRegisterer tests
"""
import pytest

from src.core.shared.services.password.plain_text_password import PlainTextPassword
from src.core.users.application.users_registerer import UsersRegisterer
from src.core.users.domain.errors.user_with_email_already_exists_error import (
UserWithEmailAlreadyExistsError,
Expand All @@ -11,7 +13,6 @@
)
from src.core.users.domain.user import User
from src.core.users.infrastructure.user_repository_fake import UsersRepositoryFake
from src.core.shared.services.password.plain_text_password import PlainTextPassword
from src.tests.fixtures.user_fixture import JANE, JOHN

# pylint: disable=redefined-outer-name
Expand Down
6 changes: 2 additions & 4 deletions src/core/users/application/users_login.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
"""
Users Login use case
"""
from src.core.users.domain.errors.user_credentials_error import (
UserCredentialsError,
)
from src.core.users.domain.users_repository import UsersRepository
from src.core.shared.services.password.password import Password
from src.core.shared.services.tokenizer.tokenizer import Tokenizer
from src.core.users.domain.errors.user_credentials_error import UserCredentialsError
from src.core.users.domain.users_repository import UsersRepository


class UsersLogin:
Expand Down
1 change: 1 addition & 0 deletions src/core/users/domain/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Tests to check User class
"""
from user import User, UserAttributes

from src.tests.fixtures.user_fixture import JANE, JOHN


Expand Down
1 change: 1 addition & 0 deletions src/core/users/domain/users_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Domain users repository interface module
"""
import abc

from src.core.users.domain.user import User


Expand Down
1 change: 1 addition & 0 deletions src/core/users/infrastructure/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from fastapi import Depends
from sqlalchemy.orm import Session

from src.core.shared.services.password.dependencies import password_hasher
from src.core.shared.services.password.password import Password
from src.core.shared.services.tokenizer.dependencies import tokenizer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
"""
import pytest
from sqlalchemy.orm import Session

from src.core.users.domain.user import User
from src.core.users.infrastructure.user_model import UserModel
from src.core.users.infrastructure.user_repository_sqlalchemy import (
UsersRepositorySQLAlchemy,
)
from src.core.users.infrastructure.user_model import UserModel
from src.tests.fixtures.user_fixture import JOHN

# pylint: disable=redefined-outer-name, unused-argument
Expand Down
6 changes: 4 additions & 2 deletions src/core/users/infrastructure/user_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
User Database Model
"""
import uuid
from sqlalchemy.dialects.postgresql import UUID

from sqlalchemy import Column, String
from src.dependencies.database import BaseModel
from sqlalchemy.dialects.postgresql import UUID

from src.core.users.domain.user import User
from src.dependencies.database import BaseModel


class UserModel(BaseModel):
Expand Down
1 change: 1 addition & 0 deletions src/core/users/infrastructure/user_repository_fake.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Users repository fake module
"""
from typing import Optional

from src.core.users.domain.user import User
from src.core.users.domain.users_repository import UsersRepository

Expand Down
2 changes: 2 additions & 0 deletions src/core/users/infrastructure/user_repository_sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
SQLAlchemy repository for Users
"""
from typing import Optional

from sqlalchemy.orm import Session

from src.core.users.domain.user import User
from src.core.users.domain.users_repository import UsersRepository
from src.core.users.infrastructure.user_model import UserModel
Expand Down
4 changes: 3 additions & 1 deletion src/dependencies/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
Database dependencies
"""
from typing import Iterable

from fastapi import Depends
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, Session
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import Session, sessionmaker

from src.config.database import database_url_connection

BaseModel = declarative_base()
Expand Down
Loading

0 comments on commit 64689ca

Please sign in to comment.