-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Config lefthook #25
Merged
Merged
Config lefthook #25
Changes from 20 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
db0fc0d
improve tes models
775e72f
update lint config and fix lint issue
4c82117
block push if lint fails
9724ccf
block push if lint fails
f64ba49
configure lefthook
db07662
configure lefthook
0b4b94b
Revert "configure lefthook"
17cee80
Revert "configure lefthook"
54a4d31
Revert "configure lefthook"
d7bf79f
configure lefthook
8d6f81a
configure lefthook
25eb0c5
lint code
1697a12
lint code
600134c
lint code
d400654
add utils.py
db31c39
lint code
662adb1
remove tes models from default models file
4157c5e
separate models into different files
fae0a06
lint code
c5be79a
fix test imports
420bbe6
Merge remote-tracking branch 'origin/models' into config-lefthook
4830de7
lint
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,37 @@ | ||
import click | ||
import json | ||
|
||
import click | ||
|
||
from crategen.converter_manager import ConverterManager | ||
|
||
|
||
@click.command() | ||
@click.option('--input', prompt='Input file', help='Path to the input JSON file.') | ||
@click.option('--output', prompt='Output file', help='Path to the output JSON file.') | ||
@click.option('--conversion-type', prompt='Conversion type', type=click.Choice(['tes-to-wrroc', 'wes-to-wrroc']), help='Type of conversion to perform.') | ||
@click.option("--input", prompt="Input file", help="Path to the input JSON file.") | ||
@click.option("--output", prompt="Output file", help="Path to the output JSON file.") | ||
@click.option( | ||
"--conversion-type", | ||
prompt="Conversion type", | ||
type=click.Choice(["tes-to-wrroc", "wes-to-wrroc"]), | ||
help="Type of conversion to perform.", | ||
) | ||
def cli(input, output, conversion_type): | ||
""" | ||
Command Line Interface for converting TES/WES to WRROC. | ||
""" | ||
"""Command Line Interface for converting TES/WES to WRROC.""" | ||
manager = ConverterManager() | ||
|
||
# Load input data from JSON file | ||
with open(input, 'r') as input_file: | ||
with open(input) as input_file: | ||
data = json.load(input_file) | ||
|
||
# Perform the conversion based on the specified type | ||
if conversion_type == 'tes-to-wrroc': | ||
if conversion_type == "tes-to-wrroc": | ||
result = manager.convert_tes_to_wrroc(data) | ||
elif conversion_type == 'wes-to-wrroc': | ||
elif conversion_type == "wes-to-wrroc": | ||
result = manager.convert_wes_to_wrroc(data) | ||
|
||
# Save the result to the output JSON file | ||
with open(output, 'w') as output_file: | ||
with open(output, "w") as output_file: | ||
json.dump(result, output_file, indent=4) | ||
|
||
if __name__ == '__main__': | ||
|
||
if __name__ == "__main__": | ||
cli() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
from abc import ABC, abstractmethod | ||
|
||
|
||
class AbstractConverter(ABC): | ||
@abstractmethod | ||
def convert_to_wrroc(self, data): | ||
"""Convert data to WRROC format""" | ||
|
||
@abstractmethod | ||
def convert_from_wrroc(self, wrroc_data): | ||
"""Convert WRROC data to the original format""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,50 @@ | ||
from .abstract_converter import AbstractConverter | ||
from .utils import convert_to_iso8601 | ||
from ..models import TESData, WRROCDataTES | ||
from pydantic import ValidationError | ||
|
||
class TESConverter(AbstractConverter): | ||
from ..models.tes_models import TESData | ||
from ..models.wrroc_models import WRROCDataTES | ||
from .abstract_converter import AbstractConverter | ||
|
||
|
||
class TESConverter(AbstractConverter): | ||
def convert_to_wrroc(self, tes_data): | ||
# Validate TES data | ||
try: | ||
validated_tes_data = TESData(**tes_data) | ||
except ValidationError as e: | ||
raise ValueError(f"Invalid TES data: {e}") | ||
raise ValueError(f"Invalid TES data: {e}") from e | ||
|
||
# Extract validated data | ||
id = validated_tes_data.id | ||
name = validated_tes_data.name | ||
description = validated_tes_data.description | ||
executors = validated_tes_data.executors | ||
inputs = validated_tes_data.inputs | ||
outputs = validated_tes_data.outputs | ||
creation_time = validated_tes_data.creation_time | ||
end_time = validated_tes_data.logs[0].end_time if validated_tes_data.logs else "" | ||
( | ||
id, | ||
name, | ||
description, | ||
creation_time, | ||
state, | ||
inputs, | ||
outputs, | ||
executors, | ||
resources, | ||
volumes, | ||
logs, | ||
tags, | ||
) = validated_tes_data.dict().values() | ||
end_time = validated_tes_data.logs[0].end_time | ||
|
||
# Convert to WRROC | ||
wrroc_data = { | ||
"@id": id, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (code-quality): Inline variable that is immediately returned ( |
||
"name": name, | ||
"description": description, | ||
"instrument": executors[0].image if executors else None, | ||
"object": [{"@id": input.url, "name": input.path} for input in inputs], | ||
"result": [{"@id": output.url, "name": output.path} for output in outputs], | ||
"startTime": convert_to_iso8601(creation_time), | ||
"endTime": convert_to_iso8601(end_time), | ||
"instrument": executors[0]["image"] if executors else None, | ||
"object": [ | ||
{"@id": input["url"], "name": input["path"], "type": input["type"]} | ||
for input in inputs | ||
], | ||
"result": [ | ||
{"@id": output["url"], "name": output["path"]} for output in outputs | ||
], | ||
"startTime": creation_time, | ||
"endTime": end_time, | ||
} | ||
return wrroc_data | ||
|
||
|
@@ -40,7 +53,7 @@ def convert_from_wrroc(self, data): | |
try: | ||
validated_data = WRROCDataTES(**data) | ||
except ValidationError as e: | ||
raise ValueError(f"Invalid WRROC data for TES conversion: {e}") | ||
raise ValueError(f"Invalid WRROC data for TES conversion: {e}") from e | ||
|
||
# Extract validated data | ||
id = validated_data.id | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Use a more robust method for extracting validated data
Using .dict().values() is potentially fragile if the order of fields in the Pydantic model changes. Consider using named attributes instead, e.g., validated_tes_data.id, validated_tes_data.name, etc. This would make the code more robust and easier to understand.