Skip to content

Commit

Permalink
implement divvy config validation, add schema; #54
Browse files Browse the repository at this point in the history
  • Loading branch information
stolarczyk committed Feb 26, 2021
1 parent 5973700 commit d40bfeb
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -2,6 +2,7 @@

[![PEP compatible](http://pepkit.github.io/img/PEP-compatible-green.svg)](http://pepkit.github.io)
[![Build Status](https://travis-ci.org/pepkit/divvy.svg?branch=master)](https://travis-ci.org/pepkit/divvy)
[![Coverage Status](https://coveralls.io/repos/github/pepkit/divvy/badge.svg?branch=master)](https://coveralls.io/github/pepkit/divvy?branch=master)
[![codecov](https://codecov.io/gh/pepkit/divvy/branch/master/graph/badge.svg?token=AO0I7HA2YL)](https://codecov.io/gh/pepkit/divvy)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

`divvy` is a python package for reading portable computing environment configuration files, which we call *divvy configuration files*. Complete documentation and API for the `divvy` python package is at [divvy.databio.org](http://divvy.databio.org).
10 changes: 8 additions & 2 deletions divvy/compute.py
Expand Up @@ -17,6 +17,7 @@
DEFAULT_COMPUTE_RESOURCES_NAME,
NEW_COMPUTE_KEY,
DEFAULT_CONFIG_FILEPATH,
DEFAULT_CONFIG_SCHEMA,
)
from .utils import write_submit_script
from . import __version__
Expand Down Expand Up @@ -45,7 +46,12 @@ def __init__(self, entries=None, filepath=None):
# Handle the case of an empty one, when we'll use the default
filepath = select_divvy_config(None)

super(ComputingConfiguration, self).__init__(entries, filepath)
super(ComputingConfiguration, self).__init__(
entries=entries,
filepath=filepath,
schema_source=DEFAULT_CONFIG_SCHEMA,
write_validate=True,
)

if not hasattr(self, "compute_packages"):
raise Exception(
Expand All @@ -63,7 +69,7 @@ def __init__(self, entries=None, filepath=None):
self.config_file = self.file_path

def write(self, filename=None):
super(ComputingConfiguration, self).write(filename)
super(ComputingConfiguration, self).write(filepath=filename, exclude_case=True)
filename = filename or getattr(self, yacman.FILEPATH_KEY)
filedir = os.path.dirname(filename)
# For this object, we *also* have to write the template files
Expand Down
4 changes: 4 additions & 0 deletions divvy/const.py
Expand Up @@ -9,11 +9,15 @@
DEFAULT_CONFIG_FILEPATH = os.path.join(
os.path.dirname(__file__), "default_config", "divvy_config.yaml"
)
DEFAULT_CONFIG_SCHEMA = os.path.join(
os.path.dirname(__file__), "schemas", "divvy_config_schema.yaml"
)
COMPUTE_CONSTANTS = [
"COMPUTE_SETTINGS_VARNAME",
"DEFAULT_COMPUTE_RESOURCES_NAME",
"NEW_COMPUTE_KEY",
"DEFAULT_CONFIG_FILEPATH",
"DEFAULT_CONFIG_SCHEMA",
]

__all__ = COMPUTE_CONSTANTS + ["DEFAULT_COMPUTE_RESOURCES_NAME"]
21 changes: 21 additions & 0 deletions divvy/schemas/divvy_config_schema.yaml
@@ -0,0 +1,21 @@
description: "divvy configuration file schema"
version: "0.1"
required:
- compute_packages
properties:
compute_packages:
type: object
additionalProperties: false
patternProperties:
^.*$:
type: object
additionalProperties: false
patternProperties:
^.*$:
type: string
adapters:
type: object
additionalProperties: false
patternProperties:
^.*$:
type: string

0 comments on commit d40bfeb

Please sign in to comment.