Skip to content

Commit

Permalink
ensure required args from parsers are correctly filled from parsed args
Browse files Browse the repository at this point in the history
  • Loading branch information
ifrit98 committed Sep 12, 2023
1 parent 82fed4f commit 98f6775
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion bittensor/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,22 @@ def __init__(
if _config.get("command") != None and _config.get("subcommand") != None:
default_param_args = [_config.get("command"), _config.get("subcommand")]

## Get all args by name
## Get all args by name and ensure required arguments are filled if present
# Create a list of all required arguments
required_args = []
for action in parser._actions:
if action.required:
required_args.append(action.dest)

# Check each required argument in the args list
default_param_args = []
for arg in required_args:
if arg_name in args:
default_param_args.extend([arg_name, str(args[args.index('--' + arg) + 1])])
else:
raise ValueError(f"The required argument {arg_name} was not provided in the command line arguments.")

# Parse the arguments with the new list
default_params = parser.parse_args(args=default_param_args)

all_default_args = default_params.__dict__.keys() | []
Expand Down

0 comments on commit 98f6775

Please sign in to comment.