Skip to content

Commit ba4bf3a

Browse files
committed
fix filetype issue
1 parent 62b331d commit ba4bf3a

File tree

3 files changed

+27
-22
lines changed

3 files changed

+27
-22
lines changed

data_pipeline_api/fdp_utils.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,24 @@ def post_storage_root(
229229
data["root"] = data["root"] + "/"
230230
return post_entry(url, "storage_root", data, token, api_version)
231231

232+
def post_file_type(
233+
url: str, data: dict, token: str, api_version: str = "1.0.0"
234+
) -> dict:
235+
"""
236+
Internal wrapper function to return check if a file_type already exists and return it.
237+
"""
238+
if not "extension" in data and data["extension"]:
239+
raise ValueError("error file_type name not specified")
240+
file_type_exists = get_entry(url= url,
241+
endpoint= "file_type",
242+
query= {"extension": data["extension"]},
243+
api_version= api_version)
244+
if file_type_exists : return file_type_exists[0]
245+
return post_entry(url= url,
246+
endpoint= "file_type",
247+
data= data,
248+
token= token,
249+
api_version= api_version)
232250

233251
def remove_local_from_root(root: str) -> str:
234252
"""

data_pipeline_api/pipeline.py

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,10 @@ def initialise(token: str, config: str, script: str) -> dict:
8282
config_location_url = config_location_response["url"]
8383

8484
# Configure Yaml File Type
85-
config_filetype_response = fdp_utils.post_entry(
85+
config_filetype_response = fdp_utils.post_file_type(
8686
token=token,
8787
url=registry_url,
88-
endpoint="file_type",
89-
data={"name": "yaml", "extension": "yaml"},
88+
data={"name": "YAML Document", "extension": "yaml"},
9089
api_version=api_version,
9190
)
9291
config_filetype_url = config_filetype_response["url"]
@@ -174,14 +173,14 @@ def initialise(token: str, config: str, script: str) -> dict:
174173
)
175174

176175
script_location_url = script_location_response["url"]
176+
script_file_type = os.path.basename(script).split(".")[-1]
177177

178178
# TODO: Change to Batch?
179179
# Create Script File Type
180-
script_filetype_response = fdp_utils.post_entry(
180+
script_filetype_response = fdp_utils.post_file_type(
181181
token=token,
182182
url=registry_url,
183-
endpoint="file_type",
184-
data={"name": "py", "extension": "py"},
183+
data={"name": "python submission script", "extension": script_file_type},
185184
api_version=api_version,
186185
)
187186

@@ -478,23 +477,11 @@ def finalise(token: str, handle: dict) -> None:
478477

479478
file_type = os.path.basename(new_path).split(".")[-1]
480479

481-
file_type_exists = fdp_utils.get_entry(
480+
file_type_url = fdp_utils.post_file_type(
481+
token=token,
482482
url=registry_url,
483-
endpoint="file_type",
484-
query={"extension": file_type},
483+
data={"name": file_type, "extension": file_type},
485484
api_version=api_version,
486-
)
487-
488-
if file_type_exists:
489-
entry = fdp_utils.get_first_entry(file_type_exists)
490-
file_type_url = entry["url"]
491-
else:
492-
file_type_url = fdp_utils.post_entry(
493-
token=token,
494-
url=registry_url,
495-
endpoint="file_type",
496-
data={"name": file_type, "extension": file_type},
497-
api_version=api_version,
498485
)["url"]
499486

500487
data_product_exists = fdp_utils.get_entry(

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "data_pipeline_api"
3-
version = "0.7.5"
3+
version = "0.7.6"
44
description = "Python api to interact with the Fair Data Pipeline"
55
authors = [
66
"Ryan J Field <[email protected]>",

0 commit comments

Comments
 (0)