Commit de523c2a authored by Alexandre Bulté's avatar Alexandre Bulté
Browse files


parent 5288a4b9
Pipeline #556 passed with stage
in 35 seconds
......@@ -6,6 +6,7 @@ from datetime import datetime, timezone
from pathlib import Path
import importlib_resources
import os
import requests
import toml
from tableschema import Schema
......@@ -37,6 +38,10 @@ import_custom_checks()
def get_schemas_config():
schemas_config_file = os.environ.get('VALIDATA_SCHEMAS_CONFIG')
if schemas_config_file is not None:
with open(schemas_config_file) as fp:
return toml.load(fp)
with importlib_resources.open_text('validata_core', 'schemas.toml') as fp:
return toml.load(fp)
......@@ -173,8 +178,8 @@ class Validator:
"""Return a `tableschema.Schema` instance from `source`."""
if isinstance(source, Path):
source = str(source)
if isinstance(source, str) and source.startswith("scdl-"):
# `source` seems to be a SCDL tag (i.e. `scdl-prenoms`)
# try to load as a tag from schemas_config
schema_config = self.schemas_config.get(source)
if schema_config is not None:
source = schema_config["schema"]
......@@ -8,17 +8,13 @@ import argparse
import json
import logging
import sys
from pathlib import Path
import toml
from . import Validator
from . import Validator, get_schemas_config
def cli():
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('source', help='URL or path to tabular file (CSV, XLS, etc.) to validate')
parser.add_argument('--config', type=Path, help='use alternate `schemas.toml` config file')
parser.add_argument('--log', default='WARNING', help='level of logging messages')
parser.add_argument('--schema', help='URL or path to table schema JSON file')
args = parser.parse_args()
......@@ -32,10 +28,7 @@ def cli():
stream=sys.stderr, # script outputs data
schemas_config = None
if args.config is not None:
with as fp:
schemas_config = toml.load(fp)
schemas_config = get_schemas_config()
report = Validator(schemas_config).validate(source=args.source, schema=args.schema)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment