From aa95d4e595cb941b23b8ce75fbb81a0c5d3dd3f7 Mon Sep 17 00:00:00 2001 From: David Abramov Date: Fri, 20 Sep 2024 10:31:23 -0700 Subject: [PATCH 1/3] Changed argparse to typer in scripts/check_globus_compute.py and check_globus_transfer.py. Also patched orchestration/globus/transfer.py to coerce transfer data into strings. --- orchestration/globus/transfer.py | 2 +- scripts/check_globus_compute.py | 30 ++++++++++---------- scripts/check_globus_transfer.py | 47 +++++++++++++++----------------- 3 files changed, 38 insertions(+), 41 deletions(-) diff --git a/orchestration/globus/transfer.py b/orchestration/globus/transfer.py index 91474d2..a356a93 100644 --- a/orchestration/globus/transfer.py +++ b/orchestration/globus/transfer.py @@ -115,7 +115,7 @@ def start_transfer( relative_path = item.relative_to(source_path.parent) tdata.add_item(str(item), os.path.join(dest_path, str(relative_path))) else: - tdata.add_item(source_path, dest_path) + tdata.add_item(str(source_path), str(dest_path)) logger.info( f"starting transfer {source_endpoint.uri}:{source_path} to {dest_endpoint.uri}:{dest_path}" ) diff --git a/scripts/check_globus_compute.py b/scripts/check_globus_compute.py index 88318d2..632a97f 100644 --- a/scripts/check_globus_compute.py +++ b/scripts/check_globus_compute.py @@ -1,5 +1,5 @@ -import argparse from dotenv import load_dotenv +import typer from typing import Optional from globus_compute_sdk.sdk.login_manager import LoginManager @@ -8,6 +8,8 @@ load_dotenv() +app = typer.Typer() + @task def get_login_manager(environment: Optional[str] = None) -> LoginManager: @@ -58,28 +60,26 @@ def check_globus_compute_status(endpoint_id: str) -> bool: return False -def main() -> None: +@app.command() +def main(endpoint_id: str) -> None: """ - Main function to parse command-line arguments and check the Globus Compute endpoint status. + Check the status of a Globus Compute endpoint by providing the endpoint_id. + Example usage: - python check_globus_compute.py --endpoint_id "your-uuid-here" + python check_globus_compute.py --endpoint-id "your-uuid-here" IMPORTANT: - Ensure you are logged into Globus Compute + Ensure you are logged into Globus Compute and have set the environment variables for the client credentials: export GLOBUS_COMPUTE_CLIENT_ID="your-client-id" & export GLOBUS_COMPUTE_CLIENT_SECRET="your-client-secret" - :return: None - """ - parser = argparse.ArgumentParser(description="Check the status of a Globus Compute endpoint.") - parser.add_argument('--endpoint_id', type=str, required=True, help="The UUID of the Globus Compute endpoint.") - args = parser.parse_args() - - online = check_globus_compute_status(args.endpoint_id) + :param endpoint_id: The UUID of the Globus Compute endpoint. + """ + online = check_globus_compute_status(endpoint_id) if online: - print(f"Endpoint {args.endpoint_id} is online.") + typer.echo(f"Endpoint {endpoint_id} is online.") else: - print(f"Endpoint {args.endpoint_id} is not online.") + typer.echo(f"Endpoint {endpoint_id} is not online.") if __name__ == "__main__": - main() + app() diff --git a/scripts/check_globus_transfer.py b/scripts/check_globus_transfer.py index b6c78f7..5e1377c 100644 --- a/scripts/check_globus_transfer.py +++ b/scripts/check_globus_transfer.py @@ -1,7 +1,7 @@ -import argparse from dotenv import load_dotenv import os import time +import typer import globus_sdk from prefect import flow, task, get_run_logger @@ -14,6 +14,8 @@ CLIENT_SECRET: Optional[str] = os.getenv('GLOBUS_CLIENT_SECRET') SCOPES: str = "urn:globus:auth:scope:transfer.api.globus.org:all" +app = typer.Typer() + @task def initialize_transfer_client() -> Tuple[Optional[globus_sdk.TransferClient], bool]: @@ -215,41 +217,36 @@ def check_globus_transfer_permissions(endpoint_id: str, logger.info(f"list_directory (after creating {directory_name}) successful: {success_list_directory_after}") -def main() -> None: +@app.command() +def main(endpoint_id: str, + transfer_client: Optional[globus_sdk.TransferClient], + list_contents: bool = True, + create_test_directory: bool = True, + delete_test_directory: bool = True, + directory_name: str = "test_directory/") -> None: """ Main function to parse command-line arguments and run the check_globus_transfer_permissions flow. Run from the command line: python check_globus_transfer.py --endpoint_id "your-endpoint-id" --directory_name "your-directory-name" - Command-line arguments: - --endpoint_id (str): The UUID of the endpoint to operate on. - --list_contents (bool): Whether to list directory contents. Default is True. - --create_test_directory (bool): Whether to create a directory. Default is True. - --delete_test_directory (bool): Whether to delete the directory. Default is True. - --directory_name (str): The name of the directory to create or delete. Default is "test_directory". + Args: + endpoint_id (str): The UUID of the Globus endpoint. + list_contents (bool): Whether to list directory contents. Default is True. + create_test_directory (bool): Whether to create a directory. Default is True. + delete_test_directory (bool): Whether to delete the directory. Default is True. + directory_name (str): The name of the directory to create or delete. Default is "test_directory/". """ - parser = argparse.ArgumentParser(description="Run Globus transfer operations on a specified endpoint.") - parser.add_argument('--endpoint_id', type=str, required=True, help="The UUID of the Globus endpoint.") - parser.add_argument('--list_contents', type=bool, default=True, help="Whether to list directory contents.") - parser.add_argument('--create_test_directory', type=bool, default=True, - help="Whether to create a directory.") - parser.add_argument('--delete_test_directory', type=bool, default=True, - help="Whether to delete the directory.") - parser.add_argument('--directory_name', type=str, default="test_directory/", - help="The name of the directory to create or delete.") - - args = parser.parse_args() check_globus_transfer_permissions( - endpoint_id=args.endpoint_id, + endpoint_id=endpoint_id, transfer_client=None, - list_contents=args.list_contents, - create_test_directory=args.create_test_directory, - delete_test_directory=args.delete_test_directory, - directory_name=args.directory_name + list_contents=list_contents, + create_test_directory=create_test_directory, + delete_test_directory=delete_test_directory, + directory_name=directory_name ) if __name__ == "__main__": - main() + app() From 76e6c4f71081dde1e0802176a08d9009fc1a5150 Mon Sep 17 00:00:00 2001 From: David Abramov Date: Fri, 20 Sep 2024 11:26:47 -0700 Subject: [PATCH 2/3] Keeping source_path: str and dest_path:str, but only coercing str(source_path) since it is reinitialized into a Path object --- orchestration/globus/transfer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/orchestration/globus/transfer.py b/orchestration/globus/transfer.py index a356a93..50a3489 100644 --- a/orchestration/globus/transfer.py +++ b/orchestration/globus/transfer.py @@ -94,9 +94,9 @@ def init_transfer_client(app: GlobusApp) -> TransferClient: def start_transfer( transfer_client: TransferClient, source_endpoint: GlobusEndpoint, - source_path: str, + source_path: Path, dest_endpoint: GlobusEndpoint, - dest_path: str, + dest_path: Path, max_wait_seconds=600, logger=logger, ): From 3f44d755d4c0d6dfff0317e1f83a62536b8dd5d7 Mon Sep 17 00:00:00 2001 From: David Abramov Date: Fri, 20 Sep 2024 11:26:56 -0700 Subject: [PATCH 3/3] Keeping source_path: str and dest_path:str, but only coercing str(source_path) since it is reinitialized into a Path object --- orchestration/globus/transfer.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/orchestration/globus/transfer.py b/orchestration/globus/transfer.py index 50a3489..a9972cb 100644 --- a/orchestration/globus/transfer.py +++ b/orchestration/globus/transfer.py @@ -94,9 +94,9 @@ def init_transfer_client(app: GlobusApp) -> TransferClient: def start_transfer( transfer_client: TransferClient, source_endpoint: GlobusEndpoint, - source_path: Path, + source_path: str, dest_endpoint: GlobusEndpoint, - dest_path: Path, + dest_path: str, max_wait_seconds=600, logger=logger, ): @@ -115,7 +115,7 @@ def start_transfer( relative_path = item.relative_to(source_path.parent) tdata.add_item(str(item), os.path.join(dest_path, str(relative_path))) else: - tdata.add_item(str(source_path), str(dest_path)) + tdata.add_item(str(source_path), dest_path) logger.info( f"starting transfer {source_endpoint.uri}:{source_path} to {dest_endpoint.uri}:{dest_path}" )