Skip to content

Simplify creation of a required custom check #213

@joelostblom

Description

@joelostblom

Currently, creating a custom check that is required involves the invocation of two different classes and the repetition of the message and path string for both:

import check_datapackage as cdp

license_check = cdp.CustomCheck(
    type="only-mit",
    jsonpath="$.licenses[*].name",
    message="Data Packages may only be licensed under MIT.",
    check=lambda license_name: license_name == "mit",
)
license_required = cdp.RequiredCheck(
    jsonpath="$.licenses[*].name",
    message="Data Packages may only be licensed under MIT.",
)

package_properties = cdp.example_package_properties()
config = cdp.Config(
    extensions=cdp.Extensions(
        custom_checks=[license_check], required_checks=[license_required]
    )
)
cdp.check(properties=package_properties, config=config, error=True)

We could of course assign the message and path strings to variables beforehand, but it is still a bit clunky. I saw that the 'required' type is explicitly disabled for the custom class, so I take it as there was some issue, but maybe this is still something to do here to make the workflow easier.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions