Skip to content

Commit 565ad59

Browse files
committed
fix: coderabbit
1 parent 9d6de50 commit 565ad59

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

databusclient/api/delete.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ def _confirm_delete(databusURI: str) -> str:
2020
print("\nThis action is irreversible and will permanently remove the resource and all its data.")
2121
while True:
2222
choice = input("Type 'yes'/'y' to confirm, 'skip'/'s' to skip this resource, or 'cancel'/'c' to abort: ").strip().lower()
23-
if choice == "yes" or choice == "y":
23+
if choice in ("yes", "y"):
2424
return "confirm"
25-
elif choice == "skip" or choice == "s":
25+
elif choice in ("skip", "s"):
2626
return "skip"
27-
elif choice == "cancel" or choice == "c":
27+
elif choice in ("cancel", "c"):
2828
return "cancel"
2929
else:
3030
print("Invalid input. Please type 'yes'/'y', 'skip'/'s', or 'cancel'/'c'.")
@@ -107,12 +107,14 @@ def _delete_artifact(databusURI: str, databus_key: str, dry_run: bool = False, f
107107
versions = [versions]
108108
# Multiple versions case [{}, {}]
109109

110-
version_uris = [v["@id"] for v in versions if "@id" in v]
111-
if not version_uris:
112-
raise ValueError("No versions found in artifact JSON-LD")
110+
# If versions is None or empty skip
111+
if not versions:
112+
version_uris = [v["@id"] for v in versions if "@id" in v]
113+
if not version_uris:
114+
raise ValueError("No versions found in artifact JSON-LD")
113115

114-
# Delete all versions
115-
_delete_list(version_uris, databus_key, dry_run=dry_run, force=force)
116+
# Delete all versions
117+
_delete_list(version_uris, databus_key, dry_run=dry_run, force=force)
116118

117119
# Finally, delete the artifact itself
118120
_delete_resource(databusURI, databus_key, dry_run=dry_run, force=force)
@@ -150,7 +152,6 @@ def _delete_group(databusURI: str, databus_key: str, dry_run: bool = False, forc
150152
# Finally, delete the group itself
151153
_delete_resource(databusURI, databus_key, dry_run=dry_run, force=force)
152154

153-
# TODO: add to README.md
154155
def delete(databusURIs: List[str], databus_key: str, dry_run: bool, force: bool):
155156
"""
156157
Delete a dataset from the databus.

databusclient/client.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ def __download_file__(url, filename, vault_token_file=None, databus_key=None, au
522522
print("Redirects url: ", url)
523523

524524
# --- 2. Try direct GET ---
525-
response = requests.get(url, stream=True, allow_redirects=True)
525+
response = requests.get(url, stream=True, allow_redirects=True, timeout=30)
526526
www = response.headers.get('WWW-Authenticate', '') # get WWW-Authenticate header if present to check for Bearer auth
527527

528528
# Vault token required if 401 Unauthorized with Bearer challenge
@@ -536,7 +536,7 @@ def __download_file__(url, filename, vault_token_file=None, databus_key=None, au
536536
headers = {"Authorization": f"Bearer {vault_token}"}
537537

538538
# --- 4. Retry with token ---
539-
response = requests.get(url, headers=headers, stream=True)
539+
response = requests.get(url, headers=headers, stream=True, timeout=30)
540540

541541
# Databus API key required if only 401 Unauthorized
542542
elif response.status_code == 401:
@@ -545,7 +545,7 @@ def __download_file__(url, filename, vault_token_file=None, databus_key=None, au
545545
raise ValueError("Databus API key not given for protected download")
546546

547547
headers = {"X-API-KEY": databus_key}
548-
response = requests.get(url, headers=headers, stream=True)
548+
response = requests.get(url, headers=headers, stream=True, timeout=30)
549549

550550
try:
551551
response.raise_for_status() # Raise if still failing
@@ -718,12 +718,12 @@ def wsha256(raw: str):
718718
return sha256(raw.encode('utf-8')).hexdigest()
719719

720720

721-
def __handle_databus_collection__(uri: str, databus_key: str = None) -> str:
721+
def __handle_databus_collection__(uri: str, databus_key: str | None = None) -> str:
722722
headers = {"Accept": "text/sparql"}
723723
if databus_key is not None:
724724
headers["X-API-KEY"] = databus_key
725725

726-
return requests.get(uri, headers=headers).text
726+
return requests.get(uri, headers=headers, timeout=30).text
727727

728728

729729
def __download_list__(urls: List[str],
@@ -735,7 +735,7 @@ def __download_list__(urls: List[str],
735735
fileLocalDir = localDir
736736
for url in urls:
737737
if localDir is None:
738-
host, account, group, artifact, version, file = get_databus_id_parts_from_uri(url)
738+
_host, account, group, artifact, version, file = get_databus_id_parts_from_uri(url)
739739
fileLocalDir = os.path.join(os.getcwd(), account, group, artifact, version if version is not None else "latest")
740740
print(f"Local directory not given, using {fileLocalDir}")
741741

0 commit comments

Comments
 (0)