From 1202fc551309dfd6039f05a06e9c94802e0eb969 Mon Sep 17 00:00:00 2001 From: Jonathan Feng Date: Mon, 12 Jun 2023 21:38:29 -0700 Subject: [PATCH 1/5] add attachment url option flag --- scaleapi/__init__.py | 20 ++++++++++++++++++++ scaleapi/_version.py | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/scaleapi/__init__.py b/scaleapi/__init__.py index f0a14d9..b687268 100644 --- a/scaleapi/__init__.py +++ b/scaleapi/__init__.py @@ -269,6 +269,10 @@ def tasks(self, **kwargs) -> Tasklist: limit (int): Determines the page size (1-100) + include_attachment_url (bool): + If true, returns a pre-signed s3 url for the + attachment used to create the task. + next_token (str): Can be use to fetch the next page of tasks """ @@ -288,6 +292,7 @@ def tasks(self, **kwargs) -> Tasklist: "updated_before", "updated_after", "unique_id", + "include_attachment_url", } for key in kwargs: @@ -323,6 +328,7 @@ def get_tasks( created_after: str = None, created_before: str = None, tags: Union[List[str], str] = None, + include_attachment_url: bool = True, ) -> Generator[Task, None, None]: """Retrieve all tasks as a `generator` method, with the given parameters. This methods handles pagination of @@ -382,6 +388,11 @@ def get_tasks( The tags of a task; multiple tags can be specified as a list. + include_attachment_url (bool): + If true, returns a pre-signed s3 url for the + attachment used to create the task. + + Yields: Generator[Task]: Yields Task objects, can be iterated. @@ -404,6 +415,7 @@ def get_tasks( created_after, created_before, tags, + include_attachment_url, ) while has_more: @@ -431,6 +443,7 @@ def get_tasks_count( created_after: str = None, created_before: str = None, tags: Union[List[str], str] = None, + include_attachment_url: bool = True, ) -> int: """Returns number of tasks with given filters. @@ -485,6 +498,10 @@ def get_tasks_count( The tags of a task; multiple tags can be specified as a list. + include_attachment_url (bool): + If true, returns a pre-signed s3 url for the + attachment used to create the task. + Returns: int: Returns number of tasks @@ -504,6 +521,7 @@ def get_tasks_count( created_after, created_before, tags, + include_attachment_url, ) tasks_args["limit"] = 1 @@ -526,6 +544,7 @@ def _process_tasks_endpoint_args( created_after: str = None, created_before: str = None, tags: Union[List[str], str] = None, + include_attachment_url: bool = True, ): """Generates args for /tasks endpoint.""" tasks_args = { @@ -539,6 +558,7 @@ def _process_tasks_endpoint_args( "updated_before": updated_before, "updated_after": updated_after, "unique_id": unique_id, + "include_attachment_url": include_attachment_url, } if status: diff --git a/scaleapi/_version.py b/scaleapi/_version.py index cf0e064..709a0ab 100644 --- a/scaleapi/_version.py +++ b/scaleapi/_version.py @@ -1,2 +1,2 @@ -__version__ = "2.14.3" +__version__ = "2.14.4" __package_name__ = "scaleapi" From 4ccc37c7d934e418925994c3ecf738e217d8ba74 Mon Sep 17 00:00:00 2001 From: Jonathan Feng Date: Mon, 12 Jun 2023 21:41:49 -0700 Subject: [PATCH 2/5] include test --- tests/test_client.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/test_client.py b/tests/test_client.py index 63d4c67..a00a02f 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -407,6 +407,19 @@ def test_get_tasks(): ): assert task.id in task_ids +def test_get_tasks_returns_attachment(): + batch = create_a_batch() + tasks = [] + for _ in range(1): + tasks.append(make_a_task(batch=batch.name)) + for task in client.get_tasks( + project_name=TEST_PROJECT_NAME, + batch_name=batch.name, + include_attachment_url=True, + ): + assert task.as_dict()['attachmentS3Downloads'] + + def test_get_tasks_count(): tasks_count = client.tasks(project=TEST_PROJECT_NAME).total From cc4716fb5477852d5a060478095f26cc5d5cd9de Mon Sep 17 00:00:00 2001 From: Jonathan Feng Date: Mon, 12 Jun 2023 22:10:09 -0700 Subject: [PATCH 3/5] formating --- tests/test_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_client.py b/tests/test_client.py index a00a02f..45bb503 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -407,6 +407,7 @@ def test_get_tasks(): ): assert task.id in task_ids + def test_get_tasks_returns_attachment(): batch = create_a_batch() tasks = [] @@ -420,7 +421,6 @@ def test_get_tasks_returns_attachment(): assert task.as_dict()['attachmentS3Downloads'] - def test_get_tasks_count(): tasks_count = client.tasks(project=TEST_PROJECT_NAME).total get_tasks_count = client.get_tasks_count(project_name=TEST_PROJECT_NAME) From b3bcca0fa769dcbb812e48b4fba3748c216b0282 Mon Sep 17 00:00:00 2001 From: Jonathan Feng Date: Mon, 12 Jun 2023 22:11:40 -0700 Subject: [PATCH 4/5] more reformatting --- tests/test_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_client.py b/tests/test_client.py index 45bb503..b99ea36 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -418,7 +418,7 @@ def test_get_tasks_returns_attachment(): batch_name=batch.name, include_attachment_url=True, ): - assert task.as_dict()['attachmentS3Downloads'] + assert task.as_dict()["attachmentS3Downloads"] def test_get_tasks_count(): From ce2559650ddf40e19536b1aea38624d1b731f19f Mon Sep 17 00:00:00 2001 From: Jonathan Feng Date: Mon, 12 Jun 2023 22:24:19 -0700 Subject: [PATCH 5/5] remove test case --- tests/test_client.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/tests/test_client.py b/tests/test_client.py index b99ea36..63d4c67 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -408,19 +408,6 @@ def test_get_tasks(): assert task.id in task_ids -def test_get_tasks_returns_attachment(): - batch = create_a_batch() - tasks = [] - for _ in range(1): - tasks.append(make_a_task(batch=batch.name)) - for task in client.get_tasks( - project_name=TEST_PROJECT_NAME, - batch_name=batch.name, - include_attachment_url=True, - ): - assert task.as_dict()["attachmentS3Downloads"] - - def test_get_tasks_count(): tasks_count = client.tasks(project=TEST_PROJECT_NAME).total get_tasks_count = client.get_tasks_count(project_name=TEST_PROJECT_NAME)