diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 00000000..857bdcf3 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,2 @@ +include requirements/* +include README.md \ No newline at end of file diff --git a/docs/changelog.md b/docs/changelog.md index c3310025..63f7df30 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -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 diff --git a/eido/_version.py b/eido/_version.py index 3b93d0be..27fdca49 100644 --- a/eido/_version.py +++ b/eido/_version.py @@ -1 +1 @@ -__version__ = "0.0.2" +__version__ = "0.0.3" diff --git a/eido/eido.py b/eido/eido.py index b1006f6b..49411012 100644 --- a/eido/eido.py +++ b/eido/eido.py @@ -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 @@ -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) @@ -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(): @@ -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)