Skip to content

Commit f87bef2

Browse files
Merge pull request #179 from fair-workflows/auto-publish-steps
Reintroduce autopublishing of steps
2 parents c9707d7 + c70aebb commit f87bef2

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

fairworkflows/fairworkflow.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ def draw(self, filepath):
431431
'Cannot produce visualization of RDF, you need to install '
432432
'graphviz dependency https://graphviz.org/')
433433

434-
def publish_as_nanopub(self, use_test_server=False, **kwargs):
434+
def publish_as_nanopub(self, use_test_server=False, publish_steps=False, **kwargs):
435435
"""Publish to nanopub server.
436436
437437
Publish the workflow as nanopublication to the nanopub server.
@@ -441,6 +441,9 @@ def publish_as_nanopub(self, use_test_server=False, **kwargs):
441441
442442
Args:
443443
use_test_server (bool): Toggle using the test nanopub server.
444+
publish_steps (bool): Toggle publishing publishing all unpublished steps first before
445+
publishing the workflow. (Otherwise an exception is raised and unpublished steps
446+
need to be published manually first)
444447
kwargs: Keyword arguments to be passed to [nanopub.Publication.from_assertion](
445448
https://nanopub.readthedocs.io/en/latest/reference/publication.html#
446449
nanopub.publication.Publication.from_assertion).
@@ -453,7 +456,11 @@ def publish_as_nanopub(self, use_test_server=False, **kwargs):
453456
for step in self:
454457
if step.is_modified or not step._is_published:
455458
self._is_modified = True # If one of the steps is modified the workflow is too.
456-
raise RuntimeError(f'{step} was not published yet, please publish steps first')
459+
if publish_steps:
460+
step.publish_as_nanopub(use_test_server=use_test_server, **kwargs)
461+
else:
462+
raise RuntimeError(f'{step} was not published yet, please publish steps first, '
463+
f'or use force=True')
457464

458465
return self._publish_as_nanopub(use_test_server=use_test_server, **kwargs)
459466

tests/test_fairworkflow.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,10 @@ def test_publish_as_nanopub(self, mock_publish, test_workflow):
277277
{'concept_uri': test_published_uris[3]} # Last call
278278
]
279279
with pytest.raises(RuntimeError):
280-
# 'Publishing a workflow with unpublished steps must raise RunTimeError'
280+
# 'Publishing a workflow with unpublished steps must raise RunTimeError...'
281281
test_workflow.publish_as_nanopub()
282-
# First publish the steps
283-
for step in test_workflow:
284-
step.publish_as_nanopub()
285-
pubinfo = test_workflow.publish_as_nanopub()
282+
# ...unless using pubish_steps=True
283+
pubinfo = test_workflow.publish_as_nanopub(publish_steps=True)
286284
assert pubinfo['concept_uri'] == 'www.example.org/published_workflow#workflow'
287285
assert mock_publish.call_count == 4 # 1 workflow, 3 steps
288286
for step in test_workflow:

0 commit comments

Comments
 (0)