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

Introducing ruff #668

Merged
merged 1 commit into from
Jul 26, 2024
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
6 changes: 3 additions & 3 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-test-image
lint-black:
name: 'Lint check (black)'
lint-ruff:
name: 'Lint check (ruff)'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: psf/black@stable
- uses: chartboost/ruff-action@v1
unit-test-postgres:
name: 'Unit tests (PostgreSQL)'
runs-on: ubuntu-latest
Expand Down
10 changes: 6 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
repos:
- repo: https://github.com/psf/black
rev: 24.4.2
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.4
hooks:
- id: black
language_version: python3.12
- id: ruff-format
name: ruff-format
entry: make format
language_version: python3.12
12 changes: 5 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: format isort black doc test test_migrations run
.PHONY: format doc test test_migrations run

install:
poetry install --no-root --all-extras
Expand All @@ -7,13 +7,11 @@ install:
update:
poetry update

format: isort black
format:
poetry run ruff format && poetry run ruff check --fix --select I

isort:
isort .

black:
black .
lint:
poetry run ruff check --fix

doc:
poetry run python docs/generate_openapi_doc.py
Expand Down
12 changes: 0 additions & 12 deletions alembic.ini
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,6 @@ prepend_sys_path = .

sqlalchemy.url = driver://user:pass@localhost/dbname


[post_write_hooks]
# post_write_hooks defines scripts or Python functions that are run
# on newly generated revision scripts. See the documentation for further
# detail and examples

# format using "black" - use the console_scripts runner, against the "black" entrypoint
# hooks=black
# black.type=console_scripts
# black.entrypoint=black
# black.options=-l 79

# Logging configuration
[loggers]
keys = root,sqlalchemy,alembic
Expand Down
8 changes: 7 additions & 1 deletion app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,15 @@
from fastapi.responses import JSONResponse
from pydantic import ValidationError
from pydantic_core import ArgsKwargs, ErrorDetails
from starlette import status
from starlette.exceptions import HTTPException as StarletteHTTPException

from app.exceptions import *
from app.exceptions import (
AuthorizationError,
BadRequestError,
ContractRevertError,
ServiceUnavailableError,
)
from app.log import output_access_log
from app.routers.issuer import (
account,
Expand Down
8 changes: 4 additions & 4 deletions app/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def ethereum_address_validator(
"""Validator for ethereum address"""
if value is not None:
if not isinstance(value, str):
raise ValueError(f"value must be of string")
raise ValueError("value must be of string")
if not Web3.is_address(value):
raise ValueError("invalid ethereum address")
return value
Expand All @@ -51,14 +51,14 @@ def datetime_string_validator(
datetime_format = "%Y-%m-%d %H:%M:%S"

if not isinstance(value, str):
raise ValueError(f"value must be of string datetime format")
raise ValueError("value must be of string datetime format")

try:
converted = datetime.strptime(value, datetime_format)
if value != converted.strftime(datetime_format):
raise ValueError(f"value must be string datetime format")
raise ValueError("value must be string datetime format")
except ValueError:
raise ValueError(f"value must be of string datetime format")
raise ValueError("value must be of string datetime format")
return value


Expand Down
4 changes: 2 additions & 2 deletions app/model/db/batch_issue_redeem.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
SPDX-License-Identifier: Apache-2.0
"""

from enum import Enum
from enum import StrEnum

from sqlalchemy import BigInteger, Boolean, Integer, String
from sqlalchemy.orm import Mapped, mapped_column
Expand All @@ -44,7 +44,7 @@ class BatchIssueRedeemUpload(Base):
processed: Mapped[bool | None] = mapped_column(Boolean, default=False, index=True)


class BatchIssueRedeemProcessingCategory(str, Enum):
class BatchIssueRedeemProcessingCategory(StrEnum):
"""Batch Issue/Redeem Category"""

ISSUE = "Issue"
Expand Down
4 changes: 2 additions & 2 deletions app/model/db/batch_register_personal_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
SPDX-License-Identifier: Apache-2.0
"""

from enum import Enum
from enum import StrEnum

from sqlalchemy import JSON, Integer, String
from sqlalchemy.ext.hybrid import hybrid_property
Expand All @@ -39,7 +39,7 @@ class BatchRegisterPersonalInfoUpload(Base):
status: Mapped[str] = mapped_column(String, nullable=False, index=True)


class BatchRegisterPersonalInfoUploadStatus(str, Enum):
class BatchRegisterPersonalInfoUploadStatus(StrEnum):
"""Batch Register PersonalInfo Upload Status"""

PENDING = "pending"
Expand Down
2 changes: 1 addition & 1 deletion app/model/db/bulk_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
SPDX-License-Identifier: Apache-2.0
"""

from sqlalchemy import BigInteger, Boolean, Integer, String
from sqlalchemy import BigInteger, Integer, String
from sqlalchemy.orm import Mapped, mapped_column

from .base import Base
Expand Down
6 changes: 3 additions & 3 deletions app/model/db/idx_issue_redeem.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"""

from datetime import datetime
from enum import Enum
from enum import StrEnum

from sqlalchemy import BigInteger, DateTime, String
from sqlalchemy.orm import Mapped, mapped_column
Expand Down Expand Up @@ -48,14 +48,14 @@ class IDXIssueRedeem(Base):
block_timestamp: Mapped[datetime | None] = mapped_column(DateTime)


class IDXIssueRedeemEventType(str, Enum):
class IDXIssueRedeemEventType(StrEnum):
"""Issue/Redeem event type"""

ISSUE = "Issue"
REDEEM = "Redeem"


class IDXIssueRedeemSortItem(str, Enum):
class IDXIssueRedeemSortItem(StrEnum):
"""Issue/Redeem sort item"""

BLOCK_TIMESTAMP = "block_timestamp"
Expand Down
4 changes: 2 additions & 2 deletions app/model/db/idx_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
"""

from datetime import datetime
from enum import Enum
from enum import StrEnum

from sqlalchemy import JSON, BigInteger, DateTime, String
from sqlalchemy.orm import Mapped, mapped_column

from .base import Base


class IDXTransferSourceEventType(str, Enum):
class IDXTransferSourceEventType(StrEnum):
"""Transfer source event type"""

TRANSFER = "Transfer"
Expand Down
4 changes: 2 additions & 2 deletions app/model/db/idx_transfer_approval.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"""

from datetime import datetime
from enum import Enum
from enum import StrEnum

from sqlalchemy import BigInteger, Boolean, DateTime, String
from sqlalchemy.orm import Mapped, mapped_column
Expand Down Expand Up @@ -85,7 +85,7 @@ def json(self):
}


class IDXTransferApprovalsSortItem(str, Enum):
class IDXTransferApprovalsSortItem(StrEnum):
ID = "id"
EXCHANGE_ADDRESS = "exchange_address"
APPLICATION_ID = "application_id"
Expand Down
4 changes: 2 additions & 2 deletions app/model/db/ledger_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
SPDX-License-Identifier: Apache-2.0
"""

from enum import Enum
from enum import StrEnum

from sqlalchemy import JSON, Integer, String
from sqlalchemy.orm import Mapped, mapped_column
Expand Down Expand Up @@ -66,6 +66,6 @@ class LedgerDetailsTemplate(Base):
data_source: Mapped[str | None] = mapped_column(String(42))


class LedgerDetailsDataType(str, Enum):
class LedgerDetailsDataType(StrEnum):
IBET_FIN = "ibetfin"
DB = "db"
4 changes: 2 additions & 2 deletions app/model/db/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
SPDX-License-Identifier: Apache-2.0
"""

from enum import Enum
from enum import StrEnum

from sqlalchemy import JSON, Integer, String
from sqlalchemy.orm import Mapped, mapped_column
Expand Down Expand Up @@ -92,7 +92,7 @@ class Notification(Base):
metainfo: Mapped[dict | None] = mapped_column(JSON)


class NotificationType(str, Enum):
class NotificationType(StrEnum):
ISSUE_ERROR = "IssueError"
BULK_TRANSFER_ERROR = "BulkTransferError"
BATCH_REGISTER_PERSONAL_INFO_ERROR = "BatchRegisterPersonalInfoError"
Expand Down
4 changes: 2 additions & 2 deletions app/model/db/scheduled_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#
# SPDX-License-Identifier: Apache-2.0
from datetime import datetime
from enum import Enum
from enum import StrEnum

from sqlalchemy import JSON, DateTime, Integer, String
from sqlalchemy.orm import Mapped, mapped_column
Expand Down Expand Up @@ -48,5 +48,5 @@ class ScheduledEvents(Base):
data: Mapped[dict] = mapped_column(JSON, nullable=False)


class ScheduledEventType(str, Enum):
class ScheduledEventType(StrEnum):
UPDATE = "Update"
4 changes: 2 additions & 2 deletions app/model/db/token.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
"""

from datetime import datetime
from enum import Enum, StrEnum
from enum import StrEnum

from sqlalchemy import JSON, Boolean, DateTime, Integer, String
from sqlalchemy.orm import Mapped, mapped_column

from .base import Base, naive_utcnow


class TokenType(str, Enum):
class TokenType(StrEnum):
IBET_STRAIGHT_BOND = "IbetStraightBond"
IBET_SHARE = "IbetShare"

Expand Down
4 changes: 2 additions & 2 deletions app/model/db/token_holders.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
SPDX-License-Identifier: Apache-2.0
"""

from enum import Enum
from enum import StrEnum

from sqlalchemy import BigInteger, String
from sqlalchemy.orm import Mapped, mapped_column
Expand All @@ -41,7 +41,7 @@ class TokenHoldersList(Base):
batch_status: Mapped[str | None] = mapped_column(String(256))


class TokenHolderBatchStatus(str, Enum):
class TokenHolderBatchStatus(StrEnum):
PENDING = "pending"
DONE = "done"
FAILED = "failed"
Expand Down
4 changes: 2 additions & 2 deletions app/model/db/transfer_appoval_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
SPDX-License-Identifier: Apache-2.0
"""

from enum import Enum
from enum import StrEnum
from typing import Optional

from sqlalchemy import JSON, BigInteger, String
Expand Down Expand Up @@ -59,6 +59,6 @@ def json(self):
}


class TransferApprovalOperationType(str, Enum):
class TransferApprovalOperationType(StrEnum):
APPROVE = "approve"
CANCEL = "cancel"
4 changes: 2 additions & 2 deletions app/model/schema/base/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
SPDX-License-Identifier: Apache-2.0
"""

from enum import Enum, IntEnum, StrEnum
from enum import IntEnum, StrEnum
from typing import Literal, Optional

from pydantic import BaseModel, Field, StringConstraints
Expand Down Expand Up @@ -53,7 +53,7 @@ class IbetShareContractVersion(StrEnum):
EMPTY_str = Literal[""]


class TokenType(str, Enum):
class TokenType(StrEnum):
IBET_STRAIGHT_BOND = "IbetStraightBond"
IBET_SHARE = "IbetShare"

Expand Down
2 changes: 0 additions & 2 deletions app/model/schema/bulk_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
SPDX-License-Identifier: Apache-2.0
"""

from typing import Optional

from pydantic import BaseModel, Field

from .base import TokenType
Expand Down
6 changes: 3 additions & 3 deletions app/model/schema/position.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
SPDX-License-Identifier: Apache-2.0
"""

from enum import Enum
from enum import StrEnum
from typing import Annotated, List, Optional

from fastapi import Query
Expand Down Expand Up @@ -58,7 +58,7 @@ class LockedPosition(BaseModel):
locked: int = Field(description="Locked amount")


class LockEventCategory(str, Enum):
class LockEventCategory(StrEnum):
Lock = "Lock"
Unlock = "Unlock"

Expand Down Expand Up @@ -88,7 +88,7 @@ class LockEvent(BaseModel):
############################


class ListAllLockEventsSortItem(str, Enum):
class ListAllLockEventsSortItem(StrEnum):
token_address = "token_address"
lock_address = "lock_address"
recipient_address = "recipient_address"
Expand Down
Loading
Loading