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

added functionality to latch test-data upload #194

Closed
wants to merge 1 commit into from
Closed
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 latch_cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,11 @@ def test_data(ctx):

@test_data.command("upload")
@click.argument("src_path", nargs=1, type=click.Path(exists=True))
@click.option(
"--s3_path",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"--s3_path",
"--s3-path",

kebab-case for cli options

default = None,
type=str,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you make this optional as well (see my other comment)

help=("Destination folder path to write to on s3 (omit s3 Bucket prefix)."))
@click.option(
"--dont-confirm-overwrite",
"-d",
Expand All @@ -514,13 +519,13 @@ def test_data(ctx):
type=bool,
help=("Automatically overwrite any files without asking for confirmation."),
)
def test_data_upload(src_path: str, dont_confirm_overwrite: bool):
def test_data_upload(src_path: str, s3_path: str, dont_confirm_overwrite: bool):
"""Upload test data object."""

from latch_cli.services.test_data.upload import upload

try:
s3_url = upload(src_path, dont_confirm_overwrite)
s3_url = upload(src_path, s3_path, dont_confirm_overwrite)
click.secho(f"Successfully uploaded to {s3_url}", fg="green")
except Exception as e:
CrashReporter.report()
Expand Down
8 changes: 6 additions & 2 deletions latch_cli/services/test_data/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
import boto3
import botocore
import click
import os

from latch_cli.services.test_data.utils import _retrieve_creds
from latch_cli.utils import account_id_from_token, retrieve_or_login

BUCKET = "latch-public"


def upload(src_path: str, dont_confirm_overwrite: bool = True) -> str:
def upload(src_path: str, s3_path: str = None, dont_confirm_overwrite: bool = True) -> str:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def upload(src_path: str, s3_path: str = None, dont_confirm_overwrite: bool = True) -> str:
def upload(src_path: str, s3_path: Optional[str] = None, dont_confirm_overwrite: bool = True) -> str:

using the Optional type from typing makes this more semantic

"""Uploads a local file/folder to a managed bucket.

Args:
Expand All @@ -39,7 +40,10 @@ def upload(src_path: str, dont_confirm_overwrite: bool = True) -> str:
if account_id is None or account_id == "":
account_id = account_id_from_token(retrieve_or_login())

allowed_key = str((Path("test-data") / account_id).joinpath(src_path))
if s3_path is None:
allowed_key = str((Path("test-data") / account_id).joinpath(src_path))
else:
allowed_key = str((Path("test-data") / account_id).joinpath(s3_path))

upload_helper(
Path(src_path).resolve(),
Expand Down