diff --git a/pymake/cmds/createjson.py b/pymake/cmds/createjson.py index 4e76376..248486f 100755 --- a/pymake/cmds/createjson.py +++ b/pymake/cmds/createjson.py @@ -55,6 +55,14 @@ def main() -> None: "choices": None, "action": None, }, + "appdir": { + "tag": ("-ad", "--appdir"), + "help": "code.json path that overides FPTH defined path, " + + "Default is None.", + "default": None, + "choices": None, + "action": None, + }, "prog_data": { "tag": ("--prog_data",), "help": "User-specified program database. If prog_data is None, " diff --git a/pymake/utils/usgsprograms.py b/pymake/utils/usgsprograms.py index f8d3e29..3bce981 100644 --- a/pymake/utils/usgsprograms.py +++ b/pymake/utils/usgsprograms.py @@ -298,6 +298,7 @@ def list_targets(current=False): @staticmethod def export_json( fpth="code.json", + appdir=None, prog_data=None, current=False, update=True, @@ -312,6 +313,9 @@ def export_json( ---------- fpth : str Path for the json file to be created. Default is "code.json" + appdir : str + path for code.json. Overides code.json path defined in fpth. + Default is None. prog_data : dict User-specified program database. If prog_data is None, it will be created from the USGS program database @@ -357,15 +361,20 @@ def export_json( print(f" {idx + 1:>2d}: {key}") # process the passed file path into appdir and file_name - appdir = pl.Path(".") - file_name = pl.Path(fpth) - if file_name.parent != str(appdir): - appdir = file_name.parent - file_name = file_name.name + if appdir is None: + appdir = pl.Path(".") + file_name = pl.Path(fpth) + if file_name.parent != str(appdir): + appdir = file_name.parent + file_name = file_name.name + else: + for idx, argv in enumerate(sys.argv): + if argv in ("--appdir", "-ad"): + appdir = pl.Path(sys.argv[idx + 1]) else: - for idx, argv in enumerate(sys.argv): - if argv in ("--appdir", "-ad"): - appdir = pl.Path(sys.argv[idx + 1]) + if isinstance(appdir, str): + appdir = pl.Path(appdir) + file_name = pl.Path(fpth).name if str(appdir) != ".": appdir.mkdir(parents=True, exist_ok=True) @@ -441,7 +450,7 @@ def export_json( if temp_target in prog_data.keys(): prog_data[temp_target]["double_switch"] = True - # export program data to a json file + # write code.json to root directory - used by executables CI try: with open(file_name, "w") as file_obj: json.dump(prog_data, file_obj, indent=4, sort_keys=True) @@ -449,7 +458,7 @@ def export_json( msg = f'could not export json file "{file_name}"' raise IOError(msg) - # write code.json + # write code.json if appdir is not the root directory if str(appdir) != ".": dst = appdir / file_name with open(dst, "w") as file_obj: