Skip to content

Commit 26d4acd

Browse files
committed
Loader: enable pickling
1 parent c3edef7 commit 26d4acd

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ DEVPKGS=-rdev-requirements.txt -rtest-requirements.txt -rmypy-requirements.txt -
3131
COVBASE=coverage run --append
3232
PYTEST_EXTRA ?=
3333

34-
VERSION=8.8.$(shell date +%Y%m%d%H%M%S --utc --date=`git log --first-parent \
34+
VERSION=8.9.$(shell date +%Y%m%d%H%M%S --utc --date=`git log --first-parent \
3535
--max-count=1 --format=format:%cI`)
3636

3737
## all : default task (install schema-salad in dev mode)

schema_salad/ref_resolver.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import requests
1515
from cachecontrol.caches import SeparateBodyFileCache
1616
from cachecontrol.wrapper import CacheControl
17+
from mypy_extensions import mypyc_attr
1718
from rdflib.exceptions import ParserError
1819
from rdflib.graph import Graph
1920
from rdflib.namespace import OWL, RDF, RDFS
@@ -134,6 +135,11 @@ def SubLoader(loader: "Loader") -> "Loader":
134135
)
135136

136137

138+
def _url_norm(url: str) -> str:
139+
return urllib.parse.urlsplit(url).geturl()
140+
141+
142+
@mypyc_attr(allow_interpreted_subclasses=True)
137143
class Loader:
138144
def __init__(
139145
self,
@@ -150,9 +156,7 @@ def __init__(
150156
doc_cache: Union[str, bool] = True,
151157
salad_version: Optional[str] = None,
152158
) -> None:
153-
self.idx: IdxType = (
154-
NormDict(lambda url: urllib.parse.urlsplit(url).geturl()) if idx is None else idx
155-
)
159+
self.idx: IdxType = NormDict(_url_norm) if idx is None else idx
156160

157161
self.ctx: ContextType = {}
158162
self.graph = schemagraph if schemagraph is not None else Graph()

schema_salad/tests/test_pickling.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import pickle
88
from pathlib import Path
99

10-
from schema_salad import schema
10+
from schema_salad import ref_resolver, schema
1111
from schema_salad.avro.schema import Names, RecordSchema
1212

1313
from .util import get_data_uri
@@ -21,6 +21,14 @@ def test_recordschema_pickle() -> None:
2121
print(pickle.loads(d))
2222

2323

24+
def test_loader_pickle() -> None:
25+
"""Pickle a Loader."""
26+
loader = ref_resolver.Loader({})
27+
print(loader)
28+
d = pickle.dumps(loader)
29+
print(pickle.loads(d))
30+
31+
2432
def test_extend_and_specialize_enums(tmp_path: Path) -> None:
2533
cwl_file_uri = get_data_uri("tests/test_schema/CommonWorkflowLanguage.yml")
2634
_, avsc_names, _, _ = schema.load_schema(cwl_file_uri)

0 commit comments

Comments
 (0)