Skip to content

Commit

Permalink
Add get_info method on the Pipeline class #84
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Druez <tdruez@nexb.com>
  • Loading branch information
tdruez committed Feb 12, 2021
1 parent a2a6e8d commit 51ce0c4
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 20 deletions.
11 changes: 11 additions & 0 deletions scanpipe/pipelines/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ def get_graph(cls):
"""
return [{"name": step.__name__, "doc": getdoc(step)} for step in cls.steps]

@classmethod
def get_info(cls):
"""
Return a dict of combined data about this Pipeline.
"""
return {
"name": cls.get_name(),
"description": cls.get_doc(),
"steps": cls.get_graph(),
}

def log(self, message):
"""
Log the `message` to this module logger and to the Run instance.
Expand Down
24 changes: 12 additions & 12 deletions scanpipe/templates/scanpipe/project_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,35 +75,35 @@ <h2 class="subtitle mb-0 pt-2 mb-5">

<div class="column has-background-light has-border-radius">
<h3 class="subtitle mb-3">Pipelines:</h3>
{% for pipeline in pipelines %}
{% for pipeline_key, pipeline_info in pipelines.items %}
<div class="mb-3">
<div>
<a class="help-text modal-button" data-target="{{ pipeline.name }}-modal" aria-haspopup="true">
<strong>{{ pipeline.name }}</strong>
<a class="help-text modal-button" data-target="{{ pipeline_key }}-modal" aria-haspopup="true">
<strong>{{ pipeline_key }}</strong>
</a>
<div id="{{ pipeline.name }}-modal" class="modal">
<div id="{{ pipeline_key }}-modal" class="modal">
<div class="modal-background"></div>
<div class="modal-card">
<header class="modal-card-head">
<p class="modal-card-title">
<strong>{{ pipeline.name }}</strong>
<strong>{{ pipeline_key }}</strong>
</p>
<button class="delete" aria-label="close"></button>
</header>
<div class="notification has-background-info-light has-text-weight-semibold is-radiusless mb-0">
{{ pipeline.description }}
{{ pipeline_info.description }}
</div>
<section class="modal-card-body has-text-centered border-bottom-radius">
{% for step in pipeline.steps %}
<span class="tag is-info">{{ step.name }}</span>
<div>{{ step.doc }}</div>
{% if not forloop.last %}<div>&darr;</div>{% endif %}
{% endfor %}
{% for step in pipeline_info.steps %}
<span class="tag is-info">{{ step.name }}</span>
<div>{{ step.doc }}</div>
{% if not forloop.last %}<div>&darr;</div>{% endif %}
{% endfor %}
</section>
</div>
</div>
</div>
{{ pipeline.description }}
{{ pipeline_info.description }}
</div>
{% endfor %}
</div>
Expand Down
11 changes: 11 additions & 0 deletions scanpipe/tests/test_pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ def test_scanpipe_pipelines_class_get_doc(self):
self.assertEqual(expected, pipeline_class.get_doc())
self.assertEqual(expected, pipeline_instance.get_doc())

def test_scanpipe_pipelines_class_get_info(self):
expected = {
"name": "DoNothing",
"description": "A pipeline that does nothing, in 2 steps.",
"steps": [
{"name": "step1", "doc": "Step1 doc."},
{"name": "step2", "doc": "Step2 doc."},
],
}
self.assertEqual(expected, DoNothing.get_info())

def test_scanpipe_pipeline_class_log(self):
project1 = Project.objects.create(name="Analysis")
run = project1.add_pipeline("do_nothing")
Expand Down
12 changes: 4 additions & 8 deletions scanpipe/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,10 @@ class ProjectCreateView(generic.CreateView):

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["pipelines"] = [
{
"name": name,
"description": pipeline_class.get_doc(),
"steps": pipeline_class.get_graph(),
}
for name, pipeline_class in scanpipe_app_config.pipelines.items()
]
context["pipelines"] = {
key: pipeline_class.get_info()
for key, pipeline_class in scanpipe_app_config.pipelines.items()
}
return context

def get_success_url(self):
Expand Down

0 comments on commit 51ce0c4

Please sign in to comment.