Skip to content

Commit

Permalink
Wrapper for async CLI commands (#105)
Browse files Browse the repository at this point in the history
* wrapper for async download cli

* wrapper for async upload cli

* version bump
  • Loading branch information
dontseyit authored Oct 1, 2024
1 parent 8485a7e commit 94b9452
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .pyproject_generation/pyproject_custom.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "ghga_connector"
version = "1.5.0"
version = "1.5.1"
description = "GHGA Connector - A CLI client application for interacting with the GHGA system."
dependencies = [
"typer~=0.12",
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ We recommend using the provided Docker container.

A pre-build version is available at [docker hub](https://hub.docker.com/repository/docker/ghga/ghga-connector):
```bash
docker pull ghga/ghga-connector:1.5.0
docker pull ghga/ghga-connector:1.5.1
```

Or you can build the container yourself from the [`./Dockerfile`](./Dockerfile):
```bash
# Execute in the repo's root dir:
docker build -t ghga/ghga-connector:1.5.0 .
docker build -t ghga/ghga-connector:1.5.1 .
```

For production-ready deployment, we recommend using Kubernetes, however,
for simple use cases, you could execute the service using docker
on a single server:
```bash
# The entrypoint is preconfigured:
docker run -p 8080:8080 ghga/ghga-connector:1.5.0 --help
docker run -p 8080:8080 ghga/ghga-connector:1.5.1 --help
```

If you prefer not to use containers, you may install the service from source:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ classifiers = [
"Intended Audience :: Developers",
]
name = "ghga_connector"
version = "1.5.0"
version = "1.5.1"
description = "GHGA Connector - A CLI client application for interacting with the GHGA system."
dependencies = [
"typer~=0.12",
Expand Down
34 changes: 30 additions & 4 deletions src/ghga_connector/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#
"""CLI-specific wrappers around core functions."""

import asyncio
import os
import sys
from dataclasses import dataclass
Expand Down Expand Up @@ -181,7 +182,7 @@ def get_work_package_information(
cli = typer.Typer(no_args_is_help=True)


async def upload(
def upload(
*,
file_id: str = typer.Option(..., help="The id of the file to upload"),
file_path: Path = typer.Option(..., help="The path to the file to upload"),
Expand All @@ -199,7 +200,20 @@ async def upload(
False, help="Set this option in order to view traceback for errors."
),
):
"""Command to upload a file"""
"""Wrapper for the async upload function"""
asyncio.run(
async_upload(file_id, file_path, my_public_key_path, my_private_key_path, debug)
)


async def async_upload(
file_id: str,
file_path: Path,
my_public_key_path: Path,
my_private_key_path: Path,
debug: bool = False,
):
"""Upload a file asynchronously"""
message_display = init_message_display(debug=debug)
HttpxClientConfigurator.configure(
exponential_backoff_max=CONFIG.exponential_backoff_max,
Expand All @@ -226,7 +240,7 @@ async def upload(


@cli.command(no_args_is_help=True)
async def download(
def download(
*,
output_dir: Path = typer.Option(
..., help="The directory to put the downloaded files into."
Expand All @@ -247,7 +261,19 @@ async def download(
False, help="Set this option in order to view traceback for errors."
),
):
"""Command to download files"""
"""Wrapper for the async download function"""
asyncio.run(
async_download(output_dir, my_public_key_path, my_private_key_path, debug)
)


async def async_download(
output_dir: Path,
my_public_key_path: Path,
my_private_key_path: Path,
debug: bool = False,
):
"""Download files asynchronously"""
if not my_public_key_path.is_file():
raise exceptions.PubKeyFileDoesNotExistError(public_key_path=my_public_key_path)

Expand Down
10 changes: 5 additions & 5 deletions tests/integration/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from pytest_httpx import HTTPXMock, httpx_mock # noqa: F401

from ghga_connector.cli import (
download,
async_download,
init_message_display,
retrieve_upload_parameters,
)
Expand Down Expand Up @@ -162,7 +162,7 @@ async def test_multipart_download(
wps_api_url=api_url,
),
):
await download(
await async_download(
output_dir=tmp_path,
my_public_key_path=Path(PUBLIC_KEY_FILE),
my_private_key_path=Path(PRIVATE_KEY_FILE),
Expand Down Expand Up @@ -274,7 +274,7 @@ async def test_download(
exceptions.UnauthorizedAPICallError,
match="This is not the token you're looking for.",
):
await download(
await async_download(
output_dir=output_dir,
my_public_key_path=Path(PUBLIC_KEY_FILE),
my_private_key_path=Path(PRIVATE_KEY_FILE),
Expand All @@ -288,7 +288,7 @@ async def test_download(
match="Endpoint file ID did not match file ID"
" announced in work order token",
):
await download(
await async_download(
output_dir=output_dir,
my_public_key_path=Path(PUBLIC_KEY_FILE),
my_private_key_path=Path(PRIVATE_KEY_FILE),
Expand All @@ -301,7 +301,7 @@ async def test_download(
if expected_exception
else nullcontext()
):
await download(
await async_download(
output_dir=output_dir,
my_public_key_path=Path(PUBLIC_KEY_FILE),
my_private_key_path=Path(PRIVATE_KEY_FILE),
Expand Down

0 comments on commit 94b9452

Please sign in to comment.