From 762b92c31d29bd371a2cb20a21fedd7f29cccda8 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Thu, 22 Apr 2021 17:25:01 +0200 Subject: fix relative path resolution For .input.dscpath, a relative path is supposed to be relative to the json file, but it was relative to cwd. For .output.directory, the matter was unspecified, but should actually work in the same way. Adapt implementation to documentation and fix the missing specification. --- mdbp/build_schema.json | 2 +- mdbp/common.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/mdbp/build_schema.json b/mdbp/build_schema.json index b8d905d..baa38ef 100644 --- a/mdbp/build_schema.json +++ b/mdbp/build_schema.json @@ -121,7 +121,7 @@ "properties": { "directory": { "type": "string", - "description": "target directory to place output artifacts" + "description": "target directory to place output artifacts, can be specified relative to the location of this json file" } } } diff --git a/mdbp/common.py b/mdbp/common.py index d0d2f2d..77cbd33 100644 --- a/mdbp/common.py +++ b/mdbp/common.py @@ -37,6 +37,19 @@ def buildjson(filename: str) -> JsonObject: buildobj, json_load( importlib.resources.open_text("mdbp", "build_schema.json"))) + for attrs in (("input", "dscpath"), ("output", "directory")): + obj = buildobj + for attr in attrs[:-1]: + try: + obj = obj[attr] + except KeyError: + break + else: + try: + obj[attrs[-1]] = str(pathlib.Path(filename).parent / + pathlib.Path(obj[attrs[-1]])) + except KeyError: + pass assert isinstance(buildobj, dict) return buildobj -- cgit v1.2.3