From b839e159a899047f2a00011232a580fd66ef6081 Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 4 Apr 2025 07:19:47 +0200 Subject: [PATCH] chore: Support config schema extract without installation --- build_helpers/extract_config_json_schema.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/build_helpers/extract_config_json_schema.py b/build_helpers/extract_config_json_schema.py index 44ecc0f91..31c8e76df 100644 --- a/build_helpers/extract_config_json_schema.py +++ b/build_helpers/extract_config_json_schema.py @@ -1,13 +1,25 @@ """Script to extract the configuration json schema from config_schema.py file.""" +import sys from pathlib import Path import rapidjson -from freqtrade.configuration.config_schema import CONF_SCHEMA - def extract_config_json_schema(): + try: + # Try to import from the installed package + from freqtrade.configuration.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 + 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.configuration.config_schema import CONF_SCHEMA + schema_filename = Path(__file__).parent / "schema.json" with schema_filename.open("w") as f: rapidjson.dump(CONF_SCHEMA, f, indent=2)