Skip to content

Commit 8c3ecc2

Browse files
authored
Merge pull request #615 from opentensor/chore/thewhaleking/add-parent-path-creation-for-debug-log
Debug log additional
2 parents 49b8384 + 52f58fb commit 8c3ecc2

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

bittensor_cli/cli.py

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -608,24 +608,38 @@ def commands_callback(value: bool):
608608

609609
def debug_callback(value: bool):
610610
if value:
611+
debug_file_loc = Path(
612+
os.getenv("BTCLI_DEBUG_FILE")
613+
or os.path.expanduser(defaults.config.debug_file_path)
614+
)
615+
if not debug_file_loc.exists():
616+
err_console.print(
617+
f"[red]Error: The debug file '{arg__(str(debug_file_loc))}' does not exist. This indicates that you have"
618+
f" not run a command which has logged debug output, or you deleted this file. Debug logging only occurs"
619+
f" if {arg__('use_cache')} is set to True in your config ({arg__('btcli config set')}). If the debug "
620+
f"file was created using the {arg__('BTCLI_DEBUG_FILE')} environment variable, please set the value for"
621+
f" the same location, and re-run this {arg__('btcli --debug')} command.[/red]"
622+
)
623+
raise typer.Exit()
611624
save_file_loc_ = Prompt.ask(
612625
"Enter the file location to save the debug log for the previous command.",
613626
default="~/.bittensor/debug-export",
614627
).strip()
615-
save_file_loc = os.path.expanduser(save_file_loc_)
628+
save_file_loc = Path(os.path.expanduser(save_file_loc_))
629+
if not save_file_loc.parent.exists():
630+
if Confirm.ask(
631+
f"The directory '{save_file_loc.parent}' does not exist. Would you like to create it?"
632+
):
633+
save_file_loc.parent.mkdir(parents=True, exist_ok=True)
616634
try:
617635
with (
618636
open(save_file_loc, "w+") as save_file,
619-
open(
620-
os.getenv("BTCLI_DEBUG_FILE")
621-
or os.path.expanduser(defaults.config.debug_file_path),
622-
"r",
623-
) as current_file,
637+
open(debug_file_loc, "r") as current_file,
624638
):
625639
save_file.write(current_file.read())
626640
console.print(f"Saved debug log to {save_file_loc}")
627-
except FileNotFoundError:
628-
print_error(f"The filepath '{save_file_loc}' does not exist.")
641+
except FileNotFoundError as e:
642+
print_error(str(e))
629643
raise typer.Exit()
630644

631645

@@ -1243,7 +1257,7 @@ def main_callback(
12431257
):
12441258
"""
12451259
Command line interface (CLI) for Bittensor. Uses the values in the configuration file. These values can be
1246-
overriden by passing them explicitly in the command line.
1260+
overridden by passing them explicitly in the command line.
12471261
"""
12481262
# Load or create the config file
12491263
if os.path.exists(self.config_path):
@@ -1267,6 +1281,9 @@ def main_callback(
12671281
if sub_key not in config[key]:
12681282
config[key][sub_key] = sub_value
12691283
updated = True
1284+
elif isinstance(value, bool) and config[key] is None:
1285+
config[key] = value
1286+
updated = True
12701287
if updated:
12711288
with open(self.config_path, "w") as f:
12721289
safe_dump(config, f)

0 commit comments

Comments
 (0)