Skip to content
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

Scottx611x/td api #1646

Merged
merged 269 commits into from Mar 28, 2017
Merged

Scottx611x/td api #1646

merged 269 commits into from Mar 28, 2017

Conversation

scottx611x
Copy link
Member

@scottx611x scottx611x commented Mar 23, 2017

Closes #1613

  • Incorporation of related object deletion for ToolDefinitions
  • JSONSchema-based validation of Workflow step's annotations (Parameters/OutputFiles)
  • Proper Parameter/OutputFile association when generating ToolDefinitions

@codecov-io
Copy link

codecov-io commented Mar 23, 2017

Codecov Report

Merging #1646 into develop will increase coverage by 0.6%.
The diff coverage is 90%.

Impacted file tree graph

@@            Coverage Diff             @@
##           develop    #1646     +/-   ##
==========================================
+ Coverage    37.03%   37.64%   +0.6%     
==========================================
  Files          369      369             
  Lines        24093    24317    +224     
  Branches      1260     1260             
==========================================
+ Hits          8924     9153    +229     
+ Misses       15169    15164      -5
Impacted Files Coverage Δ
refinery/tool_manager/serializers.py 100% <100%> (ø) ⬆️
refinery/tool_manager/admin.py 100% <100%> (ø) ⬆️
refinery/tool_manager/models.py 95.18% <100%> (+1.63%) ⬆️
...r/management/commands/generate_tool_definitions.py 70.68% <66.66%> (+70.68%) ⬆️
refinery/tool_manager/utils.py 82.97% <72.09%> (-13.69%) ⬇️
refinery/tool_manager/tests.py 99.6% <99.38%> (-0.4%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8734d1c...cdc401e. Read the comment docs.



@receiver(pre_delete, sender=ToolDefinition)
def _tooldefinition_pre_delete(sender, instance, *args, **kwargs):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unsure of convention, _tool_definition_pre_delete?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, it's probably not a good idea to add the signal name to the handler name because signal name might change. It is better to describe what the function actually does (example)

@@ -13,10 +13,30 @@ class Meta:


class ParameterSerializer(serializers.ModelSerializer):
galaxy_workflow_step = serializers.SerializerMethodField(
method_name="_get_galaxy_workflow_step", required=False,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For readability, suggestion:
galaxy_workflow_step = serializers.SerializerMethodField(
method_name="_get_galaxy_workflow_step",
required=False,
allow_null=False
)

@@ -48,6 +50,7 @@ def handle(self, **options):

# Validate workflow annotation data, and try to create a
# ToolDefinition if validation passes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might make more sense to get the list of all the workflows from all the engines first to avoid an extra indentation level. It might also be helpful to factor out this functionality into a separate re-useable utility function.

for step_index in workflow_data["steps"]:
step = workflow_data["steps"][step_index]
# Check if any annotation provided, and try to convert
# to python dict if so
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is redundant: comments should be explaining "why", not "what".

# `parameters` we can pass here without
# raising an exception
pass
else:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed. Removing will help reduce indentation levels.

# `tool_inputs`
if (not parameter["name"] in
step["tool_inputs"]):
raise RuntimeError(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be CommandError?

# annotation data against the available
# parameters of the Workflow step's
# `tool_inputs`
if (not parameter["name"] in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be a membership test instead of a boolean

).galaxy_workflow_step
except (GalaxyParameter.DoesNotExist,
GalaxyParameter.MultipleObjectsReturned):
return None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually, return values should be of the same type and errors should be indicated by exceptions. Is returning None helpful here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this just allows the Parameter Serializer to include the GalaxyParameter models fields when need be, and disclude them from the response if we are dealing with parent Parameter objects



@receiver(pre_delete, sender=ToolDefinition)
def _tooldefinition_pre_delete(sender, instance, *args, **kwargs):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, it's probably not a good idea to add the signal name to the handler name because signal name might change. It is better to describe what the function actually does (example)



@receiver(post_delete, sender=ToolDefinition)
def _tooldefinition_post_delete(sender, instance, *args, **kwargs):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above



@receiver(pre_delete, sender=FileRelationship)
def _filerelationship_pre_delete(sender, instance, *args, **kwargs):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above


logger = logging.getLogger(__name__)
ANNOTATION_ERROR_MESSAGE = (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There probably should be no new line characters here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would be the alternative?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

workflow_list = []
workflow_engines = WorkflowEngine.objects.all()

sys.stdout.write(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably make this utility function re-useable in other parts of the application besides management commands. If so, it should not be writing anything to stdout.

"Generating ToolDefinitions from workflow engine {}\n"
.format(engine.name)
)
workflow_list = get_workflow_list()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_workflow_list() can raise RuntimeError exceptions that should be handled

@@ -111,40 +114,44 @@ def test_for_proper_parameters_response(self):

class ToolDefinitionGenerationTests(TestCase):
def test_workflow_improperly_annotated(self):
with open("tool_manager/test-data/workflow_annotation_invalid.json",
"r") as f:
with open("tool_manager/test-data/workflow_annotation_invalid"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be test_data instead of test-data?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hackdna I can rename the directory?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably a good idea for consistency. All other folder and file names appear to have underscores.

@scottx611x scottx611x merged commit 3cf0725 into develop Mar 28, 2017
@scottx611x scottx611x deleted the scottx611x/td_api branch March 28, 2017 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants