Doc styling (#8067)
* Important files * Styling them all * Revert "Styling them all" This reverts commit 7d029395fdae8513b8281cbc2a6c239f8093503e. * Syling them for realsies * Fix syntax error * Fix benchmark_utils * More fixes * Fix modeling auto and script * Remove new line * Fixes * More fixes * Fix more files * Style * Add FSMT * More fixes * More fixes * More fixes * More fixes * Fixes * More fixes * More fixes * Last fixes * Make sphinx happy
This commit is contained in:
@@ -13,12 +13,11 @@ DataClassType = NewType("DataClassType", Any)
|
||||
|
||||
class HfArgumentParser(ArgumentParser):
|
||||
"""
|
||||
This subclass of `argparse.ArgumentParser` uses type hints on dataclasses
|
||||
to generate arguments.
|
||||
This subclass of `argparse.ArgumentParser` uses type hints on dataclasses to generate arguments.
|
||||
|
||||
The class is designed to play well with the native argparse. In particular,
|
||||
you can add more (non-dataclass backed) arguments to the parser after initialization
|
||||
and you'll get the output back after parsing as an additional namespace.
|
||||
The class is designed to play well with the native argparse. In particular, you can add more (non-dataclass backed)
|
||||
arguments to the parser after initialization and you'll get the output back after parsing as an additional
|
||||
namespace.
|
||||
"""
|
||||
|
||||
dataclass_types: Iterable[DataClassType]
|
||||
@@ -27,8 +26,7 @@ class HfArgumentParser(ArgumentParser):
|
||||
"""
|
||||
Args:
|
||||
dataclass_types:
|
||||
Dataclass type, or list of dataclass types for which we will "fill" instances
|
||||
with the parsed args.
|
||||
Dataclass type, or list of dataclass types for which we will "fill" instances with the parsed args.
|
||||
kwargs:
|
||||
(Optional) Passed to `argparse.ArgumentParser()` in the regular way.
|
||||
"""
|
||||
@@ -94,33 +92,27 @@ class HfArgumentParser(ArgumentParser):
|
||||
"""
|
||||
Parse command-line args into instances of the specified dataclass types.
|
||||
|
||||
This relies on argparse's `ArgumentParser.parse_known_args`.
|
||||
See the doc at:
|
||||
This relies on argparse's `ArgumentParser.parse_known_args`. See the doc at:
|
||||
docs.python.org/3.7/library/argparse.html#argparse.ArgumentParser.parse_args
|
||||
|
||||
Args:
|
||||
args:
|
||||
List of strings to parse. The default is taken from sys.argv.
|
||||
(same as argparse.ArgumentParser)
|
||||
List of strings to parse. The default is taken from sys.argv. (same as argparse.ArgumentParser)
|
||||
return_remaining_strings:
|
||||
If true, also return a list of remaining argument strings.
|
||||
look_for_args_file:
|
||||
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
|
||||
potential content to the command line args.
|
||||
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 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.
|
||||
If not None, will uses this file instead of the ".args" file specified in the previous argument.
|
||||
|
||||
Returns:
|
||||
Tuple consisting of:
|
||||
- the dataclass instances in the same order as they
|
||||
were passed to the initializer.abspath
|
||||
- if applicable, an additional namespace for more
|
||||
(non-dataclass backed) arguments added to the parser
|
||||
|
||||
- the dataclass instances in the same order as they were passed to the initializer.abspath
|
||||
- if applicable, an additional namespace for more (non-dataclass backed) arguments added to the parser
|
||||
after initialization.
|
||||
- The potential list of remaining argument strings.
|
||||
(same as argparse.ArgumentParser.parse_known_args)
|
||||
- The potential list of remaining argument strings. (same as argparse.ArgumentParser.parse_known_args)
|
||||
"""
|
||||
if args_filename or (look_for_args_file and len(sys.argv)):
|
||||
if args_filename:
|
||||
@@ -155,8 +147,8 @@ class HfArgumentParser(ArgumentParser):
|
||||
|
||||
def parse_json_file(self, json_file: str) -> Tuple[DataClass, ...]:
|
||||
"""
|
||||
Alternative helper method that does not use `argparse` at all,
|
||||
instead loading a json file and populating the dataclass types.
|
||||
Alternative helper method that does not use `argparse` at all, instead loading a json file and populating the
|
||||
dataclass types.
|
||||
"""
|
||||
data = json.loads(Path(json_file).read_text())
|
||||
outputs = []
|
||||
@@ -169,8 +161,8 @@ class HfArgumentParser(ArgumentParser):
|
||||
|
||||
def parse_dict(self, args: dict) -> Tuple[DataClass, ...]:
|
||||
"""
|
||||
Alternative helper method that does not use `argparse` at all,
|
||||
instead uses a dict and populating the dataclass types.
|
||||
Alternative helper method that does not use `argparse` at all, instead uses a dict and populating the dataclass
|
||||
types.
|
||||
"""
|
||||
outputs = []
|
||||
for dtype in self.dataclass_types:
|
||||
|
||||
Reference in New Issue
Block a user