Skip to content

Commit 4dbf85f

Browse files
committed
refactor: iteration over deploy.py
1 parent 464ec4f commit 4dbf85f

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed

databusclient/api/deploy.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class DeployLogLevel(Enum):
2323
debug = 2
2424

2525

26-
def __get_content_variants(distribution_str: str) -> Optional[Dict[str, str]]:
26+
def _get_content_variants(distribution_str: str) -> Optional[Dict[str, str]]:
2727
args = distribution_str.split("|")
2828

2929
# cv string is ALWAYS at position 1 after the URL
@@ -41,7 +41,7 @@ def __get_content_variants(distribution_str: str) -> Optional[Dict[str, str]]:
4141
return cvs
4242

4343

44-
def __get_filetype_definition(
44+
def _get_filetype_definition(
4545
distribution_str: str,
4646
) -> Tuple[Optional[str], Optional[str]]:
4747
file_ext = None
@@ -80,9 +80,9 @@ def __get_filetype_definition(
8080
return file_ext, compression
8181

8282

83-
def __get_extensions(distribution_str: str) -> Tuple[str, str, str]:
83+
def _get_extensions(distribution_str: str) -> Tuple[str, str, str]:
8484
extension_part = ""
85-
format_extension, compression = __get_filetype_definition(distribution_str)
85+
format_extension, compression = _get_filetype_definition(distribution_str)
8686

8787
if format_extension is not None:
8888
# build the format extension (only append compression if not none)
@@ -119,7 +119,7 @@ def __get_extensions(distribution_str: str) -> Tuple[str, str, str]:
119119
return extension_part, format_extension, compression
120120

121121

122-
def __get_file_stats(distribution_str: str) -> Tuple[Optional[str], Optional[int]]:
122+
def _get_file_stats(distribution_str: str) -> Tuple[Optional[str], Optional[int]]:
123123
metadata_list = distribution_str.split("|")[1:]
124124
# check whether there is the shasum:length tuple separated by :
125125
if len(metadata_list) == 0 or ":" not in metadata_list[-1]:
@@ -139,7 +139,7 @@ def __get_file_stats(distribution_str: str) -> Tuple[Optional[str], Optional[int
139139
return sha256sum, content_length
140140

141141

142-
def __load_file_stats(url: str) -> Tuple[str, int]:
142+
def _load_file_stats(url: str) -> Tuple[str, int]:
143143
resp = requests.get(url)
144144
if resp.status_code > 400:
145145
raise requests.exceptions.RequestException(response=resp)
@@ -149,20 +149,20 @@ def __load_file_stats(url: str) -> Tuple[str, int]:
149149
return sha256sum, content_length
150150

151151

152-
def __get_file_info(distribution_str: str) -> Tuple[Dict[str, str], str, str, str, int]:
153-
cvs = __get_content_variants(distribution_str)
154-
extension_part, format_extension, compression = __get_extensions(distribution_str)
152+
def get_file_info(distribution_str: str) -> Tuple[Dict[str, str], str, str, str, int]:
153+
cvs = _get_content_variants(distribution_str)
154+
extension_part, format_extension, compression = _get_extensions(distribution_str)
155155

156156
content_variant_part = "_".join([f"{key}={value}" for key, value in cvs.items()])
157157

158158
if __debug:
159159
print("DEBUG", distribution_str, extension_part)
160160

161-
sha256sum, content_length = __get_file_stats(distribution_str)
161+
sha256sum, content_length = _get_file_stats(distribution_str)
162162

163163
if sha256sum is None or content_length is None:
164164
__url = str(distribution_str).split("|")[0]
165-
sha256sum, content_length = __load_file_stats(__url)
165+
sha256sum, content_length = _load_file_stats(__url)
166166

167167
return cvs, format_extension, compression, sha256sum, content_length
168168

@@ -200,7 +200,7 @@ def create_distribution(
200200

201201
return f"{url}|{meta_string}"
202202

203-
def create_distributions_from_metadata(metadata: List[Dict[str, Union[str, int]]]) -> List[str]:
203+
def _create_distributions_from_metadata(metadata: List[Dict[str, Union[str, int]]]) -> List[str]:
204204
"""
205205
Create distributions from metadata entries.
206206
@@ -313,7 +313,7 @@ def create_dataset(
313313
compression,
314314
sha256sum,
315315
content_length,
316-
) = __get_file_info(dst_string)
316+
) = get_file_info(dst_string)
317317

318318
if not cvs and len(distributions) > 1:
319319
raise BadArgumentException(
@@ -453,7 +453,7 @@ def deploy_from_metadata(
453453
Parameters
454454
----------
455455
metadata : List[Dict[str, Union[str, int]]]
456-
List of file metadata entries (see create_distributions_from_metadata)
456+
List of file metadata entries (see _create_distributions_from_metadata)
457457
version_id : str
458458
Dataset version ID in the form $DATABUS_BASE/$ACCOUNT/$GROUP/$ARTIFACT/$VERSION
459459
title : str
@@ -467,7 +467,7 @@ def deploy_from_metadata(
467467
apikey : str
468468
API key for authentication
469469
"""
470-
distributions = create_distributions_from_metadata(metadata)
470+
distributions = _create_distributions_from_metadata(metadata)
471471

472472
dataset = create_dataset(
473473
version_id=version_id,

databusclient/api/download.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,11 @@ def _download_file(url, localDir, vault_token_file=None, databus_key=None, auth_
2626
"""
2727
if localDir is None:
2828
_host, account, group, artifact, version, file = get_databus_id_parts_from_uri(url)
29-
fileLocalDir = os.path.join(os.getcwd(), account, group, artifact, version if version is not None else "latest")
30-
print(f"Local directory not given, using {fileLocalDir}")
29+
localDir = os.path.join(os.getcwd(), account, group, artifact, version if version is not None else "latest")
30+
print(f"Local directory not given, using {localDir}")
3131

3232
file = url.split("/")[-1]
33-
filename = os.path.join(fileLocalDir, file)
34-
33+
filename = os.path.join(localDir, file)
3534
print(f"Download file: {url}")
3635
dirpath = os.path.dirname(filename)
3736
if dirpath:

tests/test_databusclient.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Client tests"""
22
import pytest
3-
from databusclient.api.deploy import create_dataset, create_distribution, __get_file_info
3+
from databusclient.api.deploy import create_dataset, create_distribution, get_file_info
44
from collections import OrderedDict
55

66

@@ -47,7 +47,7 @@ def test_distribution_cases():
4747
compression,
4848
sha256sum,
4949
content_length,
50-
) = __get_file_info(artifact_name, dst_string)
50+
) = get_file_info(artifact_name, dst_string)
5151

5252
created_dst_str = create_distribution(
5353
uri, cvs, formatExtension, compression, (sha256sum, content_length)

0 commit comments

Comments
 (0)