Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JSON Schema for Config #134

Merged
merged 1 commit into from
Sep 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering whether this breaks existing repos that have both a pyproject.toml and package.json file? Previously both files would be checked for the configuration, while this doesn't seem to be the case anymore.

This is for example the case in retrolab or the JupyterLab extension cookiecutter:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably we should keep the previous behavior of cascading through the files to be able to pick up the config.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noticed as the check release workflow started to fail here: https://github.com/jupyterlab/retrolab/runs/3535195754

Which seems to be related to the hooks not being run.

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