Skip to content

Commit 2cf65d6

Browse files
Regen parsers without mypyc decorators
1 parent 7edbaf2 commit 2cf65d6

5 files changed

Lines changed: 166 additions & 205 deletions

File tree

cwl_utils/parser/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,9 @@ def load_document_by_uri(
285285
base_uri = path.resolve().parent.as_uri()
286286
id_ = path.resolve().name.split("#")[1] if "#" in path.resolve().name else None
287287

288-
if loadingOptions is None:
289-
loadingOptions = LoadingOptions(fileuri=real_uri, baseuri=base_uri)
288+
loadingOptions = LoadingOptions(
289+
fileuri=real_uri, baseuri=base_uri, copyfrom=loadingOptions
290+
)
290291

291292
return load_document_by_string(
292293
loadingOptions.fetcher.fetch_text(real_uri),

cwl_utils/parser/cwl_v1_0.py

Lines changed: 47 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
import sys
99
import uuid as _uuid__
1010
from collections.abc import Collection
11-
from mypy_extensions import trait
1211
from typing import ClassVar
1312

1413
from schema_salad.runtime import (
14+
Saveable,
1515
file_uri,
1616
parse_errors,
1717
prefix_url,
@@ -23,25 +23,27 @@
2323
from typing import Self
2424
else:
2525
from typing_extensions import Self
26+
2627
import schema_salad.metaschema
2728

2829
import copy
29-
3030
from collections.abc import MutableSequence, Sequence, MutableMapping
3131
from io import StringIO
3232
from itertools import chain
33-
from typing import Any, Final, cast, Generic, TypeVar
33+
from typing import Any, Final, cast, Generic
3434
from urllib.parse import urldefrag, urlsplit, urlunsplit
3535

3636
from ruamel.yaml.comments import CommentedMap
3737

3838
from schema_salad.exceptions import ValidationException, SchemaSaladException
39-
from schema_salad.runtime import LoadingOptions, convert_typing, extract_type, Saveable
39+
from schema_salad.runtime import (
40+
LoadingOptions,
41+
convert_typing,
42+
extract_type,
43+
SaveableType,
44+
)
4045
from schema_salad.sourceline import SourceLine, add_lc_filename
41-
from schema_salad.utils import yaml_no_ts
42-
43-
S = TypeVar("S", bound=Saveable)
44-
46+
from schema_salad.utils import yaml_no_ts # requires schema-salad v8.2+
4547

4648
_vocab: Final[dict[str, str]] = {}
4749
_rvocab: Final[dict[str, str]] = {}
@@ -287,10 +289,10 @@ def load(
287289
return self.inner.load(r, baseuri, loadingOptions, docRoot, lc=lc)
288290

289291

290-
class _RecordLoader(_Loader, Generic[S]):
292+
class _RecordLoader(_Loader, Generic[SaveableType]):
291293
def __init__(
292294
self,
293-
classtype: type[S],
295+
classtype: type[SaveableType],
294296
container: str | None = None,
295297
no_link_check: bool | None = None,
296298
) -> None:
@@ -305,7 +307,7 @@ def load(
305307
loadingOptions: LoadingOptions,
306308
docRoot: str | None = None,
307309
lc: Any | None = None,
308-
) -> S:
310+
) -> SaveableType:
309311
if not isinstance(doc, MutableMapping):
310312
raise ValidationException(
311313
f"Value is a {convert_typing(extract_type(type(doc)))}, "
@@ -1633,9 +1635,9 @@ def fromDoc(
16331635

16341636
vocab = _vocab | loadingOptions.vocab
16351637
if class_ not in (cls.__name__, vocab.get(cls.__name__)):
1636-
raise ValidationException(f"tried `{cls.__name__}` but")
1638+
raise ValidationException(f"tried `{cls.__name__}` but")
16371639
except ValidationException as e:
1638-
raise e
1640+
raise e
16391641
location = None
16401642
if "location" in _doc:
16411643
try:
@@ -2377,9 +2379,9 @@ def fromDoc(
23772379

23782380
vocab = _vocab | loadingOptions.vocab
23792381
if class_ not in (cls.__name__, vocab.get(cls.__name__)):
2380-
raise ValidationException(f"tried `{cls.__name__}` but")
2382+
raise ValidationException(f"tried `{cls.__name__}` but")
23812383
except ValidationException as e:
2382-
raise e
2384+
raise e
23832385
location = None
23842386
if "location" in _doc:
23852387
try:
@@ -2651,12 +2653,10 @@ def save(
26512653
)
26522654

26532655

2654-
@trait
26552656
class SchemaBase(Saveable):
26562657
pass
26572658

26582659

2659-
@trait
26602660
class Parameter(SchemaBase):
26612661
"""
26622662
Define an input or output parameter to a process.
@@ -2666,22 +2666,18 @@ class Parameter(SchemaBase):
26662666
pass
26672667

26682668

2669-
@trait
26702669
class InputBinding(Saveable):
26712670
pass
26722671

26732672

2674-
@trait
26752673
class OutputBinding(Saveable):
26762674
pass
26772675

26782676

2679-
@trait
26802677
class InputSchema(SchemaBase):
26812678
pass
26822679

26832680

2684-
@trait
26852681
class OutputSchema(SchemaBase):
26862682
pass
26872683

@@ -6525,7 +6521,6 @@ def save(
65256521
)
65266522

65276523

6528-
@trait
65296524
class ProcessRequirement(Saveable):
65306525
"""
65316526
A process requirement declares a prerequisite that may or must be fulfilled before executing a process. See ```Process.hints`` <#process>`__ and ```Process.requirements`` <#process>`__.
@@ -6537,7 +6532,6 @@ class ProcessRequirement(Saveable):
65376532
pass
65386533

65396534

6540-
@trait
65416535
class Process(Saveable):
65426536
"""
65436537
The base executable type in CWL is the ``Process`` object defined by the document. Note that the ``Process`` object is abstract and cannot be directly executed.
@@ -6609,9 +6603,9 @@ def fromDoc(
66096603

66106604
vocab = _vocab | loadingOptions.vocab
66116605
if class_ not in (cls.__name__, vocab.get(cls.__name__)):
6612-
raise ValidationException(f"tried `{cls.__name__}` but")
6606+
raise ValidationException(f"tried `{cls.__name__}` but")
66136607
except ValidationException as e:
6614-
raise e
6608+
raise e
66156609
expressionLib = None
66166610
if "expressionLib" in _doc:
66176611
try:
@@ -6789,9 +6783,9 @@ def fromDoc(
67896783

67906784
vocab = _vocab | loadingOptions.vocab
67916785
if class_ not in (cls.__name__, vocab.get(cls.__name__)):
6792-
raise ValidationException(f"tried `{cls.__name__}` but")
6786+
raise ValidationException(f"tried `{cls.__name__}` but")
67936787
except ValidationException as e:
6794-
raise e
6788+
raise e
67956789
try:
67966790
if _doc.get("types") is None:
67976791
raise ValidationException("missing required field `types`", None, [])
@@ -12077,9 +12071,9 @@ def fromDoc(
1207712071

1207812072
vocab = _vocab | loadingOptions.vocab
1207912073
if class_ not in (cls.__name__, vocab.get(cls.__name__)):
12080-
raise ValidationException(f"tried `{cls.__name__}` but")
12074+
raise ValidationException(f"tried `{cls.__name__}` but")
1208112075
except ValidationException as e:
12082-
raise e
12076+
raise e
1208312077
try:
1208412078
if _doc.get("inputs") is None:
1208512079
raise ValidationException("missing required field `inputs`", None, [])
@@ -13066,9 +13060,9 @@ def fromDoc(
1306613060

1306713061
vocab = _vocab | loadingOptions.vocab
1306813062
if class_ not in (cls.__name__, vocab.get(cls.__name__)):
13069-
raise ValidationException(f"tried `{cls.__name__}` but")
13063+
raise ValidationException(f"tried `{cls.__name__}` but")
1307013064
except ValidationException as e:
13071-
raise e
13065+
raise e
1307213066
dockerPull = None
1307313067
if "dockerPull" in _doc:
1307413068
try:
@@ -13531,9 +13525,9 @@ def fromDoc(
1353113525

1353213526
vocab = _vocab | loadingOptions.vocab
1353313527
if class_ not in (cls.__name__, vocab.get(cls.__name__)):
13534-
raise ValidationException(f"tried `{cls.__name__}` but")
13528+
raise ValidationException(f"tried `{cls.__name__}` but")
1353513529
except ValidationException as e:
13536-
raise e
13530+
raise e
1353713531
try:
1353813532
if _doc.get("packages") is None:
1353913533
raise ValidationException("missing required field `packages`", None, [])
@@ -14230,9 +14224,9 @@ def fromDoc(
1423014224

1423114225
vocab = _vocab | loadingOptions.vocab
1423214226
if class_ not in (cls.__name__, vocab.get(cls.__name__)):
14233-
raise ValidationException(f"tried `{cls.__name__}` but")
14227+
raise ValidationException(f"tried `{cls.__name__}` but")
1423414228
except ValidationException as e:
14235-
raise e
14229+
raise e
1423614230
try:
1423714231
if _doc.get("listing") is None:
1423814232
raise ValidationException("missing required field `listing`", None, [])
@@ -14408,9 +14402,9 @@ def fromDoc(
1440814402

1440914403
vocab = _vocab | loadingOptions.vocab
1441014404
if class_ not in (cls.__name__, vocab.get(cls.__name__)):
14411-
raise ValidationException(f"tried `{cls.__name__}` but")
14405+
raise ValidationException(f"tried `{cls.__name__}` but")
1441214406
except ValidationException as e:
14413-
raise e
14407+
raise e
1441414408
try:
1441514409
if _doc.get("envDef") is None:
1441614410
raise ValidationException("missing required field `envDef`", None, [])
@@ -14584,9 +14578,9 @@ def fromDoc(
1458414578

1458514579
vocab = _vocab | loadingOptions.vocab
1458614580
if class_ not in (cls.__name__, vocab.get(cls.__name__)):
14587-
raise ValidationException(f"tried `{cls.__name__}` but")
14581+
raise ValidationException(f"tried `{cls.__name__}` but")
1458814582
except ValidationException as e:
14589-
raise e
14583+
raise e
1459014584
extension_fields: MutableMapping[str, Any] = {}
1459114585
for k in _doc.keys():
1459214586
if k not in cls.attrs:
@@ -14755,9 +14749,9 @@ def fromDoc(
1475514749

1475614750
vocab = _vocab | loadingOptions.vocab
1475714751
if class_ not in (cls.__name__, vocab.get(cls.__name__)):
14758-
raise ValidationException(f"tried `{cls.__name__}` but")
14752+
raise ValidationException(f"tried `{cls.__name__}` but")
1475914753
except ValidationException as e:
14760-
raise e
14754+
raise e
1476114755
coresMin = None
1476214756
if "coresMin" in _doc:
1476314757
try:
@@ -15990,9 +15984,9 @@ def fromDoc(
1599015984

1599115985
vocab = _vocab | loadingOptions.vocab
1599215986
if class_ not in (cls.__name__, vocab.get(cls.__name__)):
15993-
raise ValidationException(f"tried `{cls.__name__}` but")
15987+
raise ValidationException(f"tried `{cls.__name__}` but")
1599415988
except ValidationException as e:
15995-
raise e
15989+
raise e
1599615990
try:
1599715991
if _doc.get("inputs") is None:
1599815992
raise ValidationException("missing required field `inputs`", None, [])
@@ -17188,7 +17182,6 @@ def save(
1718817182
)
1718917183

1719017184

17191-
@trait
1719217185
class Sink(Saveable):
1719317186
pass
1719417187

@@ -18651,9 +18644,9 @@ def fromDoc(
1865118644

1865218645
vocab = _vocab | loadingOptions.vocab
1865318646
if class_ not in (cls.__name__, vocab.get(cls.__name__)):
18654-
raise ValidationException(f"tried `{cls.__name__}` but")
18647+
raise ValidationException(f"tried `{cls.__name__}` but")
1865518648
except ValidationException as e:
18656-
raise e
18649+
raise e
1865718650
try:
1865818651
if _doc.get("inputs") is None:
1865918652
raise ValidationException("missing required field `inputs`", None, [])
@@ -19213,9 +19206,9 @@ def fromDoc(
1921319206

1921419207
vocab = _vocab | loadingOptions.vocab
1921519208
if class_ not in (cls.__name__, vocab.get(cls.__name__)):
19216-
raise ValidationException(f"tried `{cls.__name__}` but")
19209+
raise ValidationException(f"tried `{cls.__name__}` but")
1921719210
except ValidationException as e:
19218-
raise e
19211+
raise e
1921919212
extension_fields: MutableMapping[str, Any] = {}
1922019213
for k in _doc.keys():
1922119214
if k not in cls.attrs:
@@ -19334,9 +19327,9 @@ def fromDoc(
1933419327

1933519328
vocab = _vocab | loadingOptions.vocab
1933619329
if class_ not in (cls.__name__, vocab.get(cls.__name__)):
19337-
raise ValidationException(f"tried `{cls.__name__}` but")
19330+
raise ValidationException(f"tried `{cls.__name__}` but")
1933819331
except ValidationException as e:
19339-
raise e
19332+
raise e
1934019333
extension_fields: MutableMapping[str, Any] = {}
1934119334
for k in _doc.keys():
1934219335
if k not in cls.attrs:
@@ -19455,9 +19448,9 @@ def fromDoc(
1945519448

1945619449
vocab = _vocab | loadingOptions.vocab
1945719450
if class_ not in (cls.__name__, vocab.get(cls.__name__)):
19458-
raise ValidationException(f"tried `{cls.__name__}` but")
19451+
raise ValidationException(f"tried `{cls.__name__}` but")
1945919452
except ValidationException as e:
19460-
raise e
19453+
raise e
1946119454
extension_fields: MutableMapping[str, Any] = {}
1946219455
for k in _doc.keys():
1946319456
if k not in cls.attrs:
@@ -19576,9 +19569,9 @@ def fromDoc(
1957619569

1957719570
vocab = _vocab | loadingOptions.vocab
1957819571
if class_ not in (cls.__name__, vocab.get(cls.__name__)):
19579-
raise ValidationException(f"tried `{cls.__name__}` but")
19572+
raise ValidationException(f"tried `{cls.__name__}` but")
1958019573
except ValidationException as e:
19581-
raise e
19574+
raise e
1958219575
extension_fields: MutableMapping[str, Any] = {}
1958319576
for k in _doc.keys():
1958419577
if k not in cls.attrs:

0 commit comments

Comments
 (0)