Skip to content

Commit

Permalink
style: hatch run linting:fmt + manual fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Psycojoker committed Jul 11, 2024
1 parent bb7d42e commit d40c1f5
Show file tree
Hide file tree
Showing 170 changed files with 888 additions and 929 deletions.
2 changes: 1 addition & 1 deletion deployment/migrations/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
fileConfig(config.config_file_name)

# Auto-generate migrations
from aleph.db.models import Base
from aleph.db.models import Base # noqa

target_metadata = Base.metadata

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = "eef5f95853bf"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = "8edf69c47884"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import asyncio
import logging
from threading import Thread
from time import sleep

import aioipfs
from alembic import op
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"""
from alembic import op
import sqlalchemy as sa


revision = 'e682fc8f9506'
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ dependencies = [
[tool.hatch.envs.linting.scripts]
typing = "mypy --config-file=pyproject.toml {args:} ./src/ ./tests/"
style = [
"ruff check {args:.} ./src/ ./tests/",
"ruff check {args:.}",
"black --check --diff {args:} ./src/ ./tests/",
"isort --check-only --profile black {args:} ./src/ ./tests/",
]
Expand Down
2 changes: 1 addition & 1 deletion src/aleph/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
import subprocess

from pkg_resources import get_distribution, DistributionNotFound
from pkg_resources import DistributionNotFound, get_distribution


def _get_git_version() -> str:
Expand Down
13 changes: 6 additions & 7 deletions src/aleph/api_entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,34 @@
from aleph.db.connection import make_engine, make_session_factory
from aleph.services.cache.node_cache import NodeCache
from aleph.services.ipfs import IpfsService
from aleph.services.ipfs.common import make_ipfs_client
from aleph.services.p2p import init_p2p_client
from aleph.services.storage.fileystem_engine import FileSystemStorageEngine
from aleph.storage import StorageService
from aleph.toolkit.monitoring import setup_sentry
from aleph.web import create_aiohttp_app
from aleph.web.controllers.app_state_getters import (
APP_STATE_CONFIG,
APP_STATE_MQ_CHANNEL,
APP_STATE_MQ_CONN,
APP_STATE_MQ_WS_CHANNEL,
APP_STATE_NODE_CACHE,
APP_STATE_P2P_CLIENT,
APP_STATE_SESSION_FACTORY,
APP_STATE_STORAGE_SERVICE,
APP_STATE_MQ_CHANNEL,
APP_STATE_MQ_WS_CHANNEL,
APP_STATE_SIGNATURE_VERIFIER,
APP_STATE_STORAGE_SERVICE,
)


async def configure_aiohttp_app(
config: Config,
) -> web.Application:
with sentry_sdk.start_transaction(name=f"init-api-server"):
p2p_client = await init_p2p_client(config, service_name=f"api-server-aiohttp")
with sentry_sdk.start_transaction(name="init-api-server"):
p2p_client = await init_p2p_client(config, service_name="api-server-aiohttp")

engine = make_engine(
config,
echo=config.logging.level.value == logging.DEBUG,
application_name=f"aleph-api",
application_name="aleph-api",
)
session_factory = make_session_factory(engine)

Expand Down
10 changes: 3 additions & 7 deletions src/aleph/chains/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,18 @@
from configmanager import Config

from aleph.schemas.pending_messages import BasePendingMessage
from aleph.types.chain_sync import ChainEventType


class Verifier(abc.ABC):
@abc.abstractmethod
async def verify_signature(self, message: BasePendingMessage) -> bool:
...
async def verify_signature(self, message: BasePendingMessage) -> bool: ...


class ChainReader(abc.ABC):
@abc.abstractmethod
async def fetcher(self, config: Config):
...
async def fetcher(self, config: Config): ...


class ChainWriter(ChainReader):
@abc.abstractmethod
async def packer(self, config: Config):
...
async def packer(self, config: Config): ...
3 changes: 2 additions & 1 deletion src/aleph/chains/avalanche.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from aleph.chains.common import get_verification_buffer
from aleph.schemas.pending_messages import BasePendingMessage

from .abc import Verifier

LOGGER = logging.getLogger("chains.avalanche")
Expand Down Expand Up @@ -86,7 +87,7 @@ async def verify_signature(self, message: BasePendingMessage) -> bool:

result = address == message.sender

except Exception as e:
except Exception:
LOGGER.exception("Error processing signature for %s" % message.sender)
result = False

Expand Down
15 changes: 7 additions & 8 deletions src/aleph/chains/chain_data_service.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
import asyncio
from io import StringIO
from typing import Dict, Optional, List, Any, Mapping, Set, cast, Type, Union, Self
from typing import Any, Dict, List, Mapping, Optional, Self, Set, Type, Union, cast

import aio_pika.abc
from aleph_message.models import StoreContent, ItemType, Chain, MessageType
from aleph_message.models import Chain, ItemType, MessageType, StoreContent
from configmanager import Config
from pydantic import ValidationError

from aleph.chains.common import LOGGER
from aleph.config import get_config
from aleph.db.accessors.chains import upsert_chain_tx
from aleph.db.accessors.files import upsert_tx_file_pin, upsert_file
from aleph.db.accessors.files import upsert_file, upsert_tx_file_pin
from aleph.db.accessors.pending_txs import upsert_pending_tx
from aleph.db.models import ChainTxDb, MessageDb
from aleph.exceptions import (
InvalidContent,
AlephStorageException,
ContentCurrentlyUnavailable,
InvalidContent,
)
from aleph.schemas.chains.indexer_response import MessageEvent, GenericMessageEvent
from aleph.schemas.chains.indexer_response import GenericMessageEvent, MessageEvent
from aleph.schemas.chains.sync_events import (
OffChainSyncEventPayload,
OnChainSyncEventPayload,
OnChainContent,
OnChainMessage,
OnChainSyncEventPayload,
)
from aleph.schemas.chains.tezos_indexer_response import (
MessageEventPayload as TezosMessageEventPayload,
)
from aleph.storage import StorageService
from aleph.toolkit.timestamp import utc_now
from aleph.types.chain_sync import ChainSyncProtocol
from aleph.types.db_session import DbSessionFactory, DbSession
from aleph.types.db_session import DbSession, DbSessionFactory
from aleph.types.files import FileType
from aleph.utils import get_sha256

Expand Down
4 changes: 1 addition & 3 deletions src/aleph/chains/common.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import logging

from aleph.schemas.pending_messages import (
BasePendingMessage,
)
from aleph.schemas.pending_messages import BasePendingMessage

LOGGER = logging.getLogger("chains.common")

Expand Down
1 change: 1 addition & 0 deletions src/aleph/chains/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from configmanager import Config

from aleph.types.db_session import DbSessionFactory

from .abc import ChainReader, ChainWriter
from .bsc import BscConnector
from .chain_data_service import ChainDataService, PendingTxPublisher
Expand Down
1 change: 1 addition & 0 deletions src/aleph/chains/cosmos.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from aleph.chains.common import get_verification_buffer
from aleph.schemas.pending_messages import BasePendingMessage

from .abc import Verifier

LOGGER = logging.getLogger("chains.cosmos")
Expand Down
3 changes: 2 additions & 1 deletion src/aleph/chains/ethereum.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from aleph.types.chain_sync import ChainEventType
from aleph.types.db_session import DbSessionFactory
from aleph.utils import run_in_executor

from .abc import ChainWriter, Verifier
from .chain_data_service import ChainDataService, PendingTxPublisher
from .indexer_reader import AlephIndexerReader
Expand Down Expand Up @@ -94,7 +95,7 @@ async def verify_signature(self, message: BasePendingMessage) -> bool:
)
return False

except Exception as e:
except Exception:
LOGGER.exception("Error processing signature for %s" % message.sender)
verified = False

Expand Down
18 changes: 9 additions & 9 deletions src/aleph/chains/indexer_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
import logging
from dataclasses import dataclass
from typing import (
Mapping,
Any,
Dict,
Iterable,
List,
Mapping,
Optional,
Tuple,
TypeVar,
Type,
TypeVar,
Union,
Dict,
Any,
Iterable,
)

import aiohttp
Expand All @@ -23,22 +23,22 @@
import aleph.toolkit.json as aleph_json
from aleph.chains.chain_data_service import PendingTxPublisher
from aleph.db.accessors.chains import (
get_missing_indexer_datetime_multirange,
add_indexer_range,
get_missing_indexer_datetime_multirange,
)
from aleph.db.models import ChainTxDb
from aleph.schemas.chains.indexer_response import (
EntityType,
IndexerBlockchain,
IndexerAccountStateResponse,
IndexerBlockchain,
IndexerEventResponse,
MessageEvent,
SyncEvent,
)
from aleph.toolkit.range import Range, MultiRange
from aleph.toolkit.range import MultiRange, Range
from aleph.toolkit.timestamp import timestamp_to_datetime
from aleph.types.chain_sync import ChainEventType, ChainSyncProtocol
from aleph.types.db_session import DbSessionFactory, DbSession
from aleph.types.db_session import DbSession, DbSessionFactory

LOGGER = logging.getLogger(__name__)

Expand Down
12 changes: 6 additions & 6 deletions src/aleph/chains/nuls.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import logging
import struct

from aleph.chains.common import get_verification_buffer
from aleph.schemas.pending_messages import BasePendingMessage
from aleph.utils import run_in_executor

from .abc import Verifier
from .nuls_aleph_sdk import (
NulsSignature,
address_from_hash,
hash_from_address,
public_key_to_hash,
address_from_hash,
)

from aleph.chains.common import get_verification_buffer
from aleph.schemas.pending_messages import BasePendingMessage
from aleph.utils import run_in_executor
from .abc import Verifier

LOGGER = logging.getLogger("chains.nuls")
CHAIN_NAME = "NULS"

Expand Down
11 changes: 6 additions & 5 deletions src/aleph/chains/nuls2.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
from configmanager import Config
from nuls2.api.server import get_server
from nuls2.model.data import (
CHEAP_UNIT_FEE,
get_address,
hash_from_address,
recover_message_address,
get_address,
CHEAP_UNIT_FEE,
)
from nuls2.model.transaction import Transaction

Expand All @@ -26,15 +26,16 @@
from aleph.db.accessors.messages import get_unconfirmed_messages
from aleph.db.accessors.pending_messages import count_pending_messages
from aleph.db.accessors.pending_txs import count_pending_txs
from aleph.schemas.chains.tx_context import TxContext
from aleph.schemas.pending_messages import BasePendingMessage
from aleph.toolkit.timestamp import utc_now
from aleph.types.db_session import DbSessionFactory
from aleph.utils import run_in_executor
from .chain_data_service import ChainDataService, PendingTxPublisher
from .abc import Verifier, ChainWriter
from aleph.schemas.chains.tx_context import TxContext

from ..db.models import ChainTxDb
from ..types.chain_sync import ChainEventType
from .abc import ChainWriter, Verifier
from .chain_data_service import ChainDataService, PendingTxPublisher

LOGGER = logging.getLogger("chains.nuls2")
CHAIN_NAME = "NULS2"
Expand Down
Loading

0 comments on commit d40c1f5

Please sign in to comment.