Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Alexandre Bulté
Validata Core
Commits
ea7419e4
Commit
ea7419e4
authored
Feb 19, 2019
by
Alexandre Bulté
Browse files
Merge branch 'alternative-schemas-toml' into dev
parents
480256c9
de523c2a
Pipeline
#561
passed with stage
in 38 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
validata_core/__init__.py
View file @
ea7419e4
...
...
@@ -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
else
:
schema_config
=
self
.
schemas_config
.
get
(
source
)
if
schema_config
is
not
None
:
source
=
schema_config
[
"schema"
]
...
...
validata_core/cli.py
View file @
ea7419e4
...
...
@@ -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
args
.
config
.
open
()
as
fp
:
schemas_config
=
toml
.
load
(
fp
)
schemas_config
=
get_schemas_config
()
report
=
Validator
(
schemas_config
).
validate
(
source
=
args
.
source
,
schema
=
args
.
schema
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment