Skip to content

Commit 26b2c42

Browse files
author
Steven Silvester
authored
Merge pull request #134 from fcollonval/ft/json-config
Add JSON Schema for Config
2 parents 21477d9 + 30a6b78 commit 26b2c42

File tree

4 files changed

+64
-8
lines changed

4 files changed

+64
-8
lines changed

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
include *.md
22
include LICENSE
33
prune media
4+
include jupyter_releaser/schema.json

jupyter_releaser/schema.json

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"title": "Jupyter Releaser Metadata",
3+
"version": "0.1.0",
4+
"description": "Jupyter Releaser configuration metadata",
5+
"properties": {
6+
"skip": {
7+
"title": "Skip Steps",
8+
"description": "A list of steps to skip in actions",
9+
"type": "array",
10+
"items": {
11+
"type": "string"
12+
}
13+
},
14+
"options": {
15+
"title": "Overrides for default options",
16+
"description": "Overrides for cli option names",
17+
"additionalProperties": {
18+
"anyOf": [
19+
{ "type": "string" },
20+
{
21+
"type": "array",
22+
"items": {
23+
"type": "string"
24+
}
25+
}
26+
]
27+
}
28+
},
29+
"hooks": {
30+
"title": "Action Step Hooks",
31+
"description": "Hooks to run before or after action steps",
32+
"patternProperties": {
33+
"^(before|after)-.*$": {
34+
"anyOf": [
35+
{ "type": "string" },
36+
{
37+
"type": "array",
38+
"items": {
39+
"type": "string"
40+
}
41+
}
42+
]
43+
}
44+
}
45+
}
46+
},
47+
"additionalProperties": false,
48+
"type": "object"
49+
}

jupyter_releaser/util.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
from subprocess import PIPE
1919

2020
import toml
21+
from jsonschema import Draft4Validator as Validator
2122
from pkg_resources import parse_version
2223

2324
from jupyter_releaser.tee import run as tee
2425

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

270272
def read_config():
271273
"""Read the jupyter-releaser config data"""
274+
config = {}
272275
if JUPYTER_RELEASER_CONFIG.exists():
273-
return toml.loads(JUPYTER_RELEASER_CONFIG.read_text(encoding="utf-8"))
276+
config = toml.loads(JUPYTER_RELEASER_CONFIG.read_text(encoding="utf-8"))
274277

275-
if PYPROJECT.exists():
278+
elif PYPROJECT.exists():
276279
data = toml.loads(PYPROJECT.read_text(encoding="utf-8"))
277-
config = data.get("tool", {}).get("jupyter-releaser")
278-
if config:
279-
return config
280+
config = data.get("tool", {}).get("jupyter-releaser") or {}
280281

281-
if PACKAGE_JSON.exists():
282+
elif PACKAGE_JSON.exists():
282283
data = json.loads(PACKAGE_JSON.read_text(encoding="utf-8"))
283284
if "jupyter-releaser" in data:
284-
return data["jupyter-releaser"]
285+
config = data["jupyter-releaser"]
285286

286-
return {}
287+
with open(osp.join(HERE, "schema.json")) as fid:
288+
schema = json.load(fid)
289+
validator = Validator(schema)
290+
validator.validate(config)
291+
return config

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ install_requires =
3232
click
3333
ghapi
3434
github-activity~=0.1
35+
jsonschema>=3.0.1
3536
pre-commit
3637
pypiserver
3738
pytest-check-links>=0.5

0 commit comments

Comments
 (0)