Skip to content

Commit

Permalink
Merge pull request #134 from fcollonval/ft/json-config
Browse files Browse the repository at this point in the history
Add JSON Schema for Config
  • Loading branch information
Steven Silvester authored Sep 7, 2021
2 parents 21477d9 + 30a6b78 commit 26b2c42
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 8 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
include *.md
include LICENSE
prune media
include jupyter_releaser/schema.json
49 changes: 49 additions & 0 deletions jupyter_releaser/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"title": "Jupyter Releaser Metadata",
"version": "0.1.0",
"description": "Jupyter Releaser configuration metadata",
"properties": {
"skip": {
"title": "Skip Steps",
"description": "A list of steps to skip in actions",
"type": "array",
"items": {
"type": "string"
}
},
"options": {
"title": "Overrides for default options",
"description": "Overrides for cli option names",
"additionalProperties": {
"anyOf": [
{ "type": "string" },
{
"type": "array",
"items": {
"type": "string"
}
}
]
}
},
"hooks": {
"title": "Action Step Hooks",
"description": "Hooks to run before or after action steps",
"patternProperties": {
"^(before|after)-.*$": {
"anyOf": [
{ "type": "string" },
{
"type": "array",
"items": {
"type": "string"
}
}
]
}
}
}
},
"additionalProperties": false,
"type": "object"
}
21 changes: 13 additions & 8 deletions jupyter_releaser/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
from subprocess import PIPE

import toml
from jsonschema import Draft4Validator as Validator
from pkg_resources import parse_version

from jupyter_releaser.tee import run as tee

HERE = osp.dirname(osp.abspath(__file__))
PYPROJECT = Path("pyproject.toml")
SETUP_PY = Path("setup.py")
SETUP_CFG = Path("setup.cfg")
Expand Down Expand Up @@ -269,18 +271,21 @@ def retry(cmd, **kwargs):

def read_config():
"""Read the jupyter-releaser config data"""
config = {}
if JUPYTER_RELEASER_CONFIG.exists():
return toml.loads(JUPYTER_RELEASER_CONFIG.read_text(encoding="utf-8"))
config = toml.loads(JUPYTER_RELEASER_CONFIG.read_text(encoding="utf-8"))

if PYPROJECT.exists():
elif PYPROJECT.exists():
data = toml.loads(PYPROJECT.read_text(encoding="utf-8"))
config = data.get("tool", {}).get("jupyter-releaser")
if config:
return config
config = data.get("tool", {}).get("jupyter-releaser") or {}

if PACKAGE_JSON.exists():
elif PACKAGE_JSON.exists():
data = json.loads(PACKAGE_JSON.read_text(encoding="utf-8"))
if "jupyter-releaser" in data:
return data["jupyter-releaser"]
config = data["jupyter-releaser"]

return {}
with open(osp.join(HERE, "schema.json")) as fid:
schema = json.load(fid)
validator = Validator(schema)
validator.validate(config)
return config
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ install_requires =
click
ghapi
github-activity~=0.1
jsonschema>=3.0.1
pre-commit
pypiserver
pytest-check-links>=0.5
Expand Down

0 comments on commit 26b2c42

Please sign in to comment.