Skip to content
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
9 changes: 7 additions & 2 deletions .github/workflows/test-pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,15 @@ jobs:
- name: Cache the image on GitHub's repository
run: docker tag aleph-client:${GITHUB_REF##*/} docker.pkg.github.com/$GITHUB_REPOSITORY/aleph-client-build-cache && docker push docker.pkg.github.com/$GITHUB_REPOSITORY/aleph-client-build-cache || true

- name: Pytest in the Docker image
- name: Black in the Docker image
run: |
docker run --entrypoint /opt/venv/bin/pytest aleph-client:${GITHUB_REF##*/} /opt/aleph-client/
docker run --entrypoint /opt/venv/bin/black aleph-client:${GITHUB_REF##*/} --check /opt/aleph-client/src

- name: MyPy in the Docker image
run: |
docker run --entrypoint /opt/venv/bin/mypy aleph-client:${GITHUB_REF##*/} --config-file /opt/aleph-client/mypy.ini /opt/aleph-client/src/ /opt/aleph-client/tests/ /opt/aleph-client/examples/

- name: Pytest in the Docker image
run: |
docker run --entrypoint /opt/venv/bin/pytest aleph-client:${GITHUB_REF##*/} /opt/aleph-client/

1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ testing =
requests
aleph-pytezos==0.1.0
types-setuptools
black
mqtt =
aiomqtt
certifi
Expand Down
5 changes: 2 additions & 3 deletions src/aleph_client/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@
aggregate.app, name="aggregate", help="Manage aggregate messages on Aleph.im"
)

app.add_typer(
account.app, name="account", help="Manage account"
)
app.add_typer(account.app, name="account", help="Manage account")


@app.command()
def whoami(
Expand Down
1 change: 0 additions & 1 deletion src/aleph_client/chains/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ def get_fallback_private_key(path: Optional[Path] = None) -> bytes:
with open(path, "rb") as prvfile:
print(prvfile.read())


default_key_path = path.parent / "default.key"
if not default_key_path.is_symlink():
# Create a symlink to use this key by default
Expand Down
2 changes: 0 additions & 2 deletions src/aleph_client/chains/sol.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,8 @@ def get_fallback_private_key(path: Optional[Path] = None) -> bytes:
with open(path, "rb") as prvfile:
print(prvfile.read())


default_key_path = path.parent / "default.key"
if not default_key_path.is_symlink():
# Create a symlink to use this key by default
os.symlink(path, default_key_path)
return private_key

8 changes: 4 additions & 4 deletions src/aleph_client/commands/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@

@app.command()
def create(
from_private_key: Optional[str] = typer.Option(
None, help=help_strings.PRIVATE_KEY
),
from_private_key: Optional[str] = typer.Option(None, help=help_strings.PRIVATE_KEY),
debug: bool = False,
):
"""Create or import a private key."""

setup_logging(debug)

typer.echo("Generating private key file.")
private_key_file = typer.prompt("Enter file in which to save the key", settings.PRIVATE_KEY_FILE)
private_key_file = typer.prompt(
"Enter file in which to save the key", settings.PRIVATE_KEY_FILE
)

if os.path.exists(private_key_file):
typer.echo(f"Error: key already exists: '{private_key_file}'")
Expand Down
88 changes: 44 additions & 44 deletions src/aleph_client/commands/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@

@app.command()
def post(
path: Optional[Path] = typer.Option(
None,
help="Path to the content you want to post. If omitted, you can input your content directly",
),
type: str = typer.Option("test", help="Text representing the message object type"),
ref: Optional[str] = typer.Option(None, help=help_strings.REF),
channel: str = typer.Option(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
),
debug: bool = False,
path: Optional[Path] = typer.Option(
None,
help="Path to the content you want to post. If omitted, you can input your content directly",
),
type: str = typer.Option("test", help="Text representing the message object type"),
ref: Optional[str] = typer.Option(None, help=help_strings.REF),
channel: str = typer.Option(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
),
debug: bool = False,
):
"""Post a message on Aleph.im."""

Expand Down Expand Up @@ -96,14 +96,14 @@ def post(

@app.command()
def amend(
hash: str = typer.Argument(..., help="Hash reference of the message to amend"),
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
),
debug: bool = False,
hash: str = typer.Argument(..., help="Hash reference of the message to amend"),
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
),
debug: bool = False,
):
"""Amend an existing Aleph message."""

Expand Down Expand Up @@ -141,10 +141,10 @@ def amend(


def forget_messages(
account: AccountFromPrivateKey,
hashes: List[str],
reason: Optional[str],
channel: str,
account: AccountFromPrivateKey,
hashes: List[str],
reason: Optional[str],
channel: str,
):
try:
result: ForgetMessage = synchronous.forget(
Expand All @@ -161,20 +161,20 @@ def forget_messages(

@app.command()
def forget(
hashes: str = typer.Argument(
..., help="Comma separated list of hash references of messages to forget"
),
reason: Optional[str] = typer.Option(
None, help="A description of why the messages are being forgotten."
),
channel: str = typer.Option(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
),
debug: bool = False,
hashes: str = typer.Argument(
..., help="Comma separated list of hash references of messages to forget"
),
reason: Optional[str] = typer.Option(
None, help="A description of why the messages are being forgotten."
),
channel: str = typer.Option(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
),
debug: bool = False,
):
"""Forget an existing Aleph message."""

Expand All @@ -188,9 +188,9 @@ def forget(

@app.command()
def watch(
ref: str = typer.Argument(..., help="Hash reference of the message to watch"),
indent: Optional[int] = typer.Option(None, help="Number of indents to use"),
debug: bool = False,
ref: str = typer.Argument(..., help="Hash reference of the message to watch"),
indent: Optional[int] = typer.Option(None, help="Number of indents to use"),
debug: bool = False,
):
"""Watch a hash for amends and print amend hashes"""

Expand All @@ -199,6 +199,6 @@ def watch(
original: AlephMessage = synchronous.get_message(item_hash=ref)

for message in synchronous.watch_messages(
refs=[ref], addresses=[original.content.address]
refs=[ref], addresses=[original.content.address]
):
typer.echo(f"{message.json(indent=indent)}")
124 changes: 62 additions & 62 deletions src/aleph_client/commands/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,62 +36,58 @@

@app.command()
def upload(
path: Path = typer.Argument(..., help="Path to your source code"),
entrypoint: str = typer.Argument(..., help="Your program entrypoint"),
channel: str = typer.Option(settings.DEFAULT_CHANNEL, help=help_strings.CHANNEL),
memory: int = typer.Option(
settings.DEFAULT_VM_MEMORY, help="Maximum memory allocation on vm in MiB"
),
vcpus: int = typer.Option(
settings.DEFAULT_VM_VCPUS, help="Number of virtual cpus to allocate."
),
timeout_seconds: float = typer.Option(
settings.DEFAULT_VM_TIMEOUT,
help="If vm is not called after [timeout_seconds] it will shutdown",
),
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
),
print_messages: bool = typer.Option(False),
print_code_message: bool = typer.Option(False),
print_program_message: bool = typer.Option(False),
runtime: str = typer.Option(
None,
help="Hash of the runtime to use for your program. Defaults to aleph debian with Python3.8 and node. You can also create your own runtime and pin it",
),
beta: bool = typer.Option(False),

debug: bool = False,
persistent: bool = False,
persistent_volume: Optional[List[str]] = typer.Option(
None,
help='''Takes 3 parameters
path: Path = typer.Argument(..., help="Path to your source code"),
entrypoint: str = typer.Argument(..., help="Your program entrypoint"),
channel: str = typer.Option(settings.DEFAULT_CHANNEL, help=help_strings.CHANNEL),
memory: int = typer.Option(
settings.DEFAULT_VM_MEMORY, help="Maximum memory allocation on vm in MiB"
),
vcpus: int = typer.Option(
settings.DEFAULT_VM_VCPUS, help="Number of virtual cpus to allocate."
),
timeout_seconds: float = typer.Option(
settings.DEFAULT_VM_TIMEOUT,
help="If vm is not called after [timeout_seconds] it will shutdown",
),
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
),
print_messages: bool = typer.Option(False),
print_code_message: bool = typer.Option(False),
print_program_message: bool = typer.Option(False),
runtime: str = typer.Option(
None,
help="Hash of the runtime to use for your program. Defaults to aleph debian with Python3.8 and node. You can also create your own runtime and pin it",
),
beta: bool = typer.Option(False),
debug: bool = False,
persistent: bool = False,
persistent_volume: Optional[List[str]] = typer.Option(
None,
help="""Takes 3 parameters
A persistent volume is allocated on the host machine at any time
eg: Use , to seperate the parameters and no spaces
--persistent_volume persistence=host,name=my-volume,size=100 ./my-program main:app
'''),

ephemeral_volume: Optional[List[str]] = typer.Option(
None,
help=
'''Takes 1 parameter Only
""",
),
ephemeral_volume: Optional[List[str]] = typer.Option(
None,
help="""Takes 1 parameter Only
Ephemeral volumes can move and be removed by the host,Garbage collected basically, when the VM isn't running
eg: Use , to seperate the parameters and no spaces
--ephemeral-volume size_mib=100 ./my-program main:app '''),

immutable_volume: Optional[List[str]] = typer.Option(
None,
help=
'''Takes 3 parameters
--ephemeral-volume size_mib=100 ./my-program main:app """,
),
immutable_volume: Optional[List[str]] = typer.Option(
None,
help="""Takes 3 parameters
Immutable volume is one whose contents do not change
eg: Use , to seperate the parameters and no spaces
--immutable-volume ref=25a393222692c2f73489dc6710ae87605a96742ceef7b91de4d7ec34bb688d94,use_latest=true,mount=/mnt/volume ./my-program main:app
'''
)

""",
),
):
"""Register a program to run on Aleph.im virtual machines from a zip archive."""

Expand All @@ -111,15 +107,19 @@ def upload(
account: AccountFromPrivateKey = _load_account(private_key, private_key_file)

runtime = (
runtime
or input(f"Ref of runtime ? [{settings.DEFAULT_RUNTIME_ID}] ")
or settings.DEFAULT_RUNTIME_ID
runtime
or input(f"Ref of runtime ? [{settings.DEFAULT_RUNTIME_ID}] ")
or settings.DEFAULT_RUNTIME_ID
)

volumes = []

# Check if the volumes are empty
if persistent_volume is None or ephemeral_volume is None or immutable_volume is None:
if (
persistent_volume is None
or ephemeral_volume is None
or immutable_volume is None
):
for volume in prompt_for_volumes():
volumes.append(volume)
typer.echo("\n")
Expand Down Expand Up @@ -211,12 +211,12 @@ def upload(

@app.command()
def update(
hash: str,
path: Path,
private_key: Optional[str] = settings.PRIVATE_KEY_STRING,
private_key_file: Optional[Path] = settings.PRIVATE_KEY_FILE,
print_message: bool = True,
debug: bool = False,
hash: str,
path: Path,
private_key: Optional[str] = settings.PRIVATE_KEY_STRING,
private_key_file: Optional[Path] = settings.PRIVATE_KEY_FILE,
print_message: bool = True,
debug: bool = False,
):
"""Update the code of an existing program"""

Expand Down Expand Up @@ -274,10 +274,10 @@ def update(

@app.command()
def unpersist(
hash: str,
private_key: Optional[str] = settings.PRIVATE_KEY_STRING,
private_key_file: Optional[Path] = settings.PRIVATE_KEY_FILE,
debug: bool = False,
hash: str,
private_key: Optional[str] = settings.PRIVATE_KEY_STRING,
private_key_file: Optional[Path] = settings.PRIVATE_KEY_FILE,
debug: bool = False,
):
"""Stop a persistent virtual machine by making it non-persistent"""

Expand Down
3 changes: 1 addition & 2 deletions src/aleph_client/commands/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,9 @@ def volume_to_dict(volume: List[str]) -> Optional[Dict[str, Union[str, int]]]:
p = param.split("=")
if p[1].isdigit():
dict_store[p[0]] = int(p[1])
elif p[1] in ['True', 'true', 'False', 'false']:
elif p[1] in ["True", "true", "False", "false"]:
dict_store[p[0]] = bool(p[1].capitalize())
else:
dict_store[p[0]] = p[1]

return dict_store

Loading