Skip to content

Commit

Permalink
Merge fe3156f into 5e863f9
Browse files Browse the repository at this point in the history
  • Loading branch information
stolarczyk committed Jan 30, 2020
2 parents 5e863f9 + fe3156f commit 69728d8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
2 changes: 2 additions & 0 deletions MANIFEST.in
@@ -0,0 +1,2 @@
include requirements/*
include README.md
5 changes: 5 additions & 0 deletions docs/changelog.md
Expand Up @@ -2,6 +2,11 @@

This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) and [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) format.

## [0.0.3] - 2020-01-30
### Added
- Option to exclude the validation case from error messages in both Python API and CLI app with `exclude_case` and `-e`/`--exclude-case`, respectively.
- include requirements in the source distribution

## [0.0.2] - 2020-01-12

### Added
Expand Down
2 changes: 1 addition & 1 deletion eido/_version.py
@@ -1 +1 @@
__version__ = "0.0.2"
__version__ = "0.0.3"
20 changes: 15 additions & 5 deletions eido/eido.py
Expand Up @@ -35,6 +35,11 @@ def build_argparser():
"-s", "--schema", required=True,
help="PEP schema file in yaml format.")

parser.add_argument(
"-e", "--exclude-case", default=False, action="store_true",
help="Whether to exclude the validation case from an error. "
"Only the human readable message explaining the error will be raised. "
"Useful when validating large PEPs.")
return parser


Expand Down Expand Up @@ -68,13 +73,14 @@ def _load_yaml(filepath):
return data


def validate_project(project, schema):
def validate_project(project, schema, exclude_case=False):
"""
Validate a project object against a schema
:param peppy.Project project: a project object to validate
:param str | dict schema: schema dict to validate against or a path to one
:return:
:param bool exclude_case: whether to exclude validated objects from the error.
Useful when used ith large projects
"""
if isinstance(schema, str) and os.path.isfile(schema):
schema_dict = _load_yaml(schema)
Expand All @@ -83,7 +89,12 @@ def validate_project(project, schema):
else:
raise TypeError("schema has to be either a dict or a path to an existing file")
project_dict = project.to_dict()
jsonschema.validate(project_dict, _preprocess_schema(schema_dict))
try:
jsonschema.validate(project_dict, _preprocess_schema(schema_dict))
except jsonschema.exceptions.ValidationError as e:
if not exclude_case:
raise e
raise jsonschema.exceptions.ValidationError(e.message)


def main():
Expand All @@ -98,5 +109,4 @@ def main():
_LOGGER.debug("Creating a Project object from: {}".format(args.pep))
p = Project(args.pep)
_LOGGER.debug("Comparing the Project ('{}') against a schema: {}.".format(args.pep, args.schema))
validate_project(p, args.schema)
_LOGGER.info("Validation successful")
validate_project(p, args.schema, args.exclude_case)

0 comments on commit 69728d8

Please sign in to comment.