From ccc9c43161282bd6f37813cc85c13da1eb51b88d Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Sun, 7 Feb 2021 21:02:51 +0000 Subject: Allow flash/compile to accept relative json paths (#11767) * Allow flash/compile to accept relative paths * Review suggestions * Review comments * Put back exists check otherwise stdin fails * fix lint --- lib/python/qmk/path.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib/python/qmk/path.py') diff --git a/lib/python/qmk/path.py b/lib/python/qmk/path.py index 54def1d5d6..2aa1916f55 100644 --- a/lib/python/qmk/path.py +++ b/lib/python/qmk/path.py @@ -2,6 +2,7 @@ """ import logging import os +import argparse from pathlib import Path from qmk.constants import MAX_KEYBOARD_SUBFOLDERS, QMK_FIRMWARE @@ -65,3 +66,12 @@ def normpath(path): return path return Path(os.environ['ORIG_CWD']) / path + + +class FileType(argparse.FileType): + def __call__(self, string): + """normalize and check exists + otherwise magic strings like '-' for stdin resolve to bad paths + """ + norm = normpath(string) + return super().__call__(norm if norm.exists() else string) -- cgit v1.2.3