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

refactor!: drop Python 3.8 & 3.9 #69

Merged
merged 3 commits into from
May 2, 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
2 changes: 1 addition & 1 deletion .github/workflows/prtitle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: "3.10"

- name: Install Dependencies
run: pip install commitizen
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
# TODO: Replace with macos-latest when works again.
# https://github.com/actions/setup-python/issues/808
os: [ubuntu-latest, macos-12] # eventually add `windows-latest`
python-version: [3.8, 3.9, "3.10", "3.11"]
python-version: ["3.10", "3.11"]

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Read the [development userguide](https://docs.apeworx.io/silverback/stable/userg

## Dependencies

- [python3](https://www.python.org/downloads) version 3.8 or greater, python3-dev
- [python3](https://www.python.org/downloads) version 3.10 or greater, python3-dev

## Installation

Expand Down
5 changes: 2 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import sys
from functools import lru_cache
from pathlib import Path
from typing import List

import requests
from semantic_version import Version # type: ignore
Expand Down Expand Up @@ -43,7 +42,7 @@
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns: List[str] = ["_build", ".DS_Store"]
exclude_patterns: list[str] = ["_build", ".DS_Store"]


# The suffix(es) of source filenames.
Expand Down Expand Up @@ -94,7 +93,7 @@ def fixpath(path: str) -> str:


@lru_cache(maxsize=None)
def get_versions() -> List[str]:
def get_versions() -> list[str]:
"""
Get all the versions from the Web.
"""
Expand Down
2 changes: 1 addition & 1 deletion example.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Annotated # NOTE: Only Python 3.9+
from typing import Annotated

from ape import chain
from ape.api import BlockAPI
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ write_to = "silverback/version.py"

[tool.black]
line-length = 100
target-version = ['py38', 'py39', 'py310', 'py311']
target-version = ['py310', 'py311']
include = '\.pyi?$'

[tool.pytest.ini_options]
Expand Down
6 changes: 2 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
include_package_data=True,
install_requires=[
"click", # Use same version as eth-ape
"eth-ape>=0.7.0,<1.0",
"eth-ape>=0.7,<1.0",
"ethpm-types>=0.6.10", # lower pin only, `eth-ape` governs upper pin
"eth-pydantic-types", # Use same version as eth-ape
"pydantic_settings", # Use same version as eth-ape
Expand All @@ -77,7 +77,7 @@
entry_points={
"console_scripts": ["silverback=silverback._cli:cli"],
},
python_requires=">=3.8,<4",
python_requires=">=3.10,<4",
extras_require=extras_require,
py_modules=["silverback"],
license="Apache-2.0",
Expand All @@ -93,8 +93,6 @@
"Operating System :: MacOS",
"Operating System :: POSIX",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
],
Expand Down
26 changes: 13 additions & 13 deletions silverback/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from collections import defaultdict
from dataclasses import dataclass
from datetime import timedelta
from typing import Callable, Dict, Optional, Union
from typing import Callable

from ape.api.networks import LOCAL_NETWORK_NAME
from ape.contracts import ContractEvent, ContractInstance
Expand All @@ -18,7 +18,7 @@

@dataclass
class TaskData:
container: Union[BlockContainer, ContractEvent, None]
container: BlockContainer | ContractEvent | None
fubuloubu marked this conversation as resolved.
Show resolved Hide resolved
handler: AsyncTaskiqDecoratedTask


Expand All @@ -35,12 +35,12 @@ class SilverbackApp(ManagerAccessMixin):
... # Connection has been initialized, can call broker methods e.g. `app.on_(...)`
"""

def __init__(self, settings: Optional[Settings] = None):
def __init__(self, settings: Settings | None = None):
"""
Create app

Args:
settings (Optional[~:class:`silverback.settings.Settings`]): Settings override.
settings (~:class:`silverback.settings.Settings` | None): Settings override.
Defaults to environment settings.
"""
if not settings:
Expand All @@ -62,7 +62,7 @@ def __init__(self, settings: Optional[Settings] = None):
self.broker = settings.get_broker()
# NOTE: If no tasks registered yet, defaults to empty list instead of raising KeyError
self.tasks: defaultdict[TaskType, list[TaskData]] = defaultdict(list)
self.poll_settings: Dict[str, Dict] = {}
self.poll_settings: dict[str, dict] = {}

atexit.register(self.network.__exit__, None, None, None)

Expand All @@ -84,14 +84,14 @@ def __init__(self, settings: Optional[Settings] = None):
def broker_task_decorator(
self,
task_type: TaskType,
container: Union[BlockContainer, ContractEvent, None] = None,
container: BlockContainer | ContractEvent | None = None,
) -> Callable[[Callable], AsyncTaskiqDecoratedTask]:
"""
Dynamically create a new broker task that handles tasks of ``task_type``.

Args:
task_type: :class:`~silverback.types.TaskType`: The type of task to create.
container: (Union[BlockContainer, ContractEvent]): The event source to watch.
container: (BlockContainer | ContractEvent): The event source to watch.

Returns:
Callable[[Callable], :class:`~taskiq.AsyncTaskiqDecoratedTask`]:
Expand Down Expand Up @@ -187,18 +187,18 @@ def do_something_on_shutdown(state):

def on_(
self,
container: Union[BlockContainer, ContractEvent],
new_block_timeout: Optional[int] = None,
start_block: Optional[int] = None,
container: BlockContainer | ContractEvent,
new_block_timeout: int | None = None,
start_block: int | None = None,
):
"""
Create task to handle events created by `container`.

Args:
container: (Union[BlockContainer, ContractEvent]): The event source to watch.
new_block_timeout: (Optional[int]): Override for block timeout that is acceptable.
container: (BlockContainer | ContractEvent): The event source to watch.
new_block_timeout: (int | None): Override for block timeout that is acceptable.
Defaults to whatever the app's settings are for default polling timeout are.
start_block (Optional[int]): block number to start processing events from.
start_block (int | None): block number to start processing events from.
Defaults to whatever the latest block is.

Raises:
Expand Down
28 changes: 14 additions & 14 deletions silverback/recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sqlite3
from abc import ABC, abstractmethod
from datetime import datetime, timezone
from typing import Optional, TypeVar
from typing import TypeVar

from pydantic import BaseModel
from taskiq import TaskiqResult
Expand All @@ -28,17 +28,17 @@ class HandlerResult(TaskiqResult):
instance: str
network: str
handler_id: str
block_number: Optional[int]
log_index: Optional[int]
block_number: int | None
log_index: int | None
created: datetime

@classmethod
def from_taskiq(
cls,
ident: SilverbackID,
handler_id: str,
block_number: Optional[int],
log_index: Optional[int],
block_number: int | None,
log_index: int | None,
result: TaskiqResult,
) -> Self:
return cls(
Expand All @@ -59,21 +59,21 @@ async def init(self):
...

@abstractmethod
async def get_state(self, ident: SilverbackID) -> Optional[SilverbackState]:
async def get_state(self, ident: SilverbackID) -> SilverbackState | None:
"""Return the stored state for a Silverback instance"""
...

@abstractmethod
async def set_state(
self, ident: SilverbackID, last_block_seen: int, last_block_processed: int
) -> Optional[SilverbackState]:
) -> SilverbackState | None:
"""Set the stored state for a Silverback instance"""
...

@abstractmethod
async def get_latest_result(
self, ident: SilverbackID, handler: Optional[str] = None
) -> Optional[HandlerResult]:
self, ident: SilverbackID, handler: str | None = None
) -> HandlerResult | None:
"""Return the latest result for a Silverback instance's handler"""
...

Expand Down Expand Up @@ -136,7 +136,7 @@ class SQLiteRecorder(BaseRecorder):
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);
"""

con: Optional[sqlite3.Connection]
con: sqlite3.Connection | None
initialized: bool = False

async def init(self):
Expand Down Expand Up @@ -182,7 +182,7 @@ async def init(self):

self.initialized = True

async def get_state(self, ident: SilverbackID) -> Optional[SilverbackState]:
async def get_state(self, ident: SilverbackID) -> SilverbackState | None:
if not self.initialized:
await self.init()

Expand Down Expand Up @@ -210,7 +210,7 @@ async def get_state(self, ident: SilverbackID) -> Optional[SilverbackState]:

async def set_state(
self, ident: SilverbackID, last_block_seen: int, last_block_processed: int
) -> Optional[SilverbackState]:
) -> SilverbackState | None:
if not self.initialized:
await self.init()

Expand Down Expand Up @@ -261,8 +261,8 @@ async def set_state(
)

async def get_latest_result(
self, ident: SilverbackID, handler: Optional[str] = None
) -> Optional[HandlerResult]:
self, ident: SilverbackID, handler: str | None = None
) -> HandlerResult | None:
if not self.initialized:
await self.init()

Expand Down
5 changes: 2 additions & 3 deletions silverback/runner.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import asyncio
from abc import ABC, abstractmethod
from typing import Optional, Tuple

from ape import chain
from ape.contracts import ContractEvent, ContractInstance
Expand Down Expand Up @@ -28,7 +27,7 @@ def __init__(self, app: SilverbackApp, *args, max_exceptions: int = 3, **kwargs)
self.exceptions = 0
self.last_block_seen = 0
self.last_block_processed = 0
self.recorder: Optional[BaseRecorder] = None
self.recorder: BaseRecorder | None = None
self.ident = SilverbackID.from_settings(settings)

def _handle_result(self, result: TaskiqResult):
Expand All @@ -43,7 +42,7 @@ def _handle_result(self, result: TaskiqResult):

async def _checkpoint(
self, last_block_seen: int = 0, last_block_processed: int = 0
) -> Tuple[int, int]:
) -> tuple[int, int]:
"""Set latest checkpoint block number"""
if (
last_block_seen > self.last_block_seen
Expand Down
Loading
Loading