Skip to content

Commit 5558c04

Browse files
committed
fix: coderabbit
1 parent 292d2fa commit 5558c04

File tree

2 files changed

+43
-15
lines changed

2 files changed

+43
-15
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Command-line and Python client for downloading and deploying datasets on DBpedia
2020
- [Delete](#cli-delete)
2121
- [Module Usage](#module-usage)
2222
- [Deploy](#module-deploy)
23-
- [Contributing](#contributing)
23+
- [Development & Contributing](#development--contributing)
2424
- [Linting](#linting)
2525
- [Testing](#testing)
2626

@@ -558,7 +558,7 @@ from databusclient import deploy
558558
deploy(dataset, "mysterious API key")
559559
```
560560
561-
## Development
561+
## Development & Contributing
562562
563563
Install development dependencies yourself or via [Poetry](https://python-poetry.org/):
564564
@@ -570,7 +570,7 @@ poetry install --with dev
570570
571571
The used linter is [Ruff](https://ruff.rs/). Ruff is configured in `pyproject.toml` and is enforced in CI (`.github/workflows/ruff.yml`).
572572
573-
For development, you can run linting locally with `ruff check . ` and optionally auto-format with `ruff format .`.
573+
For development, you can run linting locally with `ruff check .` and optionally auto-format with `ruff format .`.
574574
575575
To ensure compatibility with the `pyproject.toml` configured dependencies, run Ruff via Poetry:
576576

databusclient/api/download.py

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,12 @@ def _download_file(
114114
file.write(data)
115115
progress_bar.close()
116116

117-
# TODO: could be a problem of github raw / openflaas
117+
# TODO: keep check or remove?
118118
if total_size_in_bytes != 0 and progress_bar.n != total_size_in_bytes:
119-
raise IOError("Downloaded size does not match Content-Length header")
119+
localsize = os.path.getsize(filename)
120+
print(f"\nHeaders: {response.headers}")
121+
print(f"\n[WARNING]: Downloaded size {progress_bar.n} does not match Content-Length header {total_size_in_bytes} ( local file size: {localsize})")
122+
# raise IOError("Downloaded size does not match Content-Length header")
120123

121124

122125
def _download_files(
@@ -407,12 +410,20 @@ def _get_databus_versions_of_artifact(
407410
json_dict = json.loads(json_str)
408411
versions = json_dict.get("databus:hasVersion")
409412

410-
# Single version case {}
413+
if versions is None:
414+
raise ValueError("No 'databus:hasVersion' field in artifact JSON-LD")
415+
411416
if isinstance(versions, dict):
412417
versions = [versions]
413-
# Multiple versions case [{}, {}]
418+
elif not isinstance(versions, list):
419+
raise ValueError(
420+
f"Unexpected type for 'databus:hasVersion': {type(versions).__name__}"
421+
)
422+
423+
version_urls = [
424+
v["@id"] for v in versions if isinstance(v, dict) and "@id" in v
425+
]
414426

415-
version_urls = [v["@id"] for v in versions if "@id" in v]
416427
if not version_urls:
417428
raise ValueError("No versions found in artifact JSON-LD")
418429

@@ -435,13 +446,16 @@ def _get_file_download_urls_from_artifact_jsonld(json_str: str) -> List[str]:
435446
List of all file download URLs in the artifact version.
436447
"""
437448

438-
databusIdUrl = []
449+
databusIdUrl: List[str] = []
450+
439451
json_dict = json.loads(json_str)
440452
graph = json_dict.get("@graph", [])
441453
for node in graph:
442454
if node.get("@type") == "Part":
443-
id = node.get("file")
444-
databusIdUrl.append(id)
455+
file_uri = node.get("file")
456+
if not isinstance(file_uri, str):
457+
continue
458+
databusIdUrl.append(file_uri)
445459
return databusIdUrl
446460

447461

@@ -488,10 +502,24 @@ def _get_databus_artifacts_of_group(json_str: str) -> List[str]:
488502
Returns a list of artifact URLs.
489503
"""
490504
json_dict = json.loads(json_str)
491-
artifacts = json_dict.get("databus:hasArtifact", [])
505+
artifacts = json_dict.get("databus:hasArtifact")
506+
507+
if artifacts is None:
508+
return []
492509

493-
result = []
494-
for item in artifacts:
510+
if isinstance(artifacts, dict):
511+
artifacts_iter = [artifacts]
512+
elif isinstance(artifacts, list):
513+
artifacts_iter = artifacts
514+
else:
515+
raise ValueError(
516+
f"Unexpected type for 'databus:hasArtifact': {type(artifacts).__name__}"
517+
)
518+
519+
result: List[str] = []
520+
for item in artifacts_iter:
521+
if not isinstance(item, dict):
522+
continue
495523
uri = item.get("@id")
496524
if not uri:
497525
continue
@@ -538,7 +566,7 @@ def download(
538566
# Auto-detect sparql endpoint from host if not given
539567
if uri_endpoint is None:
540568
uri_endpoint = f"https://{host}/sparql"
541-
print(f"SPARQL endpoint {endpoint}")
569+
print(f"SPARQL endpoint {uri_endpoint}")
542570

543571
if group == "collections" and artifact is not None:
544572
print(f"Downloading collection: {databusURI}")

0 commit comments

Comments
 (0)