Skip to content

Commit

Permalink
Stop fetching schema releases from GitHub
Browse files Browse the repository at this point in the history
  • Loading branch information
danlamanna committed Feb 17, 2023
1 parent e99dfd0 commit efbe69e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
# Fetch all commits so that versioningit will return something
# compatible with semantic-version
fetch-depth: 0
submodules: true

- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v4
Expand Down
26 changes: 17 additions & 9 deletions dandischema/metadata.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
from copy import deepcopy
import json
from pathlib import Path
import sys
from typing import Any, Dict, Iterable, TypeVar, cast

if sys.version_info >= (3, 10, 0):
# Available in python >= 3.10
from importlib.resources import files
else:
from importlib_resources import files

import jsonschema
import pydantic
import requests

from .consts import (
ALLOWED_INPUT_SCHEMAS,
Expand Down Expand Up @@ -129,6 +135,14 @@ def _validate_asset_json(data: dict, schema_dir: str) -> None:
_validate_obj_json(data, schema)


def _get_schema(schema_version: str, schema_name: str) -> dict:
return json.loads(
files("dandischema.schema")
.joinpath(f"releases/{schema_version}/{schema_name}")
.read_text()
)


def validate(
obj, schema_version=None, schema_key=None, missing_ok=False, json_validation=False
):
Expand Down Expand Up @@ -181,10 +195,7 @@ def validate(
"using json schema for older versions"
)
schema_filename = schema_map[schema_key]
schema = requests.get(
f"https://raw.githubusercontent.com/dandi/schema/"
f"master/releases/{schema_version}/{schema_filename}"
).json()
schema = _get_schema(schema_version, schema_filename)
_validate_obj_json(obj, schema, missing_ok)
klass = getattr(models, schema_key)
try:
Expand Down Expand Up @@ -217,10 +228,7 @@ def migrate(
if version2tuple(schema_version) > version2tuple(to_version):
raise ValueError(f"Cannot migrate from {schema_version} to lower {to_version}.")
if not (skip_validation):
schema = requests.get(
f"https://raw.githubusercontent.com/dandi/schema/"
f"master/releases/{schema_version}/dandiset.json"
).json()
schema = _get_schema(schema_version, "dandiset.json")
_validate_obj_json(obj, schema)
if version2tuple(schema_version) < version2tuple("0.6.0"):
for val in obj.get("about", []):
Expand Down
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ project_urls =
[options]
python_requires = >=3.7
install_requires =
# importlib-resources can be removed once 3.10 becomes the minimum required version.
# https://setuptools.pypa.io/en/latest/userguide/datafiles.html#accessing-data-files-at-runtime
importlib-resources; python_version < "3.10"
jsonschema[format]
pydantic[email] >= 1.8.1
typing_extensions; python_version < "3.8"
Expand Down

0 comments on commit efbe69e

Please sign in to comment.