Skip to content

Commit

Permalink
Cleanup: Code did not respect black, isort and ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
hoh committed Jun 7, 2024
1 parent 991ae3c commit 1f3aa97
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 36 deletions.
4 changes: 3 additions & 1 deletion src/aleph_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@

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.")
raise ImportError(
f"The 'aleph_client.{name}' type is deprecated and has been removed from aleph_client. Please use `aleph.sdk.{name}` instead."
)
3 changes: 1 addition & 2 deletions src/aleph_client/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
Aleph Client command-line interface.
"""

from aleph_client.utils import AsyncTyper

from aleph_client.commands import (
about,
account,
Expand All @@ -15,6 +13,7 @@
node,
program,
)
from aleph_client.utils import AsyncTyper

app = AsyncTyper(no_args_is_help=True)

Expand Down
4 changes: 3 additions & 1 deletion src/aleph_client/commands/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ async def balance(
response = await session.get(uri)
if response.status == 200:
balance_data = await response.json()
formatted_balance_data = json.dumps(balance_data, indent=4, default=extended_json_encoder)
formatted_balance_data = json.dumps(
balance_data, indent=4, default=extended_json_encoder
)
typer.echo(formatted_balance_data)
else:
typer.echo(
Expand Down
4 changes: 3 additions & 1 deletion src/aleph_client/commands/aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ async def post(
inline=inline,
address=address,
)
log_message = json.dumps(message.dict(), indent=4, default=extended_json_encoder)
log_message = json.dumps(
message.dict(), indent=4, default=extended_json_encoder
)
typer.echo(log_message)


Expand Down
27 changes: 17 additions & 10 deletions src/aleph_client/commands/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
from aleph.sdk.exceptions import DomainConfigurationError
from aleph.sdk.query.filters import MessageFilter
from aleph.sdk.types import AccountFromPrivateKey
from aleph_client.commands import help_strings
from aleph_client.commands.utils import is_environment_interactive
from aleph_client.utils import AsyncTyper
from aleph_message.models import AggregateMessage, MessageType
from rich.console import Console
from rich.prompt import Confirm, Prompt
from rich.table import Table

from aleph_client.commands import help_strings
from aleph_client.commands.utils import is_environment_interactive
from aleph_client.utils import AsyncTyper

app = AsyncTyper(no_args_is_help=True)


Expand Down Expand Up @@ -83,7 +84,9 @@ async def attach_resource(
resource_type = await get_target_type(fqdn)

if resource_type == TargetType.IPFS and not catch_all_path:
catch_all_path = Prompt.ask("Catch all path? ex: /404.html or press [Enter] to ignore", default=None)
catch_all_path = Prompt.ask(
"Catch all path? ex: /404.html or press [Enter] to ignore", default=None
)

if domain_info is not None and domain_info.get("info"):
current_resource = domain_info["info"]["message_id"]
Expand All @@ -109,14 +112,12 @@ async def attach_resource(
"message_id": item_hash,
"type": resource_type,
# console page compatibility
"programType": resource_type
"programType": resource_type,
}
}

if catch_all_path and catch_all_path.startswith("/"):
aggregate_content[fqdn]["options"] = {
"catch_all_path": catch_all_path
}
aggregate_content[fqdn]["options"] = {"catch_all_path": catch_all_path}

aggregate_message, message_status = await client.create_aggregate(
key="domains", content=aggregate_content, channel="ALEPH-CLOUDSOLUTIONS"
Expand Down Expand Up @@ -276,14 +277,20 @@ async def attach(
item_hash: Optional[str] = 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),
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),
):
"""Attach resource to a Custom Domain."""
account: AccountFromPrivateKey = _load_account(private_key, private_key_file)

await attach_resource(
account, Hostname(fqdn), item_hash, interactive=False if (not ask) else None, catch_all_path=catch_all_path
account,
Hostname(fqdn),
item_hash,
interactive=False if (not ask) else None,
catch_all_path=catch_all_path,
)
raise typer.Exit()

Expand Down
4 changes: 3 additions & 1 deletion src/aleph_client/commands/help_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@
Requires at least a "ref" (message hash) and "mount" path. "use_latest" is True by default, to use the latest version of the volume, if it has been amended. See the docs for more info: https://docs.aleph.im/computing/volumes/immutable/\n
Example: --immutable-volume ref=25a393222692c2f73489dc6710ae87605a96742ceef7b91de4d7ec34bb688d94,mount=/lib/python3.8/site-packages"""
ASK_FOR_CONFIRMATION = "Prompt user for confirmation"
IPFS_CATCH_ALL_PATH = "Choose a relative path to catch all unmatched route or a 404 error"
IPFS_CATCH_ALL_PATH = (
"Choose a relative path to catch all unmatched route or a 404 error"
)
17 changes: 10 additions & 7 deletions src/aleph_client/commands/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,14 @@ def validate_ssh_pubkey_file(file: Union[str, Path]) -> Path:
}

rootfs = Prompt.ask(
f"Do you want to use a custom rootfs or one of the following prebuilt ones?",
"Do you want to use a custom rootfs or one of the following prebuilt ones?",
default=rootfs,
choices=[*os_map.values(), "custom"],
)

if rootfs == "custom":
rootfs = validated_prompt(
f"Enter the item hash of the rootfs to use for your instance",
"Enter the item hash of the rootfs to use for your instance",
lambda x: len(x) == 64,
)
else:
Expand All @@ -152,19 +152,22 @@ def validate_ssh_pubkey_file(file: Union[str, Path]) -> Path:
rootfs_size = rootfs_message.content.size

vcpus = validated_int_prompt(
f"Number of virtual cpus to allocate", vcpus, min_value=1, max_value=4
"Number of virtual cpus to allocate", vcpus, min_value=1, max_value=4
)

memory = validated_int_prompt(
f"Maximum memory allocation on vm in MiB", memory, min_value=2000, max_value=8000
"Maximum memory allocation on vm in MiB",
memory,
min_value=2000,
max_value=8000,
)

rootfs_size = validated_int_prompt(
f"Disk size in MiB", rootfs_size, min_value=20000, max_value=100000
"Disk size in MiB", rootfs_size, min_value=20000, max_value=100000
)

hypervisor = Prompt.ask(
f"Which hypervisor you want to use?",
"Which hypervisor you want to use?",
default=hypervisor,
choices=[*hv_map.values()],
)
Expand Down Expand Up @@ -291,7 +294,7 @@ async def _show_instances(messages: List[InstanceMessage]):
)
console = Console()
console.print(table)
console.print(f"To connect to an instance, use:\n\n" f" ssh root@<ipv6 address>\n")
console.print("To connect to an instance, use:\n\n" " ssh root@<ipv6 address>\n")


@app.command()
Expand Down
3 changes: 2 additions & 1 deletion src/aleph_client/commands/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
from aleph.sdk.query.responses import MessagesResponse
from aleph.sdk.types import AccountFromPrivateKey, StorageEnum
from aleph.sdk.utils import extended_json_encoder
from aleph_message.models import AlephMessage, ItemHash, MessageType, ProgramMessage

from aleph_client.commands import help_strings
from aleph_client.commands.utils import (
colorful_json,
Expand All @@ -25,7 +27,6 @@
str_to_datetime,
)
from aleph_client.utils import AsyncTyper
from aleph_message.models import AlephMessage, ItemHash, MessageType, ProgramMessage

app = AsyncTyper(no_args_is_help=True)

Expand Down
2 changes: 1 addition & 1 deletion src/aleph_client/commands/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging
import re
import unicodedata
from typing import Dict, List, Optional
from typing import Optional

import aiohttp
import typer
Expand Down
21 changes: 10 additions & 11 deletions src/aleph_client/commands/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@
from aleph.sdk.conf import settings as sdk_settings
from aleph.sdk.query.filters import MessageFilter
from aleph.sdk.types import AccountFromPrivateKey, StorageEnum
from aleph_message.models import (
ItemHash,
MessagesResponse,
ProgramContent,
ProgramMessage,
StoreMessage,
)
from aleph_message.status import MessageStatus

from aleph_client.commands import help_strings
from aleph_client.commands.utils import (
get_or_prompt_volumes,
Expand All @@ -20,14 +29,6 @@
)
from aleph_client.conf import settings
from aleph_client.utils import AsyncTyper, create_archive
from aleph_message.models import (
ItemHash,
MessagesResponse,
ProgramContent,
ProgramMessage,
StoreMessage,
)
from aleph_message.status import MessageStatus

logger = logging.getLogger(__name__)
app = AsyncTyper(no_args_is_help=True)
Expand Down Expand Up @@ -258,9 +259,7 @@ async def unpersist(
account=account, api_server=sdk_settings.API_HOST
) as client:
existing: MessagesResponse = await client.get_messages(
message_filter=MessageFilter(
hashes=[item_hash]
)
message_filter=MessageFilter(hashes=[item_hash])
)
message: ProgramMessage = existing.messages[0]
content: ProgramContent = message.content.copy()
Expand Down

0 comments on commit 1f3aa97

Please sign in to comment.