Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pymake/cmds/createjson.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, "
Expand Down
29 changes: 19 additions & 10 deletions pymake/utils/usgsprograms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -441,15 +450,15 @@ 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)
except:
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:
Expand Down