|
40 | 40 | from .loghandler import _logger, defaultStreamHandler
|
41 | 41 | from .mutation import MutationManager
|
42 | 42 | from .pack import pack
|
43 |
| -from .pathmapper import (adjustDirObjs, normalizeFilesDirs, trim_listing, |
44 |
| - visit_class) |
| 43 | +from .pathmapper import adjustDirObjs, normalizeFilesDirs, trim_listing |
45 | 44 | from .process import (Process, add_sizes, # pylint: disable=unused-import
|
46 | 45 | scandeps, shortname, use_custom_schema,
|
47 |
| - use_standard_schema) |
| 46 | + use_standard_schema, CWL_IANA) |
48 | 47 | from .provenance import ResearchObject
|
49 | 48 | from .resolver import ga4gh_tool_registries, tool_resolver
|
50 | 49 | from .secrets import SecretStore
|
|
53 | 52 | from .stdfsaccess import StdFsAccess
|
54 | 53 | from .update import ALLUPDATES, UPDATES
|
55 | 54 | from .utils import (DEFAULT_TMP_PREFIX, json_dumps, onWindows,
|
56 |
| - processes_to_kill, versionstring, |
| 55 | + processes_to_kill, versionstring, visit_class, |
57 | 56 | windows_default_container_id)
|
58 | 57 |
|
59 | 58 |
|
@@ -343,8 +342,13 @@ def init_job_order(job_order_object, # type: Optional[MutableMapping[Text
|
343 | 342 | job_order_object = {}
|
344 | 343 |
|
345 | 344 | if print_input_deps:
|
346 |
| - printdeps(job_order_object, loader, stdout, relative_deps, "", |
347 |
| - basedir=file_uri(str(input_basedir) + "/")) |
| 345 | + basedir = None |
| 346 | + uri = job_order_object["id"] |
| 347 | + if uri == args.workflow: |
| 348 | + basedir = os.path.dirname(uri) |
| 349 | + uri = "" |
| 350 | + printdeps(job_order_object, loader, stdout, relative_deps, uri, |
| 351 | + basedir=basedir, nestdirs=False) |
348 | 352 | exit(0)
|
349 | 353 |
|
350 | 354 | def path_to_loc(p):
|
@@ -388,40 +392,64 @@ def make_relative(base, obj):
|
388 | 392 | uri = uri_file_path(uri)
|
389 | 393 | obj["location"] = os.path.relpath(uri, base)
|
390 | 394 |
|
391 |
| - |
392 |
| -def printdeps(obj, # type: Optional[Mapping[Text, Any]] |
| 395 | +def printdeps(obj, # type: Mapping[Text, Any] |
393 | 396 | document_loader, # type: Loader
|
394 | 397 | stdout, # type: Union[TextIO, StreamWriter]
|
395 | 398 | relative_deps, # type: bool
|
396 | 399 | uri, # type: Text
|
397 |
| - prov_args=None, # type: Any |
398 |
| - basedir=None # type: Text |
399 |
| - ): # type: (...) -> Tuple[Optional[Dict[Text, Any]], Optional[Dict[Text, Any]]] |
| 400 | + basedir=None, # type: Text |
| 401 | + nestdirs=True # type: bool |
| 402 | + ): # type: (...) -> None |
400 | 403 | """Print a JSON representation of the dependencies of the CWL document."""
|
401 |
| - deps = {"class": "File", "location": uri} # type: Dict[Text, Any] |
| 404 | + deps = find_deps(obj, document_loader, uri, basedir=basedir, |
| 405 | + nestdirs=nestdirs) |
| 406 | + if relative_deps == "primary": |
| 407 | + base = basedir if basedir else os.path.dirname(uri_file_path(str(uri))) |
| 408 | + elif relative_deps == "cwd": |
| 409 | + base = os.getcwd() |
| 410 | + visit_class(deps, ("File", "Directory"), functools.partial( |
| 411 | + make_relative, base)) |
| 412 | + stdout.write(json_dumps(deps, indent=4)) |
| 413 | + |
| 414 | +def prov_deps(obj, # type: Mapping[Text, Any] |
| 415 | + document_loader, # type: Loader |
| 416 | + uri, # type: Text |
| 417 | + basedir=None # type: Text |
| 418 | + ): # type: (...) -> MutableMapping[Text, Any] |
| 419 | + deps = find_deps(obj, document_loader, uri, basedir=basedir) |
| 420 | + |
| 421 | + def remove_non_cwl(deps): # type: (MutableMapping[Text, Any]) -> None |
| 422 | + if 'secondaryFiles' in deps: |
| 423 | + sec_files = deps['secondaryFiles'] |
| 424 | + for index, entry in enumerate(sec_files): |
| 425 | + if not ('format' in entry and entry['format'] == CWL_IANA): |
| 426 | + del sec_files[index] |
| 427 | + else: |
| 428 | + remove_non_cwl(entry) |
| 429 | + |
| 430 | + remove_non_cwl(deps) |
| 431 | + return deps |
| 432 | + |
| 433 | + |
| 434 | +def find_deps(obj, # type: Mapping[Text, Any] |
| 435 | + document_loader, # type: Loader |
| 436 | + uri, # type: Text |
| 437 | + basedir=None, # type: Text |
| 438 | + nestdirs=True # type: bool |
| 439 | + ): # type: (...) -> Dict[Text, Any] |
| 440 | + """Find the dependencies of the CWL document.""" |
| 441 | + deps = {"class": "File", "location": uri, "format": CWL_IANA} # type: Dict[Text, Any] |
402 | 442 |
|
403 | 443 | def loadref(base, uri):
|
404 | 444 | return document_loader.fetch(document_loader.fetcher.urljoin(base, uri))
|
405 | 445 |
|
406 | 446 | sfs = scandeps(
|
407 | 447 | basedir if basedir else uri, obj, {"$import", "run"},
|
408 |
| - {"$include", "$schemas", "location"}, loadref) |
| 448 | + {"$include", "$schemas", "location"}, loadref, nestdirs=nestdirs) |
409 | 449 | if sfs:
|
410 | 450 | deps["secondaryFiles"] = sfs
|
411 | 451 |
|
412 |
| - if relative_deps: |
413 |
| - if relative_deps == "primary": |
414 |
| - base = basedir if basedir else os.path.dirname(uri_file_path(str(uri))) |
415 |
| - elif relative_deps == "cwd": |
416 |
| - base = os.getcwd() |
417 |
| - else: |
418 |
| - raise Exception(u"Unknown relative_deps %s" % relative_deps) |
419 |
| - absdeps = copy.deepcopy(deps) |
420 |
| - visit_class(deps, ("File", "Directory"), functools.partial(make_relative, base)) |
421 |
| - if prov_args: |
422 |
| - return (deps, absdeps) |
423 |
| - stdout.write(json_dumps(deps, indent=4)) |
424 |
| - return (None, None) |
| 452 | + return deps |
425 | 453 |
|
426 | 454 | def print_pack(document_loader, # type: Loader
|
427 | 455 | processobj, # type: Union[Dict[Text, Any], List[Dict[Text, Any]]]
|
@@ -501,7 +529,7 @@ def main(argsl=None, # type: List[str]
|
501 | 529 | if not hasattr(args, key):
|
502 | 530 | setattr(args, key, val)
|
503 | 531 |
|
504 |
| - ## Configure logging |
| 532 | + # Configure logging |
505 | 533 | rdflib_logger = logging.getLogger("rdflib.term")
|
506 | 534 | rdflib_logger.addHandler(stderr_handler)
|
507 | 535 | rdflib_logger.setLevel(logging.ERROR)
|
@@ -562,6 +590,7 @@ def main(argsl=None, # type: List[str]
|
562 | 590 | runtimeContext.research_obj = ro
|
563 | 591 | log_file_io = ro.open_log_file_for_activity(ro.engine_uuid)
|
564 | 592 | prov_log_handler = logging.StreamHandler(log_file_io)
|
| 593 | + |
565 | 594 | class ProvLogFormatter(logging.Formatter):
|
566 | 595 | """Enforce ISO8601 with both T and Z."""
|
567 | 596 | def __init__(self): # type: () -> None
|
@@ -613,7 +642,8 @@ def formatTime(self, record, datefmt=None):
|
613 | 642 | fetcher_constructor=loadingContext.fetcher_constructor)
|
614 | 643 |
|
615 | 644 | if args.print_deps:
|
616 |
| - printdeps(workflowobj, document_loader, stdout, args.relative_deps, uri) |
| 645 | + printdeps(workflowobj, document_loader, stdout, |
| 646 | + args.relative_deps, uri) |
617 | 647 | return 0
|
618 | 648 |
|
619 | 649 | document_loader, avsc_names, processobj, metadata, uri \
|
@@ -752,6 +782,7 @@ def my_represent_none(self, data): # pylint: disable=unused-argument
|
752 | 782 | if out is not None:
|
753 | 783 | if runtimeContext.research_obj:
|
754 | 784 | runtimeContext.research_obj.create_job(out, None, True)
|
| 785 | + |
755 | 786 | def loc_to_path(obj):
|
756 | 787 | for field in ("path", "nameext", "nameroot", "dirname"):
|
757 | 788 | if field in obj:
|
@@ -801,14 +832,9 @@ def loc_to_path(obj):
|
801 | 832 | finally:
|
802 | 833 | if args and runtimeContext and runtimeContext.research_obj \
|
803 | 834 | and workflowobj:
|
804 |
| - #adding all related cwl files to RO |
805 | 835 | research_obj = runtimeContext.research_obj
|
806 |
| - prov_dependencies = printdeps( |
807 |
| - workflowobj, document_loader, stdout, args.relative_deps, uri, |
808 |
| - research_obj) |
809 |
| - prov_dep = prov_dependencies[1] |
810 |
| - assert prov_dep |
811 |
| - research_obj.generate_snapshot(prov_dep) |
| 836 | + prov_dependencies = prov_deps(workflowobj, document_loader, uri) |
| 837 | + research_obj.generate_snapshot(prov_dependencies) |
812 | 838 | if prov_log_handler:
|
813 | 839 | # Stop logging so we won't half-log adding ourself to RO
|
814 | 840 | _logger.debug(u"[provenance] Closing provenance log file %s",
|
|
0 commit comments