From 5509990a7193985b72a22c0af000c5c1185ce4ed Mon Sep 17 00:00:00 2001 From: Mazz Mosley Date: Fri, 18 Sep 2015 14:42:05 +0100 Subject: [PATCH] Ensure RefResolver works across operating systems Slashes, paths and a tale of woe. Validation now works on windows \o/ Signed-off-by: Mazz Mosley --- compose/config/validation.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/compose/config/validation.py b/compose/config/validation.py index 0258c5d94..959465e98 100644 --- a/compose/config/validation.py +++ b/compose/config/validation.py @@ -1,6 +1,7 @@ import json import logging import os +import sys from functools import wraps from docker.utils.ports import split_port @@ -290,12 +291,20 @@ def validate_against_service_schema(config, service_name): def _validate_against_schema(config, schema_filename, format_checker=[], service_name=None): config_source_dir = os.path.dirname(os.path.abspath(__file__)) + + if sys.platform == "win32": + file_pre_fix = "///" + config_source_dir = config_source_dir.replace('\\', '/') + else: + file_pre_fix = "//" + + resolver_full_path = "file:{}{}/".format(file_pre_fix, config_source_dir) schema_file = os.path.join(config_source_dir, schema_filename) with open(schema_file, "r") as schema_fh: schema = json.load(schema_fh) - resolver = RefResolver('file://' + config_source_dir + '/', schema) + resolver = RefResolver(resolver_full_path, schema) validation_output = Draft4Validator(schema, resolver=resolver, format_checker=FormatChecker(format_checker)) errors = [error for error in sorted(validation_output.iter_errors(config), key=str)]