Skip to content

Commit 679c417

Browse files
authored
Merge pull request #975 from common-workflow-language/prov_decoupling
maintenance: refactor code in provenance
2 parents 9867c93 + 121c958 commit 679c417

File tree

11 files changed

+86
-87
lines changed

11 files changed

+86
-87
lines changed

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,6 @@ Workflow.make_workflow_step
698698
::
699699

700700
make_workflow_step(toolpath_object, pos, loadingContext, parentworkflowProv)
701-
(Dict[Text, Any], int, LoadingContext, Optional[CreateProvProfile]) -> WorkflowStep
701+
(Dict[Text, Any], int, LoadingContext, Optional[ProvenanceProfile]) -> WorkflowStep
702702

703703
Create and return a workflow step object.

cwltool/builder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929

3030
if TYPE_CHECKING:
31-
from .provenance import CreateProvProfile # pylint: disable=unused-import
31+
from .provenance import ProvenanceProfile # pylint: disable=unused-import
3232
CONTENT_LIMIT = 64 * 1024
3333

3434

@@ -162,7 +162,7 @@ def __init__(self,
162162
self.stagedir = stagedir
163163

164164
self.pathmapper = None # type: Optional[PathMapper]
165-
self.prov_obj = None # type: Optional[CreateProvProfile]
165+
self.prov_obj = None # type: Optional[ProvenanceProfile]
166166
self.find_default_container = None # type: Optional[Callable[[], Text]]
167167

168168
def build_job_script(self, commands):

cwltool/command_line_tool.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
docker_windows_path_adjust, json_dumps, onWindows,
5050
random_outdir, windows_default_container_id)
5151
if TYPE_CHECKING:
52-
from .provenance import CreateProvProfile # pylint: disable=unused-import
52+
from .provenance import ProvenanceProfile # pylint: disable=unused-import
5353

5454
ACCEPTLIST_EN_STRICT_RE = re.compile(r"^[a-zA-Z0-9._+-]+$")
5555
ACCEPTLIST_EN_RELAXED_RE = re.compile(r".*") # Accept anything
@@ -89,7 +89,7 @@ def __init__(self,
8989
self.outdir = outdir
9090
self.tmpdir = tmpdir
9191
self.script = script
92-
self.prov_obj = None # type: Optional[CreateProvProfile]
92+
self.prov_obj = None # type: Optional[ProvenanceProfile]
9393

9494
def run(self, runtimeContext): # type: (RuntimeContext) -> None
9595
try:
@@ -179,7 +179,7 @@ def __init__(self, job, output_callback, cachebuilder, jobcache):
179179
self.output_callback = output_callback
180180
self.cachebuilder = cachebuilder
181181
self.outdir = jobcache
182-
self.prov_obj = None # type: Optional[CreateProvProfile]
182+
self.prov_obj = None # type: Optional[ProvenanceProfile]
183183

184184
def run(self, runtimeContext):
185185
# type: (RuntimeContext) -> None

cwltool/context.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
if TYPE_CHECKING:
2222
from .process import Process
2323
from .provenance import (ResearchObject, # pylint: disable=unused-import
24-
CreateProvProfile)
24+
ProvenanceProfile)
2525

2626
class ContextBase(object):
2727
def __init__(self, kwargs=None):
@@ -63,7 +63,7 @@ def __init__(self, kwargs=None):
6363
self.cwl_full_name = "" # type: str
6464
self.host_provenance = False # type: bool
6565
self.user_provenance = False # type: bool
66-
self.prov_obj = None # type: Optional[CreateProvProfile]
66+
self.prov_obj = None # type: Optional[ProvenanceProfile]
6767

6868
super(LoadingContext, self).__init__(kwargs)
6969

@@ -131,7 +131,7 @@ def __init__(self, kwargs=None):
131131
self.orcid = '' # type: str
132132
self.cwl_full_name = "" # type: str
133133
self.process_run_id = None # type: Optional[str]
134-
self.prov_obj = None # type: Optional[CreateProvProfile]
134+
self.prov_obj = None # type: Optional[ProvenanceProfile]
135135
super(RuntimeContext, self).__init__(kwargs)
136136

137137

cwltool/executors.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from .mutation import MutationManager
2222
from .process import Process # pylint: disable=unused-import
2323
from .process import cleanIntermediate, relocateOutputs
24-
from .provenance import CreateProvProfile
24+
from .provenance import ProvenanceProfile
2525
from .utils import DEFAULT_TMP_PREFIX
2626
from .workflow import Workflow, WorkflowJob, WorkflowJobStep
2727

@@ -135,7 +135,7 @@ def run_jobs(self,
135135
# define provenance profile for single commandline tool
136136
if not isinstance(process, Workflow) \
137137
and runtime_context.research_obj is not None:
138-
process.provenance_object = CreateProvProfile(
138+
process.provenance_object = ProvenanceProfile(
139139
runtime_context.research_obj,
140140
full_name=runtime_context.cwl_full_name,
141141
host_provenance=False,
@@ -160,11 +160,12 @@ def run_jobs(self,
160160
else:
161161
runtime_context.prov_obj = job.prov_obj
162162
assert runtime_context.prov_obj
163-
process_run_id = \
164-
runtime_context.prov_obj.evaluate(
165-
process, job, job_order_object,
166-
runtime_context.make_fs_access,
167-
runtime_context.research_obj)
163+
runtime_context.prov_obj.evaluate(
164+
process, job, job_order_object,
165+
runtime_context.research_obj)
166+
process_run_id =\
167+
runtime_context.prov_obj.record_process_start(
168+
process, job)
168169
runtime_context = runtime_context.copy()
169170
runtime_context.process_run_id = process_run_id
170171
job.run(runtime_context)

cwltool/job.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
processes_to_kill, subprocess)
3838

3939
if TYPE_CHECKING:
40-
from .provenance import CreateProvProfile # pylint: disable=unused-import
40+
from .provenance import ProvenanceProfile # pylint: disable=unused-import
4141
needs_shell_quoting_re = re.compile(r"""(^$|[\s|&;()<>\'"$@])""")
4242

4343
FORCE_SHELLED_POPEN = os.getenv("CWLTOOL_FORCE_SHELL_POPEN", "0") == "1"
@@ -191,8 +191,8 @@ def __init__(self,
191191
self.generatefiles = {"class": "Directory", "listing": [], "basename": ""} # type: Directory
192192
self.stagedir = None # type: Optional[Text]
193193
self.inplace_update = False
194-
self.prov_obj = None # type: Optional[CreateProvProfile]
195-
self.parent_wf = None # type: Optional[CreateProvProfile]
194+
self.prov_obj = None # type: Optional[ProvenanceProfile]
195+
self.parent_wf = None # type: Optional[ProvenanceProfile]
196196
self.timelimit = None # type: Optional[int]
197197
self.networkaccess = False # type: bool
198198

@@ -340,11 +340,8 @@ def _execute(self,
340340
if runtimeContext.research_obj is not None and self.prov_obj is not None and \
341341
runtimeContext.process_run_id is not None:
342342
#creating entities for the outputs produced by each step (in the provenance document)
343-
self.prov_obj.generate_output_prov(
344-
outputs, runtimeContext.process_run_id, str(self.name))
345-
self.prov_obj.document.wasEndedBy(
346-
runtimeContext.process_run_id, None, self.prov_obj.workflow_run_uri,
347-
datetime.datetime.now())
343+
self.prov_obj.record_process_end(str(self.name), runtimeContext.process_run_id,
344+
outputs, datetime.datetime.now())
348345
if processStatus != "success":
349346
_logger.warning(u"[job %s] completed %s", self.name, processStatus)
350347
else:

cwltool/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,8 @@ def my_represent_none(self, data): # pylint: disable=unused-argument
808808

809809
if out is not None:
810810
if runtimeContext.research_obj is not None:
811-
runtimeContext.research_obj.create_job(out, None, True)
811+
runtimeContext.research_obj.create_job(
812+
out, None, True)
812813

813814
def loc_to_path(obj):
814815
for field in ("path", "nameext", "nameroot", "dirname"):

cwltool/process.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
except ImportError:
5252
from scandir import scandir # type: ignore
5353
if TYPE_CHECKING:
54-
from .provenance import CreateProvProfile # pylint: disable=unused-import
54+
from .provenance import ProvenanceProfile # pylint: disable=unused-import
5555

5656

5757
class LogAsDebugFilter(logging.Filter):
@@ -458,8 +458,8 @@ def __init__(self,
458458
loadingContext # type: LoadingContext
459459
): # type: (...) -> None
460460
self.metadata = getdefault(loadingContext.metadata, {}) # type: Dict[Text,Any]
461-
self.provenance_object = None # type: Optional[CreateProvProfile]
462-
self.parent_wf = None # type: Optional[CreateProvProfile]
461+
self.provenance_object = None # type: Optional[ProvenanceProfile]
462+
self.parent_wf = None # type: Optional[ProvenanceProfile]
463463
global SCHEMA_FILE, SCHEMA_DIR, SCHEMA_ANY # pylint: disable=global-statement
464464
if SCHEMA_FILE is None or SCHEMA_ANY is None or SCHEMA_DIR is None:
465465
get_schema("v1.0")

0 commit comments

Comments
 (0)