Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce ruff, remove flake8 #27

Merged
merged 2 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ jobs:
- name: Install and configure Poetry
uses: snok/install-poetry@v1
with:
version: 1.1.12
version: 1.6.1
virtualenvs-create: false
- name: Install Dependencies
run: poetry install --no-root --no-interaction
- name: Style Check (black)
run: poetry run black . --check --verbose --diff --color
run: poetry run black gcmanager/ tests/ --check --verbose --diff --color
- name: Imports Sorting Check (isort)
run: poetry run isort . --check --diff
run: poetry run isort gcmanager/ tests/ --check --diff
- name: Type Check (mypy)
run: poetry run mypy
- name: Lint Check (flake8)
run: poetry run flake8 .
- name: Lint Check (Ruff)
run: poetry run ruff gcmanager/ tests/
- name: Common Security Checks (bandit)
run: poetry run bandit -r gcmanager --verbose
- name: Start MongoDB
Expand Down
3 changes: 1 addition & 2 deletions gcmanager/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@
def create_app() -> falcon.App:
container = build_dependency_container()
router = make_router(container)
app = App(router=router)
return app
return App(router=router)
7 changes: 1 addition & 6 deletions gcmanager/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,7 @@ def _build_mongo_db_connection_string(container: Container) -> str:
"environment variables required to "
"build mongodb connection string are missing",
)
return "mongodb://%s:%s@%s:%s/" % (
quote(username),
quote(password),
host,
port,
)
return f"mongodb://{quote(username)}:{quote(password)}@{host}:{port}/"


def _build_mongodb_client(container: Container) -> None:
Expand Down
19 changes: 7 additions & 12 deletions gcmanager/repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from abc import ABC
from abc import abstractmethod
from dataclasses import asdict
from typing import Optional

from pymongo import ASCENDING
from pymongo.collection import Collection
Expand Down Expand Up @@ -34,7 +33,7 @@ def get_available_denominations(self) -> list[Denomination]:
def get_near_expiry_gift_card(
self,
denomination: Denomination,
) -> Optional[GiftCard]:
) -> GiftCard | None:
pass

@abstractmethod
Expand All @@ -46,11 +45,11 @@ def mark_used(self, gift_card_id: GiftCardID) -> None:
pass

@abstractmethod
def get_by_id(self, gift_card_id: GiftCardID) -> Optional[GiftCard]:
def get_by_id(self, gift_card_id: GiftCardID) -> GiftCard | None:
pass

@abstractmethod
def get_by_redeem_code(self, redeem_code: RedeemCode) -> Optional[GiftCard]:
def get_by_redeem_code(self, redeem_code: RedeemCode) -> GiftCard | None:
pass

@abstractmethod
Expand Down Expand Up @@ -108,11 +107,7 @@ def get_summary(self) -> GiftCardAssetSummary:
)
used_aggregation = aggregation_result["used"]
total = total_aggregation[0]["amount"]
if not used_aggregation:
used = 0
else:
used = used_aggregation[0]["amount"]

used = 0 if not used_aggregation else used_aggregation[0]["amount"]
return GiftCardAssetSummary(total=Money(total), used=Money(used))

def next_id(self) -> uuid.UUID:
Expand All @@ -134,7 +129,7 @@ def get_available_denominations(self) -> list[Denomination]:
def get_near_expiry_gift_card(
self,
denomination: Denomination,
) -> Optional[GiftCard]:
) -> GiftCard | None:
result = list(
self._collection.find({"is_used": False})
.sort("date_of_issue", ASCENDING)
Expand Down Expand Up @@ -170,7 +165,7 @@ def update(self, gift_card_request: GiftCardUpdateRequest) -> None:
def mark_used(self, gift_card_id: GiftCardID) -> None:
self._collection.update_one({"_id": gift_card_id}, {"$set": {"is_used": True}})

def get_by_id(self, gift_card_id: GiftCardID) -> Optional[GiftCard]:
def get_by_id(self, gift_card_id: GiftCardID) -> GiftCard | None:
gc_dict = self._collection.find_one({"_id": gift_card_id})
if not gc_dict:
return None
Expand All @@ -182,7 +177,7 @@ def _make_gc(gc_dict: dict) -> GiftCard:
date_of_issue = gc_dict.pop("date_of_issue").date()
return GiftCard(**{"id": gc_id, "date_of_issue": date_of_issue, **gc_dict})

def get_by_redeem_code(self, redeem_code: RedeemCode) -> Optional[GiftCard]:
def get_by_redeem_code(self, redeem_code: RedeemCode) -> GiftCard | None:
gc_dict = self._collection.find_one({"redeem_code": redeem_code})
if not gc_dict:
return None
Expand Down
3 changes: 1 addition & 2 deletions gcmanager/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from abc import ABC
from abc import abstractmethod
from typing import NewType
from typing import Type

from gcmanager.enums import AppEnvironment

Expand Down Expand Up @@ -49,7 +48,7 @@ def load() -> Settings:
)


def settings_selector(enviroment: AppEnvironment) -> Type[AppSettings]:
def settings_selector(enviroment: AppEnvironment) -> type[AppSettings]:
env_settings_map = {
AppEnvironment.TEST: TestAppSettings,
AppEnvironment.PROD: ProdAppSettings,
Expand Down
10 changes: 7 additions & 3 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
build:
black . --check --verbose --diff --color
isort . --check --diff
black gcmanager/ tests/ --check --verbose --diff --color
isort gcmanager/ tests/ --check --diff
mypy
flake8 .
ruff check gcmanager/ tests/
bandit -r gcmanager --verbose
docker-compose -f mongo-for-testing.yml up -d
coverage erase
Expand All @@ -11,3 +11,7 @@ build:
docker-compose -f mongo-for-testing.yml down
coverage combine
coverage report
style:
ruff check --select="COM812,COM819,F401,I001,I002,W291,W292,W293,UP,SIM" gcmanager/ tests/ --fix
black gcmanager/ tests/
isort gcmanager/ tests/
Loading
Loading