Skip to content

Commit

Permalink
Linting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
davramov committed Aug 16, 2024
1 parent f7b4bc6 commit fe4d4cc
Show file tree
Hide file tree
Showing 12 changed files with 158 additions and 142 deletions.
2 changes: 1 addition & 1 deletion examples/alcf_compute_endpoint_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
token_response = auth_client.oauth2_client_credentials_tokens(requested_scopes=SCOPES)
compute_tokens = token_response.by_resource_server['compute.api.globus.org']
access_token = compute_tokens['access_token']

# Initialize the ComputeClient with the token
compute_client = ComputeClient(authorizer=globus_sdk.AccessTokenAuthorizer(access_token))

Expand Down
26 changes: 13 additions & 13 deletions examples/test_cc_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@
# Set the client ID and fetch client secret from environment
CLIENT_ID = os.getenv('GLOBUS_CLIENT_ID')
CLIENT_SECRET = os.getenv('GLOBUS_CLIENT_SECRET')

# SCOPES = ['urn:globus:auth:scope:transfer.api.globus.org:all[*https://auth.globus.org/scopes/55c3adf6-31f1-4647-9a38-52591642f7e7/data_access]']
SCOPES = "urn:globus:auth:scope:transfer.api.globus.org:all"
# ENDPOINT_ID = "d40248e6-d874-4f7b-badd-2c06c16f1a58" # NERSC DTN alsdev Collab
ENDPOINT_ID = "55c3adf6-31f1-4647-9a38-52591642f7e7" #ALCF Iribeta CGS
ENDPOINT_ID = "UUID"


def initialize_transfer_client():
Expand Down Expand Up @@ -62,6 +59,7 @@ def list_directory(transfer_client, endpoint_id, path):
elapsed_time = time.time() - start_time
logger.info(f"list_directory task took {elapsed_time:.2f} seconds")


@task
def create_directory(transfer_client, endpoint_id, base_path, directory_name):
logger = get_run_logger()
Expand All @@ -72,7 +70,7 @@ def create_directory(transfer_client, endpoint_id, base_path, directory_name):
base_path += '/'
if base_path.startswith('/'):
base_path = base_path.lstrip('/')

full_path = base_path + directory_name

# Validate the path
Expand All @@ -89,7 +87,7 @@ def create_directory(transfer_client, endpoint_id, base_path, directory_name):
if err.info.consent_required:
logger.error(f"Got a ConsentRequired error with scopes: {err.info.consent_required.required_scopes}")
elif err.code == "PermissionDenied":
logger.error(f"Permission denied for creating directory {full_path}. Ensure proper permissions are set.")
logger.error(f"Permission denied for creating directory {full_path}. Ensure proper permissions.")
elif err.http_status == 500:
logger.error(f"Server error when creating directory {full_path} in endpoint {endpoint_id}.")
else:
Expand All @@ -107,7 +105,8 @@ def remove_directory(transfer_client, endpoint_id, path):
delete_data = globus_sdk.DeleteData(transfer_client, endpoint_id, recursive=True)
delete_data.add_item(path)
transfer_result = transfer_client.submit_delete(delete_data)
logger.info(f"Successfully submitted request to remove directory {path} in endpoint {endpoint_id}. Task ID: {transfer_result['task_id']}")
logger.info(f"Successfully submitted request to remove directory {path} in endpoint {endpoint_id}.")
logger.info(f"Task ID: {transfer_result['task_id']}")
except globus_sdk.GlobusAPIError as err:
logger.error(f"Error removing directory {path} in endpoint {endpoint_id}: {err.message}")
if err.info.consent_required:
Expand All @@ -134,18 +133,19 @@ def main_flow():

# List the contents of the root directory
logger = get_run_logger()
# logger.info("Listing / directory:")
# list_directory(transfer_client, endpoint_id, base_path)
logger.info("Listing / directory:")
list_directory(transfer_client, endpoint_id, base_path)

# Create a new directory in the root directory
# new_directory_name = "test/"
# create_directory(transfer_client, endpoint_id, base_path, new_directory_name)
new_directory_name = "test/"
create_directory(transfer_client, endpoint_id, base_path, new_directory_name)

remove_directory(transfer_client, endpoint_id, "bl832_test/scratch/BLS-00564_dyparkinson/")

# List the contents again to verify the new directory
# logger.info(f"\nListing / directory after creating {new_directory_name}:")
# list_directory(transfer_client, endpoint_id, base_path+new_directory_name)
logger.info(f"\nListing / directory after creating {new_directory_name}:")
list_directory(transfer_client, endpoint_id, base_path+new_directory_name)


if __name__ == "__main__":
main_flow()
17 changes: 10 additions & 7 deletions examples/tiff_to_zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@

import os
import argparse
import zarr
from ngff_zarr import (
detect_cli_io_backend,
cli_input_to_ngff_image,
to_multiscales,
to_ngff_zarr,
Methods,
config
Methods
)


def parse_arguments():
parser = argparse.ArgumentParser(description='Convert TIFF files to NGFF Zarr format.')
parser.add_argument('tiff_directory', type=str, help='Directory containing the TIFF files.')
parser.add_argument('--zarr_directory', type=str, default=None, help='Directory to store the Zarr output. Defaults to a new folder in the input directory.')
parser.add_argument('--zarr_directory',
type=str,
default=None,
help='Directory to store Zarr output. Default is new folder in input directory.')
return parser.parse_args()


def set_permissions_recursive(path, permissions=0o2775):
for root, dirs, files in os.walk(path):
for dir in dirs:
Expand All @@ -26,11 +29,12 @@ def set_permissions_recursive(path, permissions=0o2775):
os.chmod(os.path.join(root, file), permissions)
os.chmod(path, permissions) # Also set permissions for the top-level directory


def main():
args = parse_arguments()

tiff_dir = args.tiff_directory
zarr_dir = args.zarr_directory
zarr_dir = args.zarr_directory

if not os.path.isdir(tiff_dir):
raise TypeError("The specified TIFF directory is not a valid directory")
Expand All @@ -51,7 +55,6 @@ def main():
print('Output directory: ' + zarr_dir)

# Build NGFF Zarr directory
# config.cache_store = zarr.storage.DirectoryStore("/alsuser/pscratch/zarr-ngff-cache", dimension_separator="/")
backend = detect_cli_io_backend(file_paths)
image = cli_input_to_ngff_image(backend, file_paths)
# The scale and axis units are the same as the one printed in the reconstruction script
Expand All @@ -66,4 +69,4 @@ def main():


if __name__ == "__main__":
main()
main()
47 changes: 22 additions & 25 deletions orchestration/_tests/test_globus_flow.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
from pydantic import BaseModel, ConfigDict, PydanticDeprecatedSince20
import warnings
import pytest
from unittest.mock import MagicMock, patch
from typing import List, Optional, Dict, Any
from uuid import UUID, uuid4
from globus_sdk import ConfidentialAppAuthClient, TransferClient
from globus_sdk.authorizers.client_credentials import ClientCredentialsAuthorizer
from globus_compute_sdk.sdk.client import Client
from orchestration.flows.bl832.alcf import (
process_new_832_ALCF_flow
)
from orchestration.flows.bl832.config import Config832

from prefect.testing.utilities import prefect_test_harness
from prefect.blocks.system import JSON, Secret

from orchestration._tests.test_globus import MockTransferClient

from globus_sdk import ConfidentialAppAuthClient, TransferClient
from globus_sdk.authorizers.client_credentials import ClientCredentialsAuthorizer
from globus_compute_sdk.sdk.client import Client
from pydantic import BaseModel, ConfigDict, PydanticDeprecatedSince20
import pytest
from typing import List, Optional, Dict, Any
from unittest.mock import MagicMock, patch
from uuid import UUID, uuid4
import warnings

warnings.filterwarnings("ignore", category=DeprecationWarning)
warnings.filterwarnings("ignore", category=PydanticDeprecatedSince20)


@pytest.fixture(autouse=True, scope="session")
def prefect_test_fixture():
with prefect_test_harness():
globus_client_id = Secret(value = "test-globus-client-id")
globus_client_id.save(name = "globus-client-id")
globus_client_secret = Secret(value = "your_globus_client_secret")
globus_client_secret.save(name = "globus-client-secret")
globus_client_id = Secret(value="test-globus-client-id")
globus_client_id.save(name="globus-client-id")
globus_client_secret = Secret(value="your_globus_client_secret")
globus_client_secret.save(name="globus-client-secret")
pruning_config = JSON(value={"max_wait_seconds": 600})
pruning_config.save(name="pruning-config")
yield
Expand Down Expand Up @@ -103,8 +100,10 @@ def __init__(self) -> None:
"nersc832": MockEndpoint(root_path="mock_nersc832_path", uuid_value=str(uuid4())),
"nersc_test": MockEndpoint(root_path="mock_nersc_test_path", uuid_value=str(uuid4())),
"nersc_alsdev": MockEndpoint(root_path="mock_nersc_alsdev_path", uuid_value=str(uuid4())),
"nersc832_alsdev_raw": MockEndpoint(root_path="mock_nersc832_alsdev_raw_path", uuid_value=str(uuid4())),
"nersc832_alsdev_scratch": MockEndpoint(root_path="mock_nersc832_alsdev_scratch_path", uuid_value=str(uuid4())),
"nersc832_alsdev_raw": MockEndpoint(root_path="mock_nersc832_alsdev_raw_path",
uuid_value=str(uuid4())),
"nersc832_alsdev_scratch": MockEndpoint(root_path="mock_nersc832_alsdev_scratch_path",
uuid_value=str(uuid4())),
"alcf832_raw": MockEndpoint(root_path="mock_alcf832_raw_path", uuid_value=str(uuid4())),
"alcf832_scratch": MockEndpoint(root_path="mock_alcf832_scratch_path", uuid_value=str(uuid4())),
}
Expand Down Expand Up @@ -156,7 +155,7 @@ def get_result(self, task_id):
# Mock getting the result of a task
return "mock_result"

# Update your test to include this mocking

@pytest.fixture(autouse=True)
def mock_globus_compute_client(monkeypatch):
monkeypatch.setattr(Client, "__init__", MockGlobusComputeClient.__init__)
Expand All @@ -172,14 +171,12 @@ class MockFlowsClient:
def __init__(self):
self.flows = {}


def create_flow(self, request: CreateFlowRequest) -> Dict[str, Any]:
"""Mock method for initializing a new flow with Globus Flows"""
flow_id = UUID("123e4567-e89b-12d3-a456-426614174000")
self.flows[flow_id] = request.model_dump()
return {"flow_id": str(flow_id)}


def get_flow(self, flow_id: UUID) -> Dict[str, Any]:
"""Mock method for getting a flow"""
return self.flows.get(flow_id, {})
Expand All @@ -191,14 +188,12 @@ def __init__(self, flow_id: UUID):
self.flow_id = flow_id
self.runs = {}


def run_flow(self, request: RunFlowRequest) -> Dict[str, Any]:
"""Mock method for running a registered flow function"""
run_id = UUID("123e4567-e89b-12d3-a456-426614174001")
self.runs[run_id] = request.model_dump()
return {"run_id": str(run_id), "status": "SUCCEEDED"}


def get_run(self, run_id: UUID) -> Dict[str, Any]:
"""Mock method for getting a run"""
return self.runs.get(run_id, {})
Expand Down Expand Up @@ -266,7 +261,9 @@ def mock_oauth2_client_credentials_tokens(self):
"expires_in": 3600,
}

monkeypatch.setattr(ConfidentialAppAuthClient, "oauth2_client_credentials_tokens", mock_oauth2_client_credentials_tokens)
monkeypatch.setattr(ConfidentialAppAuthClient,
"oauth2_client_credentials_tokens",
mock_oauth2_client_credentials_tokens)

def mock_get_new_access_token(self):
pass
Expand Down
Loading

0 comments on commit fe4d4cc

Please sign in to comment.