Unverified Commit 1a779ad7 authored by Jared T Nielsen's avatar Jared T Nielsen Committed by GitHub
Browse files

Specify config filename (#6626)

parent a622705e
...@@ -88,7 +88,7 @@ class HfArgumentParser(ArgumentParser): ...@@ -88,7 +88,7 @@ class HfArgumentParser(ArgumentParser):
self.add_argument(field_name, **kwargs) self.add_argument(field_name, **kwargs)
def parse_args_into_dataclasses( def parse_args_into_dataclasses(
self, args=None, return_remaining_strings=False, look_for_args_file=True self, args=None, return_remaining_strings=False, look_for_args_file=True, args_filename=None
) -> Tuple[DataClass, ...]: ) -> Tuple[DataClass, ...]:
""" """
Parse command-line args into instances of the specified dataclass types. Parse command-line args into instances of the specified dataclass types.
...@@ -107,6 +107,9 @@ class HfArgumentParser(ArgumentParser): ...@@ -107,6 +107,9 @@ class HfArgumentParser(ArgumentParser):
If true, will look for a ".args" file with the same base name If true, will look for a ".args" file with the same base name
as the entry point script for this process, and will append its as the entry point script for this process, and will append its
potential content to the command line args. potential content to the command line args.
args_filename:
If not None, will uses this file instead of the ".args" file
specified in the previous argument.
Returns: Returns:
Tuple consisting of: Tuple consisting of:
...@@ -118,8 +121,12 @@ class HfArgumentParser(ArgumentParser): ...@@ -118,8 +121,12 @@ class HfArgumentParser(ArgumentParser):
- The potential list of remaining argument strings. - The potential list of remaining argument strings.
(same as argparse.ArgumentParser.parse_known_args) (same as argparse.ArgumentParser.parse_known_args)
""" """
if look_for_args_file and len(sys.argv): if args_filename or (look_for_args_file and len(sys.argv)):
args_file = Path(sys.argv[0]).with_suffix(".args") if args_filename:
args_file = Path(args_filename)
else:
args_file = Path(sys.argv[0]).with_suffix(".args")
if args_file.exists(): if args_file.exists():
fargs = args_file.read_text().split() fargs = args_file.read_text().split()
args = fargs + args if args is not None else fargs + sys.argv[1:] args = fargs + args if args is not None else fargs + sys.argv[1:]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment