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

Enable ruff #276

Draft
wants to merge 7 commits into
base: lp-fix-most-ruff-errors
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ dependencies = [
[tool.hatch.envs.linting.scripts]
typing = "mypy {args:} ./src/ ./tests/"
style = [
# "ruff {args:}",
"ruff check {args:} ./src/ ./tests/",
"black --check --diff {args:} ./src/ ./tests/",
"isort --check-only --profile black {args:} ./src/ ./tests/",
]
fmt = [
"black {args:} ./src/ ./tests/",
# "ruff --fix {args:}",
"ruff --fix {args:}",
"isort --profile black {args:} ./src/ ./tests/",
"style",
]
Expand Down
6 changes: 4 additions & 2 deletions src/aleph_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

def __getattr__(name):
if name in moved_types:
raise ImportError(
f"The 'aleph_client.{name}' type is deprecated and has been removed from aleph_client. Please use `aleph.sdk.{name}` instead."
msg = (
f"The 'aleph_client.{name}' type is deprecated and has been removed from aleph_client. "
f"Please use `aleph.sdk.{name}` instead."
)
raise ImportError(msg)
25 changes: 12 additions & 13 deletions src/aleph_client/commands/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import logging
import sys
from pathlib import Path
from typing import Optional

import aiohttp
import typer
Expand All @@ -26,8 +25,8 @@

@app.command()
def create(
private_key: Optional[str] = typer.Option(None, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(None, help=help_strings.PRIVATE_KEY_FILE),
private_key: str | None = typer.Option(None, help=help_strings.PRIVATE_KEY),
private_key_file: Path | None = typer.Option(None, help=help_strings.PRIVATE_KEY_FILE),
replace: bool = False,
debug: bool = False,
):
Expand Down Expand Up @@ -62,8 +61,8 @@ def create(

@app.command()
def address(
private_key: Optional[str] = typer.Option(settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
private_key: str | None = typer.Option(settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Path | None = typer.Option(settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
):
"""
Display your public address.
Expand All @@ -81,8 +80,8 @@ def address(

@app.command()
def export_private_key(
private_key: Optional[str] = typer.Option(settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
private_key: str | None = typer.Option(settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Path | None = typer.Option(settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
):
"""
Display your private key.
Expand Down Expand Up @@ -110,9 +109,9 @@ def path():

@app.command("sign-bytes")
def sign_bytes(
message: Optional[str] = typer.Option(None, help="Message to sign"),
private_key: Optional[str] = typer.Option(settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
message: str | None = typer.Option(None, help="Message to sign"),
private_key: str | None = typer.Option(settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Path | None = typer.Option(settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
debug: bool = False,
):
"""Sign a message using your private key."""
Expand All @@ -132,9 +131,9 @@ def sign_bytes(

@app.command()
async def balance(
address: Optional[str] = typer.Option(None, help="Address"),
private_key: Optional[str] = typer.Option(settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
address: str | None = typer.Option(None, help="Address"),
private_key: str | None = typer.Option(settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Path | None = typer.Option(settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
):
account: AccountFromPrivateKey = _load_account(private_key, private_key_file)

Expand Down
27 changes: 13 additions & 14 deletions src/aleph_client/commands/aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import json
from pathlib import Path
from typing import Optional

import typer
from aleph.sdk.account import _load_account
Expand All @@ -23,10 +22,10 @@
@app.command()
async def forget(
key: str = typer.Argument(..., help="Aggregate item hash to be removed."),
reason: Optional[str] = typer.Option(None, help="A description of why the messages are being forgotten"),
channel: Optional[str] = typer.Option(default=settings.DEFAULT_CHANNEL, help=help_strings.CHANNEL),
private_key: Optional[str] = typer.Option(settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
reason: str | None = typer.Option(None, help="A description of why the messages are being forgotten"),
channel: str | None = typer.Option(default=settings.DEFAULT_CHANNEL, help=help_strings.CHANNEL),
private_key: str | None = typer.Option(settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Path | None = typer.Option(settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
debug: bool = False,
):
"""Forget all the messages composing an aggregate."""
Expand All @@ -52,12 +51,12 @@ async def forget(
async def post(
key: str = typer.Argument(..., help="Aggregate key to be created."),
content: str = typer.Argument(..., help="Aggregate content (ex : {'c': 3, 'd': 4})"),
address: Optional[str] = typer.Option(default=None, help="address"),
channel: Optional[str] = typer.Option(default=settings.DEFAULT_CHANNEL, help=help_strings.CHANNEL),
address: str | None = typer.Option(default=None, help="address"),
channel: str | None = typer.Option(default=settings.DEFAULT_CHANNEL, help=help_strings.CHANNEL),
inline: bool = typer.Option(False, help="inline"),
sync: bool = typer.Option(False, help="Sync response"),
private_key: Optional[str] = typer.Option(settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
private_key: str | None = typer.Option(settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Path | None = typer.Option(settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
debug: bool = False,
):
"""Create or Update aggregate"""
Expand All @@ -68,9 +67,9 @@ async def post(

try:
content_dict = json.loads(content)
except json.JSONDecodeError:
except json.JSONDecodeError as e:
typer.echo("Invalid JSON for content. Please provide valid JSON.")
raise typer.Exit(1)
raise typer.Exit(1) from e

async with AuthenticatedAlephHttpClient(account=account, api_server=settings.API_HOST) as client:
message, _ = await client.create_aggregate(
Expand All @@ -88,9 +87,9 @@ async def post(
@app.command()
async def get(
key: str = typer.Argument(..., help="Aggregate key to be fetched."),
address: Optional[str] = typer.Option(default=None, help="Address"),
private_key: Optional[str] = typer.Option(settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
address: str | None = typer.Option(default=None, help="Address"),
private_key: str | None = typer.Option(settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Path | None = typer.Option(settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
debug: bool = False,
):
"""Fetch an aggregate by key and content."""
Expand Down
41 changes: 22 additions & 19 deletions src/aleph_client/commands/domain.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from __future__ import annotations

import logging
from pathlib import Path
from time import sleep
from typing import Dict, Optional, cast
from typing import cast

import typer
from aleph.sdk.account import _load_account
Expand All @@ -28,6 +29,8 @@
from aleph_client.commands.utils import is_environment_interactive
from aleph_client.utils import AsyncTyper

logger = logging.getLogger(__name__)

app = AsyncTyper(no_args_is_help=True)


Expand Down Expand Up @@ -64,9 +67,9 @@ async def check_domain_records(fqdn, target, owner):
async def attach_resource(
account: AccountFromPrivateKey,
fqdn: Hostname,
item_hash: Optional[str] = None,
catch_all_path: Optional[str] = None,
interactive: Optional[bool] = None,
item_hash: str | None = None,
catch_all_path: str | None = None,
interactive: bool | None = None,
):
interactive = is_environment_interactive() if interactive is None else interactive

Expand Down Expand Up @@ -107,7 +110,7 @@ async def attach_resource(

async with AuthenticatedAlephHttpClient(account=account, api_server=settings.API_HOST) as client:

options: Optional[Dict] = None
options: dict | None = None
if catch_all_path and catch_all_path.startswith("/"):
options = {"catch_all_path": catch_all_path}

Expand All @@ -134,7 +137,7 @@ async def attach_resource(
)


async def detach_resource(account: AccountFromPrivateKey, fqdn: Hostname, interactive: Optional[bool] = None):
async def detach_resource(account: AccountFromPrivateKey, fqdn: Hostname, interactive: bool | None = None):
domain_info = await get_aggregate_domain_info(account, fqdn)
interactive = is_environment_interactive() if interactive is None else interactive

Expand Down Expand Up @@ -173,12 +176,12 @@ async def detach_resource(account: AccountFromPrivateKey, fqdn: Hostname, intera

@app.command()
async def add(
private_key: Optional[str] = typer.Option(settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
private_key: str | None = typer.Option(settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Path | None = typer.Option(settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
fqdn: str = typer.Argument(..., help=help_strings.CUSTOM_DOMAIN_NAME),
target: Optional[TargetType] = typer.Option(None, help=help_strings.CUSTOM_DOMAIN_TARGET_TYPES),
item_hash: Optional[str] = typer.Option(None, help=help_strings.CUSTOM_DOMAIN_ITEM_HASH),
owner: Optional[str] = typer.Option(None, help=help_strings.CUSTOM_DOMAIN_OWNER_ADDRESS),
target: TargetType | None = typer.Option(None, help=help_strings.CUSTOM_DOMAIN_TARGET_TYPES),
item_hash: str | None = typer.Option(None, help=help_strings.CUSTOM_DOMAIN_ITEM_HASH),
owner: str | None = typer.Option(None, help=help_strings.CUSTOM_DOMAIN_OWNER_ADDRESS),
ask: bool = typer.Option(default=True, help=help_strings.ASK_FOR_CONFIRMATION),
):
"""Add and link a Custom Domain."""
Expand Down Expand Up @@ -257,10 +260,10 @@ async def add(

@app.command()
async def attach(
private_key: Optional[str] = typer.Option(settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
private_key: str | None = typer.Option(settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Path | None = typer.Option(settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
fqdn: str = typer.Argument(..., help=help_strings.CUSTOM_DOMAIN_NAME),
item_hash: Optional[str] = typer.Option(None, help=help_strings.CUSTOM_DOMAIN_ITEM_HASH),
item_hash: str | None = typer.Option(None, help=help_strings.CUSTOM_DOMAIN_ITEM_HASH),
catch_all_path: str = typer.Option(default=None, help=help_strings.IPFS_CATCH_ALL_PATH),
ask: bool = typer.Option(default=True, help=help_strings.ASK_FOR_CONFIRMATION),
):
Expand All @@ -279,8 +282,8 @@ async def attach(

@app.command()
async def detach(
private_key: Optional[str] = typer.Option(settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
private_key: str | None = typer.Option(settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Path | None = typer.Option(settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
fqdn: str = typer.Argument(..., help=help_strings.CUSTOM_DOMAIN_NAME),
ask: bool = typer.Option(default=True, help=help_strings.ASK_FOR_CONFIRMATION),
):
Expand All @@ -293,8 +296,8 @@ async def detach(

@app.command()
async def info(
private_key: Optional[str] = typer.Option(settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
private_key: str | None = typer.Option(settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Path | None = typer.Option(settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
fqdn: str = typer.Argument(..., help=help_strings.CUSTOM_DOMAIN_NAME),
):
"""Show Custom Domain Details."""
Expand All @@ -318,7 +321,7 @@ async def info(
options = domain_info["info"].get("options")
if resource_type == TargetType.IPFS and options and "catch_all_path" in options:
table.add_column("Catch all path", justify="right", style="cyan", no_wrap=True)
print(domain_info)
logger.debug(domain_info)
table_values.append(domain_info["info"]["options"]["catch_all_path"])
elif resource_type == TargetType.PROGRAM:
table.add_column("Target resource", justify="right", style="cyan", no_wrap=True)
Expand Down
37 changes: 20 additions & 17 deletions src/aleph_client/commands/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import logging
from datetime import datetime
from pathlib import Path
from typing import Optional

import aiohttp
import typer
Expand All @@ -30,10 +29,10 @@
@app.command()
async def pin(
item_hash: str = typer.Argument(..., help="IPFS hash to pin on aleph.im"),
channel: Optional[str] = typer.Option(default=settings.DEFAULT_CHANNEL, help=help_strings.CHANNEL),
private_key: Optional[str] = typer.Option(settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
ref: Optional[str] = typer.Option(None, help=help_strings.REF),
channel: str | None = typer.Option(default=settings.DEFAULT_CHANNEL, help=help_strings.CHANNEL),
private_key: str | None = typer.Option(settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Path | None = typer.Option(settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
ref: str | None = typer.Option(None, help=help_strings.REF),
debug: bool = False,
):
"""Persist a file from IPFS on aleph.im."""
Expand All @@ -58,10 +57,10 @@ async def pin(
@app.command()
async def upload(
path: Path = typer.Argument(..., help="Path of the file to upload"),
channel: Optional[str] = typer.Option(default=settings.DEFAULT_CHANNEL, help=help_strings.CHANNEL),
private_key: Optional[str] = typer.Option(settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
ref: Optional[str] = typer.Option(None, help=help_strings.REF),
channel: str | None = typer.Option(default=settings.DEFAULT_CHANNEL, help=help_strings.CHANNEL),
private_key: str | None = typer.Option(settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Path | None = typer.Option(settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
ref: str | None = typer.Option(None, help=help_strings.REF),
debug: bool = False,
):
"""Upload and store a file on aleph.im."""
Expand Down Expand Up @@ -129,9 +128,9 @@ async def download(
async def forget(
item_hash: str = typer.Argument(..., help="Hash to forget"),
reason: str = typer.Argument("User deletion", help="reason to forget"),
channel: Optional[str] = typer.Option(default=settings.DEFAULT_CHANNEL, help=help_strings.CHANNEL),
private_key: Optional[str] = typer.Option(settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
channel: str | None = typer.Option(default=settings.DEFAULT_CHANNEL, help=help_strings.CHANNEL),
private_key: str | None = typer.Option(settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Path | None = typer.Option(settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
debug: bool = False,
):
"""forget a file and his message on aleph.im."""
Expand All @@ -154,7 +153,9 @@ class GetAccountFilesQueryParams(BaseModel):
page: int = Field(default=1, ge=1, description="Offset in pages. Starts at 1.")
sort_order: int = Field(
default=-1,
description="Order in which files should be listed: -1 means most recent messages first, 1 means older messages first.",
description=(
"Order in which files should be listed: -1 means most recent messages first, 1 means older messages first."
),
)


Expand Down Expand Up @@ -206,14 +207,16 @@ def _show_files(files_data: dict) -> None:

@app.command()
async def list(
address: Optional[str] = typer.Option(None, help="Address"),
private_key: Optional[str] = typer.Option(settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
address: str | None = typer.Option(None, help="Address"),
private_key: str | None = typer.Option(settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Path | None = typer.Option(settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
pagination: int = typer.Option(100, help="Maximum number of files to return."),
page: int = typer.Option(1, help="Offset in pages."),
sort_order: int = typer.Option(
-1,
help="Order in which files should be listed: -1 means most recent messages first, 1 means older messages first.",
help=(
"Order in which files should be listed: -1 means most recent messages first, 1 means older messages first."
),
),
json: bool = typer.Option(default=False, help="Print as json instead of rich table"),
):
Expand Down
Loading
Loading