comparison env/lib/python3.9/site-packages/galaxy/tool_util/cwl/cwltool_deps.py @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4f3585e2f14b
1 """Logic for dealing with cwltool as an optional dependency.
2
3 Use this as the import interface for cwltool and just call
4 :func:`ensure_cwltool_available` before using any of the imported
5 functionality at runtime.
6 """
7 import re
8 import warnings
9
10 warnings.filterwarnings("ignore", message=r"[\n.]DEPRECATION: Python 2", module="cwltool")
11
12 import requests
13
14 try:
15 from cwltool import (
16 main,
17 workflow,
18 job,
19 process,
20 pathmapper,
21 )
22 except ImportError:
23 main = None # type: ignore
24 workflow = None # type: ignore
25 job = None # type: ignore
26 process = None # type: ignore
27 pathmapper = None # type: ignore
28
29 try:
30 from cwltool.context import (
31 getdefault,
32 LoadingContext,
33 RuntimeContext,
34 )
35 from cwltool.job import relink_initialworkdir
36 from cwltool.stdfsaccess import StdFsAccess
37 except ImportError:
38 getdefault = None # type: ignore
39 LoadingContext = None # type: ignore
40 relink_initialworkdir = None # type: ignore
41 RuntimeContext = None # type: ignore
42 StdFsAccess = None # type: ignore
43
44 try:
45 from cwltool import load_tool
46 from cwltool.load_tool import (
47 default_loader,
48 resolve_and_validate_document,
49 )
50 except ImportError:
51 default_loader = None # type: ignore
52 load_tool = None # type: ignore
53 resolve_and_validate_document = None # type: ignore
54
55
56 def _has_relax_path_checks_flag():
57 """Return True if cwltool uses a flag to control path checks.
58
59 Old cwltool uses the module global below to control whether
60 it's strict about path checks. New versions use an attribute
61 of LoadingContext.
62
63 Once the version of cwltool required is new enough, we can remove
64 this function and simplify the conditionals where it's used.
65 """
66
67 lc = LoadingContext()
68 return hasattr(lc, "relax_path_checks")
69
70
71 try:
72 from cwltool import command_line_tool
73 if not _has_relax_path_checks_flag():
74 command_line_tool.ACCEPTLIST_RE = command_line_tool.ACCEPTLIST_EN_RELAXED_RE
75 except ImportError:
76 command_line_tool = None # type: ignore
77
78 try:
79 from cwltool.load_tool import resolve_and_validate_document
80 except ImportError:
81 resolve_and_validate_document = None # type: ignore
82
83 try:
84 import shellescape
85 except ImportError:
86 shellescape = None # type: ignore
87
88 try:
89 import schema_salad
90 from schema_salad import (
91 ref_resolver,
92 sourceline,
93 )
94 except ImportError:
95 schema_salad = None # type: ignore
96 ref_resolver = None # type: ignore
97 sourceline = None # type: ignore
98
99 needs_shell_quoting = re.compile(r"""(^$|[\s|&;()<>\'"$@])""").search
100
101 # if set to True, file format checking is not performed.
102 beta_relaxed_fmt_check = True
103
104
105 def ensure_cwltool_available():
106 """Assert optional dependencies proxied via this module are available at runtime.
107
108 Throw an ImportError with a description of the problem if they do not exist.
109 """
110 if main is None or workflow is None or shellescape is None:
111 message = "This feature requires cwltool and dependencies to be available, they are not."
112 if main is None:
113 message += " cwltool is not unavailable."
114 elif resolve_and_validate_document is None:
115 message += " cwltool.load_tool.resolve_and_validate_document is unavailable - cwltool version is too old."
116 if requests is None:
117 message += " Library 'requests' unavailable."
118 if shellescape is None:
119 message += " Library 'shellescape' unavailable."
120 if schema_salad is None:
121 message += " Library 'schema_salad' unavailable."
122 raise ImportError(message)
123
124
125 __all__ = (
126 'default_loader',
127 'ensure_cwltool_available',
128 'getdefault',
129 'load_tool',
130 'LoadingContext',
131 'main',
132 'needs_shell_quoting',
133 'pathmapper',
134 'process',
135 'ref_resolver',
136 'relink_initialworkdir',
137 'resolve_and_validate_document',
138 'RuntimeContext',
139 'schema_salad',
140 'shellescape',
141 'sourceline',
142 'StdFsAccess',
143 'workflow',
144 )