diff --git a/Makefile b/Makefile index 9bac436cb..649f855f2 100644 --- a/Makefile +++ b/Makefile @@ -31,7 +31,7 @@ DEVPKGS=-rdev-requirements.txt -rtest-requirements.txt -rmypy-requirements.txt - COVBASE=coverage run --append PYTEST_EXTRA ?= -VERSION=8.8.$(shell date +%Y%m%d%H%M%S --utc --date=`git log --first-parent \ +VERSION=8.9.$(shell date +%Y%m%d%H%M%S --utc --date=`git log --first-parent \ --max-count=1 --format=format:%cI`) ## all : default task (install schema-salad in dev mode) diff --git a/schema_salad/ref_resolver.py b/schema_salad/ref_resolver.py index ea1fed732..9451aa949 100644 --- a/schema_salad/ref_resolver.py +++ b/schema_salad/ref_resolver.py @@ -14,6 +14,7 @@ import requests from cachecontrol.caches import SeparateBodyFileCache from cachecontrol.wrapper import CacheControl +from mypy_extensions import mypyc_attr from rdflib.exceptions import ParserError from rdflib.graph import Graph from rdflib.namespace import OWL, RDF, RDFS @@ -134,6 +135,11 @@ def SubLoader(loader: "Loader") -> "Loader": ) +def _url_norm(url: str) -> str: + return urllib.parse.urlsplit(url).geturl() + + +@mypyc_attr(allow_interpreted_subclasses=True) class Loader: def __init__( self, @@ -150,9 +156,7 @@ def __init__( doc_cache: Union[str, bool] = True, salad_version: Optional[str] = None, ) -> None: - self.idx: IdxType = ( - NormDict(lambda url: urllib.parse.urlsplit(url).geturl()) if idx is None else idx - ) + self.idx: IdxType = NormDict(_url_norm) if idx is None else idx self.ctx: ContextType = {} self.graph = schemagraph if schemagraph is not None else Graph() diff --git a/schema_salad/tests/test_pickling.py b/schema_salad/tests/test_pickling.py index 96c42bab9..7d0948d5c 100644 --- a/schema_salad/tests/test_pickling.py +++ b/schema_salad/tests/test_pickling.py @@ -7,7 +7,7 @@ import pickle from pathlib import Path -from schema_salad import schema +from schema_salad import ref_resolver, schema from schema_salad.avro.schema import Names, RecordSchema from .util import get_data_uri @@ -21,6 +21,14 @@ def test_recordschema_pickle() -> None: print(pickle.loads(d)) +def test_loader_pickle() -> None: + """Pickle a Loader.""" + loader = ref_resolver.Loader({}) + print(loader) + d = pickle.dumps(loader) + print(pickle.loads(d)) + + def test_extend_and_specialize_enums(tmp_path: Path) -> None: cwl_file_uri = get_data_uri("tests/test_schema/CommonWorkflowLanguage.yml") _, avsc_names, _, _ = schema.load_schema(cwl_file_uri) diff --git a/schema_salad/validate.py b/schema_salad/validate.py index 52fe57c00..8125164ec 100644 --- a/schema_salad/validate.py +++ b/schema_salad/validate.py @@ -76,7 +76,6 @@ def avro_type_name(url: str) -> str: Extract either the last part of the URL fragment past the slash, otherwise the whole fragment. """ - global primitives if url in primitives: return primitives[url]