diff --git a/crategen/converters/tes_converter.py b/crategen/converters/tes_converter.py index 0d7a0b9..6701627 100644 --- a/crategen/converters/tes_converter.py +++ b/crategen/converters/tes_converter.py @@ -25,37 +25,23 @@ def convert_to_wrroc(self, data: dict) -> dict: except ValidationError as e: raise ValueError(f"Invalid TES data: {e.errors()}") from e - # Extract validated data - ( - id, - name, - description, - creation_time, - state, - inputs, - outputs, - executors, - resources, - volumes, - logs, - tags, - ) = data_tes.dict().values() - end_time = logs[0].end_time + executors = data_tes.executors + end_time = data_tes.logs[0].end_time if data_tes.logs else None # Convert to WRROC format wrroc_data = { - "@id": id, - "name": name, - "description": description, - "instrument": executors[0]["image"] if executors else None, + "@id": data_tes.id, + "name": data_tes.name, + "description": data_tes.description, + "instrument": executors[0].image if executors else None, "object": [ - {"@id": input["url"], "name": input["path"], "type": input["type"]} - for input in inputs + {"@id": input.url, "name": input.path, "type": input.type} + for input in data_tes.inputs ], "result": [ - {"@id": output["url"], "name": output["path"]} for output in outputs + {"@id": output.url, "name": output.path} for output in data_tes.outputs ], - "startTime": creation_time, + "startTime": data_tes.creation_time, "endTime": end_time, } return wrroc_data diff --git a/crategen/converters/wes_converter.py b/crategen/converters/wes_converter.py index 619e069..856ce5f 100644 --- a/crategen/converters/wes_converter.py +++ b/crategen/converters/wes_converter.py @@ -61,6 +61,7 @@ def convert_from_wrroc(self, data: dict) -> dict: f"Invalid WRROC data for WES conversion: {e.errors()}" ) from e + # Convert from WRROC to WES format # Convert from WRROC to WES format wes_data = { "run_id": data_wrroc.id, diff --git a/crategen/models/tes_models.py b/crategen/models/tes_models.py index fed8d2c..407a9c0 100644 --- a/crategen/models/tes_models.py +++ b/crategen/models/tes_models.py @@ -158,7 +158,7 @@ def validate_content_and_url(cls, values): if content_is_set: values["url"] = None - elif not url_is_set: + elif not content_is_set and not url_is_set: raise ValueError( "The 'url' attribute is required when the 'content' attribute is empty" ) diff --git a/crategen/validators.py b/crategen/validators.py index 16dfc1c..6a10d39 100644 --- a/crategen/validators.py +++ b/crategen/validators.py @@ -16,14 +16,17 @@ def validate_wrroc(data: dict) -> Union[WRROCProvenance, WRROCWorkflow, WRROCPro """ Validate that the input data is a valid WRROC entity and determine which profile it adheres to. - This function attempts to validate the input data against the WRROCProvenance model first. If that validation fails, it attempts validation against the WRROCWorkflow model. If that also fails, it finally attempts validation against the WRROCProcess model. + Args: + data (dict): The input data to validate. + Returns: Union[WRROCProvenance, WRROCWorkflow, WRROCProcess]: The validated WRROC data, indicating the highest profile the data adheres to. + Raises: ValueError: If the data does not adhere to any of the WRROC profiles. """ diff --git a/lefthook.yml b/lefthook.yml index f6e5dfe..9d0ec7e 100644 --- a/lefthook.yml +++ b/lefthook.yml @@ -1,35 +1,6 @@ -# EXAMPLE USAGE: -# -# Refer for explanation to following link: -# https://github.com/evilmartians/lefthook/blob/master/docs/configuration.md -# -# pre-push: -# commands: -# packages-audit: -# tags: frontend security -# run: yarn audit -# gems-audit: -# tags: backend security -# run: bundle audit -# -# pre-commit: -# parallel: true -# commands: -# eslint: -# glob: "*.{js,ts,jsx,tsx}" -# run: yarn eslint {staged_files} -# rubocop: -# tags: backend style -# glob: "*.rb" -# exclude: '(^|/)(application|routes)\.rb$' -# run: bundle exec rubocop --force-exclusion {all_files} -# govet: -# tags: backend style -# files: git ls-files -m -# glob: "*.go" -# run: go vet {files} -# scripts: -# "hello.js": -# runner: node -# "any.go": -# runner: go run +pre-push: + commands: + ruff: + files: git diff --name-only --diff-filter=d $(git merge-base origin/main HEAD)..HEAD + run: poetry run ruff check {files} + glob: '*.py' diff --git a/pyproject.toml b/pyproject.toml index 0057e22..639b47a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -69,7 +69,7 @@ exclude = [ "build", "_build", "dist", - ".env" + ".env", ] indent-width = 4