Merge pull request #11599 from freqtrade/feat/config_schema_precommit
Add custom pre-commit hook for schema extraction
This commit is contained in:
@@ -1,6 +1,18 @@
|
|||||||
# See https://pre-commit.com for more information
|
# See https://pre-commit.com for more information
|
||||||
# See https://pre-commit.com/hooks.html for more hooks
|
# See https://pre-commit.com/hooks.html for more hooks
|
||||||
repos:
|
repos:
|
||||||
|
|
||||||
|
- repo: local
|
||||||
|
# Keep json schema in sync with the config schema
|
||||||
|
# This will write the files - and fail pre-commit if a file has been changed.
|
||||||
|
hooks:
|
||||||
|
- id: Extract config json schema
|
||||||
|
name: extract-config-json-schema
|
||||||
|
entry: "python build_helpers/extract_config_json_schema.py"
|
||||||
|
language: python
|
||||||
|
pass_filenames: false
|
||||||
|
additional_dependencies: ["python-rapidjson", "jsonschema"]
|
||||||
|
|
||||||
- repo: https://github.com/pycqa/flake8
|
- repo: https://github.com/pycqa/flake8
|
||||||
rev: "7.2.0"
|
rev: "7.2.0"
|
||||||
hooks:
|
hooks:
|
||||||
|
|||||||
@@ -4,10 +4,23 @@ from pathlib import Path
|
|||||||
|
|
||||||
import rapidjson
|
import rapidjson
|
||||||
|
|
||||||
from freqtrade.configuration.config_schema import CONF_SCHEMA
|
|
||||||
|
|
||||||
|
|
||||||
def extract_config_json_schema():
|
def extract_config_json_schema():
|
||||||
|
try:
|
||||||
|
# Try to import from the installed package
|
||||||
|
from freqtrade.config_schema import CONF_SCHEMA
|
||||||
|
except ImportError:
|
||||||
|
# If freqtrade is not installed, add the parent directory to sys.path
|
||||||
|
# to import directly from the source
|
||||||
|
import sys
|
||||||
|
|
||||||
|
script_dir = Path(__file__).parent
|
||||||
|
freqtrade_dir = script_dir.parent
|
||||||
|
sys.path.insert(0, str(freqtrade_dir))
|
||||||
|
|
||||||
|
# Now try to import from the source
|
||||||
|
from freqtrade.config_schema import CONF_SCHEMA
|
||||||
|
|
||||||
schema_filename = Path(__file__).parent / "schema.json"
|
schema_filename = Path(__file__).parent / "schema.json"
|
||||||
with schema_filename.open("w") as f:
|
with schema_filename.open("w") as f:
|
||||||
rapidjson.dump(CONF_SCHEMA, f, indent=2)
|
rapidjson.dump(CONF_SCHEMA, f, indent=2)
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
from freqtrade.config_schema.config_schema import CONF_SCHEMA
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = ["CONF_SCHEMA"]
|
||||||
@@ -6,7 +6,7 @@ from typing import Any
|
|||||||
from jsonschema import Draft4Validator, validators
|
from jsonschema import Draft4Validator, validators
|
||||||
from jsonschema.exceptions import ValidationError, best_match
|
from jsonschema.exceptions import ValidationError, best_match
|
||||||
|
|
||||||
from freqtrade.configuration.config_schema import (
|
from freqtrade.config_schema.config_schema import (
|
||||||
CONF_SCHEMA,
|
CONF_SCHEMA,
|
||||||
SCHEMA_BACKTEST_REQUIRED,
|
SCHEMA_BACKTEST_REQUIRED,
|
||||||
SCHEMA_BACKTEST_REQUIRED_FINAL,
|
SCHEMA_BACKTEST_REQUIRED_FINAL,
|
||||||
|
|||||||
Reference in New Issue
Block a user