GithubHelp home page GithubHelp logo

usnistgov / valid8 Goto Github PK

View Code? Open in Web Editor NEW
3.0 4.0 1.0 6.36 MB

Human readable validation

Home Page: https://dse.nist.gov

License: Other

Makefile 1.08% Python 97.88% Shell 1.04%
data-science validation validator yaml yaml-configuration

valid8's Introduction

valid8: Human Readable Validation

valid8 interprets rules in a human-readable format (YAML) and applies those rules to a directory structure.

Installation

This package requires Python3.6+.

Clone the repository and jump in the directory, then:

$ pip install -r requirements.txt
$ pip install .

Usage

valid8 supports two subcommands:

  • apply for most uses
  • lint to check the validity of the rules file

Usage:

$ valid8 apply [--directory directory] rules.yml
$ valid8 lint rules.yml

Example rules file

Example rules.yml with one rule:

- rulename: count_lines_in_specified_files
  filters:
    path_list:
      - "Makefile"
      - "setup.py"
      - valid8
  actions:
    exists: true
    scripts:
      - wc -l ${FILEPATH}

Other examples can be found in the examples/ folder.

Filters and Actions

Each rule is described by two different concepts:

  • Filters select the files to which the rule will be applied.
  • Actions run checks on the files selected by the filters.

Each rule is considered valid if all actions taken on the files selected by the filters returned a 0 exit code (success).

Filters

Name Usage Description Status
path path: "*.json" Find files by a single name or pattern. Stable
path_list path_list:
- "hello.txt"
- "*.py"
Find files from list of names or patterns. Stable
paths_from_file paths_from_file: "file_with_paths.txt" Find files from file with names or patterns, one per line. Beta

N.B. Compatible pattern matching expressions: anything compatible with glob

The find shortcut

The find filter is also available as syntactic sugar for the path, path_list and paths_from_file filters.

Using find with a direct argument calls path

  filters:
    find: find_this_file.txt

Using find with a YAML list calls path_list

  filters:
    find:
      - find_this_file.txt
      - also_these_files.*

Using find with a YAML mapping and the key file calls path_from_file

  filters:
    find:
      file: file_with_paths.txt

These modes are not combinable. Only use one per rule.

Actions

Name Usage Description Status
exists exists: True Selected files exist (e.g. a minimum of 1 found) Stable
count count: n Find exactly n selected files. Stable
match match: {DIR_NAME}/otherfile.txt For each selected file, find another matched file Stable
scripts (inline) scripts: "wc -l {FILEPATH}" Execute a shell command for each selected file Stable
scripts (list) scripts:
- wc -l {FILEPATH}
Execute a list of shell commands for each selected file Stable

Substitutions

N.B. Only available in action.match and action.scripts

In some rules, it's useful to use information about the filtered files to make a determination on an action. The substitutions keys below are available for use in the parameter of the match and scripts action.

For example, the following will check that every file matching predictions/*/predictions.csv has a corresponding JSON file with the original directory name as its filename.

- rulename: predictions_file
  filters:
    path: "predictions/*/predictions.csv"
  actions:
    match: "pipelines/{DIR_NAME}.json"

Examples are based on the file path a/b/c.txt

Substitution keys Description Example value
{DIR_NAME} the directory name b
{DIR_PATH} the directory path a/b
{FILENAME_NOEXT} the filename without the extension c
{FILENAME} the filename with the extension c.txt
{FILEPATH} the file path a/b/c.txt

Adding a custom filter or action

  1. Add the code in filters/ or actions/ respectively.
  2. Each filter or action must be a function and must include the context parameter in the signature.
  3. In the filters/ or actions/ __init__.py, add an import to add the new function under the filters or actions module. Name must be unique

About

License

The license is documented in the LICENSE file and on the NIST website.

Versions and releases:

See

Contact:

Please send any issues, questions, or comments to [email protected]

valid8's People

Contributors

marionlb avatar petercfontana avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.