Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/cwltool/context.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 """Shared context objects that replace use of kwargs.""" | |
2 import copy | |
3 import os | |
4 import tempfile | |
5 import threading | |
6 from typing import IO, Any, Callable, Dict, Iterable, List, Optional, TextIO, Union | |
7 | |
8 # move to a regular typing import when Python 3.3-3.6 is no longer supported | |
9 from ruamel.yaml.comments import CommentedMap | |
10 from schema_salad.avro.schema import Names | |
11 from schema_salad.ref_resolver import Loader | |
12 from schema_salad.utils import FetcherCallableType | |
13 from typing_extensions import TYPE_CHECKING | |
14 | |
15 from .builder import Builder, HasReqsHints | |
16 from .mpi import MpiConfig | |
17 from .mutation import MutationManager | |
18 from .pathmapper import PathMapper | |
19 from .secrets import SecretStore | |
20 from .software_requirements import DependenciesConfiguration | |
21 from .stdfsaccess import StdFsAccess | |
22 from .utils import DEFAULT_TMP_PREFIX, CWLObjectType, ResolverType | |
23 | |
24 if TYPE_CHECKING: | |
25 from .process import Process | |
26 from .provenance import ResearchObject # pylint: disable=unused-import | |
27 from .provenance_profile import ProvenanceProfile | |
28 | |
29 | |
30 class ContextBase: | |
31 """Shared kwargs based initilizer for {Runtime,Loading}Context.""" | |
32 | |
33 def __init__(self, kwargs: Optional[Dict[str, Any]] = None) -> None: | |
34 """Initialize.""" | |
35 if kwargs: | |
36 for k, v in kwargs.items(): | |
37 if hasattr(self, k): | |
38 setattr(self, k, v) | |
39 | |
40 | |
41 def make_tool_notimpl( | |
42 toolpath_object: CommentedMap, loadingContext: "LoadingContext" | |
43 ) -> "Process": | |
44 raise NotImplementedError() | |
45 | |
46 | |
47 default_make_tool = make_tool_notimpl | |
48 | |
49 | |
50 class LoadingContext(ContextBase): | |
51 def __init__(self, kwargs: Optional[Dict[str, Any]] = None) -> None: | |
52 """Initialize the LoadingContext from the kwargs.""" | |
53 self.debug = False # type: bool | |
54 self.metadata = {} # type: CWLObjectType | |
55 self.requirements = None # type: Optional[List[CWLObjectType]] | |
56 self.hints = None # type: Optional[List[CWLObjectType]] | |
57 self.overrides_list = [] # type: List[CWLObjectType] | |
58 self.loader = None # type: Optional[Loader] | |
59 self.avsc_names = None # type: Optional[Names] | |
60 self.disable_js_validation = False # type: bool | |
61 self.js_hint_options_file = None | |
62 self.do_validate = True # type: bool | |
63 self.enable_dev = False # type: bool | |
64 self.strict = True # type: bool | |
65 self.resolver = None # type: Optional[ResolverType] | |
66 self.fetcher_constructor = None # type: Optional[FetcherCallableType] | |
67 self.construct_tool_object = default_make_tool | |
68 self.research_obj = None # type: Optional[ResearchObject] | |
69 self.orcid = "" # type: str | |
70 self.cwl_full_name = "" # type: str | |
71 self.host_provenance = False # type: bool | |
72 self.user_provenance = False # type: bool | |
73 self.prov_obj = None # type: Optional[ProvenanceProfile] | |
74 self.do_update = None # type: Optional[bool] | |
75 self.jobdefaults = None # type: Optional[CommentedMap] | |
76 self.doc_cache = True # type: bool | |
77 self.relax_path_checks = False # type: bool | |
78 | |
79 super().__init__(kwargs) | |
80 | |
81 def copy(self): | |
82 # type: () -> LoadingContext | |
83 return copy.copy(self) | |
84 | |
85 | |
86 class RuntimeContext(ContextBase): | |
87 def __init__(self, kwargs: Optional[Dict[str, Any]] = None) -> None: | |
88 """Initialize the RuntimeContext from the kwargs.""" | |
89 select_resources_callable = Callable[ # pylint: disable=unused-variable | |
90 [Dict[str, Union[int, float, str]], RuntimeContext], | |
91 Dict[str, Union[int, float, str]], | |
92 ] | |
93 self.user_space_docker_cmd = "" # type: Optional[str] | |
94 self.secret_store = None # type: Optional[SecretStore] | |
95 self.no_read_only = False # type: bool | |
96 self.custom_net = "" # type: Optional[str] | |
97 self.no_match_user = False # type: bool | |
98 self.preserve_environment = "" # type: Optional[Iterable[str]] | |
99 self.preserve_entire_environment = False # type: bool | |
100 self.use_container = True # type: bool | |
101 self.force_docker_pull = False # type: bool | |
102 | |
103 self.tmp_outdir_prefix = "" # type: str | |
104 self.tmpdir_prefix = DEFAULT_TMP_PREFIX # type: str | |
105 self.tmpdir = "" # type: str | |
106 self.rm_tmpdir = True # type: bool | |
107 self.pull_image = True # type: bool | |
108 self.rm_container = True # type: bool | |
109 self.move_outputs = "move" # type: str | |
110 | |
111 self.singularity = False # type: bool | |
112 self.disable_net = False # type: bool | |
113 self.debug = False # type: bool | |
114 self.compute_checksum = True # type: bool | |
115 self.name = "" # type: str | |
116 self.default_container = "" # type: Optional[str] | |
117 self.find_default_container = ( | |
118 None | |
119 ) # type: Optional[Callable[[HasReqsHints], Optional[str]]] | |
120 self.cachedir = None # type: Optional[str] | |
121 self.outdir = None # type: Optional[str] | |
122 self.stagedir = "" # type: str | |
123 self.part_of = "" # type: str | |
124 self.basedir = "" # type: str | |
125 self.toplevel = False # type: bool | |
126 self.mutation_manager = None # type: Optional[MutationManager] | |
127 self.make_fs_access = StdFsAccess # type: Callable[[str], StdFsAccess] | |
128 self.path_mapper = PathMapper | |
129 self.builder = None # type: Optional[Builder] | |
130 self.docker_outdir = "" # type: str | |
131 self.docker_tmpdir = "" # type: str | |
132 self.docker_stagedir = "" # type: str | |
133 self.js_console = False # type: bool | |
134 self.job_script_provider = None # type: Optional[DependenciesConfiguration] | |
135 self.select_resources = None # type: Optional[select_resources_callable] | |
136 self.eval_timeout = 20 # type: float | |
137 self.postScatterEval = ( | |
138 None | |
139 ) # type: Optional[Callable[[CWLObjectType], Optional[CWLObjectType]]] | |
140 self.on_error = "stop" # type: str | |
141 self.strict_memory_limit = False # type: bool | |
142 | |
143 self.cidfile_dir = None # type: Optional[str] | |
144 self.cidfile_prefix = None # type: Optional[str] | |
145 | |
146 self.workflow_eval_lock = None # type: Optional[threading.Condition] | |
147 self.research_obj = None # type: Optional[ResearchObject] | |
148 self.orcid = "" # type: str | |
149 self.cwl_full_name = "" # type: str | |
150 self.process_run_id = None # type: Optional[str] | |
151 self.prov_obj = None # type: Optional[ProvenanceProfile] | |
152 self.mpi_config = MpiConfig() # type: MpiConfig | |
153 self.default_stdout = None # type: Optional[Union[IO[bytes], TextIO]] | |
154 self.default_stderr = None # type: Optional[Union[IO[bytes], TextIO]] | |
155 super().__init__(kwargs) | |
156 if self.tmp_outdir_prefix == "": | |
157 self.tmp_outdir_prefix = self.tmpdir_prefix | |
158 | |
159 def get_outdir(self) -> str: | |
160 """Return self.outdir or create one with self.tmp_outdir_prefix.""" | |
161 if self.outdir: | |
162 return self.outdir | |
163 return self.create_outdir() | |
164 | |
165 def get_tmpdir(self) -> str: | |
166 """Return self.tmpdir or create one with self.tmpdir_prefix.""" | |
167 if self.tmpdir: | |
168 return self.tmpdir | |
169 return self.create_tmpdir() | |
170 | |
171 def get_stagedir(self) -> str: | |
172 """Return self.stagedir or create one with self.tmpdir_prefix.""" | |
173 if self.stagedir: | |
174 return self.stagedir | |
175 tmp_dir, tmp_prefix = os.path.split(self.tmpdir_prefix) | |
176 return tempfile.mkdtemp(prefix=tmp_prefix, dir=tmp_dir) | |
177 | |
178 def create_tmpdir(self) -> str: | |
179 """Create a temporary directory that respects self.tmpdir_prefix.""" | |
180 tmp_dir, tmp_prefix = os.path.split(self.tmpdir_prefix) | |
181 return tempfile.mkdtemp(prefix=tmp_prefix, dir=tmp_dir) | |
182 | |
183 def create_outdir(self) -> str: | |
184 """Create a temporary directory that respects self.tmp_outdir_prefix.""" | |
185 out_dir, out_prefix = os.path.split(self.tmp_outdir_prefix) | |
186 return tempfile.mkdtemp(prefix=out_prefix, dir=out_dir) | |
187 | |
188 def copy(self): | |
189 # type: () -> RuntimeContext | |
190 return copy.copy(self) | |
191 | |
192 | |
193 def getdefault(val, default): | |
194 # type: (Any, Any) -> Any | |
195 if val is None: | |
196 return default | |
197 else: | |
198 return val |