Skip to content

Commit 633a543

Browse files
committed
Fix pre-commit checks and run tests
1 parent d7bae50 commit 633a543

File tree

5 files changed

+68
-29
lines changed

5 files changed

+68
-29
lines changed

zstash/create.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
ts_utc,
2323
)
2424

25+
2526
def create():
2627
cache: str
2728
cache, args = setup_create()

zstash/globus.py

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
from globus_sdk import TransferAPIError, TransferClient, TransferData
1212
from globus_sdk.services.transfer.response.iterable import IterableTransferResponse
1313
from six.moves.urllib.parse import urlparse
14-
from .utils import ts_utc
1514

1615
from .settings import logger
16+
from .utils import ts_utc
1717

1818
hpss_endpoint_map = {
1919
"ALCF": "de463ec4-6d04-11e5-ba46-22000b92c6ec",
@@ -158,9 +158,10 @@ def file_exists(name: str) -> bool:
158158
return False
159159

160160

161-
def globus_transfer(
161+
# C901 'globus_transfer' is too complex (20)
162+
def globus_transfer( # noqa: C901
162163
remote_ep: str, remote_path: str, name: str, transfer_type: str, non_blocking: bool
163-
): # noqa: C901
164+
):
164165
global transfer_client
165166
global local_endpoint
166167
global remote_endpoint
@@ -223,10 +224,14 @@ def globus_transfer(
223224
# NOTE: How we behave here depends upon whether we want to support mutliple active transfers.
224225
# Presently, we do not, except inadvertantly (if status == PENDING)
225226
if prev_task_status == "ACTIVE":
226-
logger.info(f"{ts_utc()}: Previous task_id {task_id} Still Active. Returning.")
227+
logger.info(
228+
f"{ts_utc()}: Previous task_id {task_id} Still Active. Returning."
229+
)
227230
return "ACTIVE"
228231
elif prev_task_status == "SUCCEEDED":
229-
logger.info(f"{ts_utc()}: Previous task_id {task_id} status = SUCCEEDED. Continuing.")
232+
logger.info(
233+
f"{ts_utc()}: Previous task_id {task_id} status = SUCCEEDED. Continuing."
234+
)
230235
src_ep = task["source_endpoint_id"]
231236
dst_ep = task["destination_endpoint_id"]
232237
label = task["label"]
@@ -237,22 +242,26 @@ def globus_transfer(
237242
)
238243
)
239244
else:
240-
logger.error(f"{ts_utc()}: Previous task_id {task_id} status = {prev_task_status}. Continuing.")
245+
logger.error(
246+
f"{ts_utc()}: Previous task_id {task_id} status = {prev_task_status}. Continuing."
247+
)
241248

242249
# DEBUG: review accumulated items in TransferData
243250
logger.info(f"{ts_utc()}: TransferData: accumulated items:")
244251
attribs = transfer_data.__dict__
245-
for item in attribs['data']['DATA']:
246-
if item['DATA_TYPE'] == "transfer_item":
252+
for item in attribs["data"]["DATA"]:
253+
if item["DATA_TYPE"] == "transfer_item":
247254
print(f" source item: {item['source_path']}")
248-
255+
249256
# SUBMIT new transfer here
250257
logger.info(f"{ts_utc()}: DIVING: Submit Transfer for {transfer_data['label']}")
251258
task = submit_transfer_with_checks(transfer_data)
252259
task_id = task.get("task_id")
253260
# NOTE: This log message is misleading. If we have accumulated multiple tar files for transfer,
254261
# the "lable" given here refers only to the LAST tarfile in the TransferData list.
255-
logger.info(f"{ts_utc()}: SURFACE Submit Transfer returned new task_id = {task_id} for label {transfer_data['label']}")
262+
logger.info(
263+
f"{ts_utc()}: SURFACE Submit Transfer returned new task_id = {task_id} for label {transfer_data['label']}"
264+
)
256265

257266
transfer_data = None
258267
except TransferAPIError as e:
@@ -272,7 +281,9 @@ def globus_transfer(
272281
# test for blocking on new task_id
273282
task_status = "UNKNOWN"
274283
if not non_blocking:
275-
task_status = globus_block_wait(task_id=task_id, wait_timeout=7200, polling_interval=10, max_retries=5)
284+
task_status = globus_block_wait(
285+
task_id=task_id, wait_timeout=7200, polling_interval=10, max_retries=5
286+
)
276287
else:
277288
logger.info(f"{ts_utc()}: NO BLOCKING (task_wait) for task_id {task_id}")
278289

@@ -285,35 +296,47 @@ def globus_transfer(
285296
return task_status
286297

287298

288-
def globus_block_wait(task_id: str, wait_timeout: int, polling_interval: int, max_retries: int):
299+
def globus_block_wait(
300+
task_id: str, wait_timeout: int, polling_interval: int, max_retries: int
301+
):
289302
global transfer_client
290303

291304
# poll every "polling_interval" seconds to speed up small transfers. Report every 2 hours, stop waiting aftert 5*2 = 10 hours
292-
logger.info(f"{ts_utc()}: BLOCKING START: invoking task_wait for task_id = {task_id}")
305+
logger.info(
306+
f"{ts_utc()}: BLOCKING START: invoking task_wait for task_id = {task_id}"
307+
)
293308
task_status = "UNKNOWN"
294309
retry_count = 0
295310
while retry_count < max_retries:
296311
try:
297312
# Wait for the task to complete
298-
transfer_client.task_wait(task_id, timeout=wait_timeout, polling_interval=10)
299-
except GlobusHTTPError as e:
300-
logger.error(f"Exception: {e}")
313+
transfer_client.task_wait(
314+
task_id, timeout=wait_timeout, polling_interval=10
315+
)
316+
# except GlobusHTTPError as e:
317+
# logger.error(f"Exception: {e}")
301318
except Exception as e:
302319
logger.error(f"Unexpected Exception: {e}")
303320
else:
304321
curr_task = transfer_client.get_task(task_id)
305-
task_status = curr_task['status']
322+
task_status = curr_task["status"]
306323
if task_status == "SUCCEEDED":
307324
break
308325
finally:
309326
retry_count += 1
310-
logger.info(f"{ts_utc()}: BLOCKING retry_count = {retry_count} of {max_retries} of timeout {wait_timeout} seconds")
327+
logger.info(
328+
f"{ts_utc()}: BLOCKING retry_count = {retry_count} of {max_retries} of timeout {wait_timeout} seconds"
329+
)
311330

312331
if retry_count == max_retries:
313-
logger.info(f"{ts_utc()}: BLOCKING EXHAUSTED {max_retries} of timeout {wait_timeout} seconds")
332+
logger.info(
333+
f"{ts_utc()}: BLOCKING EXHAUSTED {max_retries} of timeout {wait_timeout} seconds"
334+
)
314335
task_status = "EXHAUSTED_TIMEOUT_RETRIES"
315336

316-
logger.info(f"{ts_utc()}: BLOCKING ENDS: task_id {task_id} returned from task_wait with status {task_status}")
337+
logger.info(
338+
f"{ts_utc()}: BLOCKING ENDS: task_id {task_id} returned from task_wait with status {task_status}"
339+
)
317340

318341
return task_status
319342

zstash/hpss.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,12 @@ def hpss_transfer(
9090
globus_status = "UNKNOWN"
9191
# Transfer file using the Globus Transfer Service
9292
logger.info(f"{ts_utc()}: DIVING: hpss calls globus_transfer(name={name})")
93-
globus_status = globus_transfer(endpoint, url_path, name, transfer_type, non_blocking)
94-
logger.info(f"{ts_utc()}: SURFACE hpss globus_transfer(name={name}) returns {globus_status}")
93+
globus_status = globus_transfer(
94+
endpoint, url_path, name, transfer_type, non_blocking
95+
)
96+
logger.info(
97+
f"{ts_utc()}: SURFACE hpss globus_transfer(name={name}) returns {globus_status}"
98+
)
9599
# NOTE: Here, the status could be "EXHAUSTED_TIMEOUT_RETRIES", meaning a very long transfer
96100
# or perhaps transfer is hanging. We should decide whether to ignore it, or cancel it, but
97101
# we'd need the task_id to issue a cancellation. Perhaps we should have globus_transfer
@@ -107,15 +111,22 @@ def hpss_transfer(
107111
os.chdir(cwd)
108112

109113
if transfer_type == "put":
110-
if not keep and scheme == "globus" and globus_status == "SUCCEEDED" and not non_blocking:
114+
if (
115+
not keep
116+
and scheme == "globus"
117+
and globus_status == "SUCCEEDED"
118+
and not non_blocking
119+
):
111120
# We should not keep the local file, so delete it now that it is on HPSS
112121
os.remove(file_path)
113122
if not keep and scheme != "globus":
114123
# We should not keep the local file, so delete it now that it is on HPSS
115124
os.remove(file_path)
116125

117126

118-
def hpss_put(hpss: str, file_path: str, cache: str, keep: bool = True, non_blocking: bool = False):
127+
def hpss_put(
128+
hpss: str, file_path: str, cache: str, keep: bool = True, non_blocking: bool = False
129+
):
119130
"""
120131
Put a file to the HPSS archive.
121132
"""

zstash/hpss_utils.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from .settings import BLOCK_SIZE, TupleFilesRowNoId, TupleTarsRowNoId, config, logger
1717
from .utils import create_tars_table, tars_table_exists, ts_utc
1818

19-
import subprocess
2019

2120
# Minimum output file object
2221
class HashIO(object):
@@ -165,9 +164,13 @@ def add_files(
165164
# process = subprocess.run(["ls", "-l", "zstash"], capture_output=True, text=True)
166165
# print(process.stdout)
167166

168-
logger.info(f"{ts_utc()}: DIVING: (add_files): Calling hpss_put to dispatch archive file {tfname}")
167+
logger.info(
168+
f"{ts_utc()}: DIVING: (add_files): Calling hpss_put to dispatch archive file {tfname}"
169+
)
169170
hpss_put(hpss, os.path.join(cache, tfname), cache, keep, non_blocking)
170-
logger.info(f"{ts_utc()}: SURFACE (add_files): Called hpss_put to dispatch archive file {tfname}")
171+
logger.info(
172+
f"{ts_utc()}: SURFACE (add_files): Called hpss_put to dispatch archive file {tfname}"
173+
)
171174

172175
# Update database with files that have been archived
173176
# Add a row to the "files" table,

zstash/utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@
44
import shlex
55
import sqlite3
66
import subprocess
7+
from datetime import datetime, timezone
78
from fnmatch import fnmatch
89
from typing import Any, List, Tuple
9-
from datetime import datetime, timezone
10-
1110

1211
from .settings import TupleTarsRow, config, logger
1312

13+
1414
def ts_utc():
1515
return datetime.now(timezone.utc).strftime("%Y%m%d_%H%M%S_%f")
1616

17+
1718
def filter_files(subset: str, files: List[str], include: bool) -> List[str]:
1819

1920
# Construct list of files to filter, based on

0 commit comments

Comments
 (0)