Skip to content

Commit 15863bf

Browse files
committed
feat: ruff linter & formatter
1 parent a8b1a10 commit 15863bf

10 files changed

Lines changed: 471 additions & 183 deletions

File tree

.github/workflows/ruff.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Ruff Linter & Formatter
2+
on: push
3+
jobs:
4+
build:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- uses: actions/checkout@v4
8+
- name: Install Python
9+
uses: actions/setup-python@v5
10+
with:
11+
python-version: "3.11"
12+
- name: Install dependencies
13+
run: |
14+
python -m pip install --upgrade pip
15+
pip install ruff
16+
# Update output format to enable automatic inline annotations.
17+
- name: Run Ruff
18+
run: ruff check --output-format=github .

databusclient/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from databusclient import cli
2-
from databusclient.api.deploy import create_dataset, deploy, create_distribution
2+
from databusclient.api.deploy import create_dataset, create_distribution, deploy
33

44
__all__ = ["create_dataset", "deploy", "create_distribution"]
55

6+
67
def run():
78
cli.app()

databusclient/api/delete.py

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import json
2-
import requests
32
from typing import List
43

5-
from databusclient.api.utils import get_databus_id_parts_from_uri, fetch_databus_jsonld
4+
import requests
5+
6+
from databusclient.api.utils import fetch_databus_jsonld, get_databus_id_parts_from_uri
7+
68

79
def _confirm_delete(databusURI: str) -> str:
810
"""
@@ -17,9 +19,17 @@ def _confirm_delete(databusURI: str) -> str:
1719
- "cancel" if the user chooses to cancel the entire deletion process
1820
"""
1921
print(f"Are you sure you want to delete: {databusURI}?")
20-
print("\nThis action is irreversible and will permanently remove the resource and all its data.")
22+
print(
23+
"\nThis action is irreversible and will permanently remove the resource and all its data."
24+
)
2125
while True:
22-
choice = input("Type 'yes'/'y' to confirm, 'skip'/'s' to skip this resource, or 'cancel'/'c' to abort: ").strip().lower()
26+
choice = (
27+
input(
28+
"Type 'yes'/'y' to confirm, 'skip'/'s' to skip this resource, or 'cancel'/'c' to abort: "
29+
)
30+
.strip()
31+
.lower()
32+
)
2333
if choice in ("yes", "y"):
2434
return "confirm"
2535
elif choice in ("skip", "s"):
@@ -30,7 +40,9 @@ def _confirm_delete(databusURI: str) -> str:
3040
print("Invalid input. Please type 'yes'/'y', 'skip'/'s', or 'cancel'/'c'.")
3141

3242

33-
def _delete_resource(databusURI: str, databus_key: str, dry_run: bool = False, force: bool = False):
43+
def _delete_resource(
44+
databusURI: str, databus_key: str, dry_run: bool = False, force: bool = False
45+
):
3446
"""
3547
Delete a single Databus resource (version, artifact, group).
3648
@@ -56,10 +68,7 @@ def _delete_resource(databusURI: str, databus_key: str, dry_run: bool = False, f
5668
if databus_key is None:
5769
raise ValueError("Databus API key must be provided for deletion")
5870

59-
headers = {
60-
"accept": "*/*",
61-
"X-API-KEY": databus_key
62-
}
71+
headers = {"accept": "*/*", "X-API-KEY": databus_key}
6372

6473
if dry_run:
6574
print(f"[DRY RUN] Would delete: {databusURI}")
@@ -70,10 +79,14 @@ def _delete_resource(databusURI: str, databus_key: str, dry_run: bool = False, f
7079
if response.status_code in (200, 204):
7180
print(f"Successfully deleted: {databusURI}")
7281
else:
73-
raise Exception(f"Failed to delete {databusURI}: {response.status_code} - {response.text}")
82+
raise Exception(
83+
f"Failed to delete {databusURI}: {response.status_code} - {response.text}"
84+
)
7485

7586

76-
def _delete_list(databusURIs: List[str], databus_key: str, dry_run: bool = False, force: bool = False):
87+
def _delete_list(
88+
databusURIs: List[str], databus_key: str, dry_run: bool = False, force: bool = False
89+
):
7790
"""
7891
Delete a list of Databus resources.
7992
@@ -85,7 +98,9 @@ def _delete_list(databusURIs: List[str], databus_key: str, dry_run: bool = False
8598
_delete_resource(databusURI, databus_key, dry_run=dry_run, force=force)
8699

87100

88-
def _delete_artifact(databusURI: str, databus_key: str, dry_run: bool = False, force: bool = False):
101+
def _delete_artifact(
102+
databusURI: str, databus_key: str, dry_run: bool = False, force: bool = False
103+
):
89104
"""
90105
Delete an artifact and all its versions.
91106
@@ -121,7 +136,10 @@ def _delete_artifact(databusURI: str, databus_key: str, dry_run: bool = False, f
121136
# Finally, delete the artifact itself
122137
_delete_resource(databusURI, databus_key, dry_run=dry_run, force=force)
123138

124-
def _delete_group(databusURI: str, databus_key: str, dry_run: bool = False, force: bool = False):
139+
140+
def _delete_group(
141+
databusURI: str, databus_key: str, dry_run: bool = False, force: bool = False
142+
):
125143
"""
126144
Delete a group and all its artifacts and versions.
127145
@@ -154,13 +172,14 @@ def _delete_group(databusURI: str, databus_key: str, dry_run: bool = False, forc
154172
# Finally, delete the group itself
155173
_delete_resource(databusURI, databus_key, dry_run=dry_run, force=force)
156174

175+
157176
def delete(databusURIs: List[str], databus_key: str, dry_run: bool, force: bool):
158177
"""
159178
Delete a dataset from the databus.
160179
161180
Delete a group, artifact, or version identified by the given databus URI.
162181
Will recursively delete all data associated with the dataset.
163-
182+
164183
Parameters:
165184
- databusURIs: List of full databus URIs of the resources to delete
166185
- databus_key: Databus API key to authenticate the deletion requests
@@ -169,7 +188,9 @@ def delete(databusURIs: List[str], databus_key: str, dry_run: bool, force: bool)
169188
"""
170189

171190
for databusURI in databusURIs:
172-
_host, _account, group, artifact, version, file = get_databus_id_parts_from_uri(databusURI)
191+
_host, _account, group, artifact, version, file = get_databus_id_parts_from_uri(
192+
databusURI
193+
)
173194

174195
if group == "collections" and artifact is not None:
175196
print(f"Deleting collection: {databusURI}")

databusclient/api/deploy.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
from enum import Enum
2-
from typing import List, Dict, Tuple, Optional, Union
3-
import requests
41
import hashlib
52
import json
3+
from enum import Enum
4+
from typing import Dict, List, Optional, Tuple, Union
5+
6+
import requests
67

78
__debug = False
89

@@ -200,7 +201,10 @@ def create_distribution(
200201

201202
return f"{url}|{meta_string}"
202203

203-
def _create_distributions_from_metadata(metadata: List[Dict[str, Union[str, int]]]) -> List[str]:
204+
205+
def _create_distributions_from_metadata(
206+
metadata: List[Dict[str, Union[str, int]]],
207+
) -> List[str]:
204208
"""
205209
Create distributions from metadata entries.
206210
@@ -233,24 +237,30 @@ def _create_distributions_from_metadata(metadata: List[Dict[str, Union[str, int]
233237
size = entry["size"]
234238
url = entry["url"]
235239
if not isinstance(size, int) or size <= 0:
236-
raise ValueError(f"Invalid size for {url}: expected positive integer, got {size}")
240+
raise ValueError(
241+
f"Invalid size for {url}: expected positive integer, got {size}"
242+
)
237243
# Validate SHA-256 hex digest (64 hex chars)
238-
if not isinstance(checksum, str) or len(checksum) != 64 or not all(
239-
c in '0123456789abcdefABCDEF' for c in checksum):
240-
raise ValueError(f"Invalid checksum for {url}")
244+
if (
245+
not isinstance(checksum, str)
246+
or len(checksum) != 64
247+
or not all(c in "0123456789abcdefABCDEF" for c in checksum)
248+
):
249+
raise ValueError(f"Invalid checksum for {url}")
241250

242251
distributions.append(
243252
create_distribution(
244253
url=url,
245254
cvs={"count": f"{counter}"},
246255
file_format=entry.get("file_format"),
247256
compression=entry.get("compression"),
248-
sha256_length_tuple=(checksum, size)
257+
sha256_length_tuple=(checksum, size),
249258
)
250259
)
251260
counter += 1
252261
return distributions
253262

263+
254264
def create_dataset(
255265
version_id: str,
256266
title: str,
@@ -361,7 +371,7 @@ def create_dataset(
361371
"@type": "Artifact",
362372
"title": title,
363373
"abstract": abstract,
364-
"description": description
374+
"description": description,
365375
}
366376
graphs.append(artifact_graph)
367377

@@ -445,7 +455,7 @@ def deploy_from_metadata(
445455
abstract: str,
446456
description: str,
447457
license_url: str,
448-
apikey: str
458+
apikey: str,
449459
) -> None:
450460
"""
451461
Deploy a dataset from metadata entries.
@@ -475,7 +485,7 @@ def deploy_from_metadata(
475485
abstract=abstract,
476486
description=description,
477487
license_url=license_url,
478-
distributions=distributions
488+
distributions=distributions,
479489
)
480490

481491
print(f"Deploying dataset version: {version_id}")

0 commit comments

Comments
 (0)