Skip to content

Commit

Permalink
Run docs generation
Browse files Browse the repository at this point in the history
  • Loading branch information
brentyi committed Jan 7, 2025
1 parent e7156a0 commit 0c2cb26
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 23 deletions.
4 changes: 0 additions & 4 deletions docs/source/examples/custom_constructors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -326,15 +326,13 @@ structs.
if isinstance(type_info.default, Bounds):
# If the default value is a `Bounds` instance, we don't need to generate a constructor.
default = (type_info.default.bounds[0], type_info.default.bounds[1])
is_default_overridden = True
else:
# Otherwise, the default value is missing. We'll mark the child defaults as missing as well.
assert type_info.default in (
tyro.constructors.MISSING,
tyro.constructors.MISSING_NONPROP,
)
default = (tyro.MISSING, tyro.MISSING)
is_default_overridden = False
# If the rule applies, we return the constructor spec.
return tyro.constructors.StructConstructorSpec(
Expand All @@ -345,14 +343,12 @@ structs.
name="lower",
type=int,
default=default[0],
is_default_overridden=is_default_overridden,
helptext="Lower bound." "",
),
tyro.constructors.StructFieldSpec(
name="upper",
type=int,
default=default[1],
is_default_overridden=is_default_overridden,
helptext="Upper bound." "",
),
),
Expand Down
33 changes: 17 additions & 16 deletions docs/source/examples/subcommands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -284,17 +284,17 @@ pushes all arguments to the end of the command:

<pre class="highlight" style="padding: 1em; box-sizing: border-box; font-size: 0.85em; line-height: 1.2em;">
<strong style="opacity: 0.7; padding-bottom: 0.5em; display: inline-block"><span style="user-select: none">$ </span>python ./03_multiple_subcommands.py --help</strong>
<span style="font-weight: bold">usage</span>: 03_multiple_subcommands.py [-h] <span style="font-weight: bold">{dataset:mnist,dataset:image-net}</span>
<span style="font-weight: bold">usage</span>: 03_multiple_subcommands.py [-h] <span style="font-weight: bold">[{dataset:mnist,dataset:image-net}]</span>

Example training script.

<span style="font-weight: lighter">╭─</span><span style="font-weight: lighter"> options </span><span style="font-weight: lighter">────────────────────────────────────────</span><span style="font-weight: lighter">─╮</span>
<span style="font-weight: lighter">│</span> -h, --help <span style="font-weight: lighter">show this help message and exit</span> <span style="font-weight: lighter">│</span>
<span style="font-weight: lighter">╰───────────────────────────────────────────────────╯</span>
<span style="font-weight: lighter">╭─</span><span style="font-weight: lighter"> subcommands </span><span style="font-weight: lighter">────────────────────────────────────</span><span style="font-weight: lighter">─╮</span>
<span style="font-weight: lighter">│</span> <span style="font-weight: bold">Dataset to train on. </span> <span style="font-weight: lighter">│</span>
<span style="font-weight: lighter">│</span> <span style="font-weight: lighter">───────────────────────────────── </span> <span style="font-weight: lighter">│</span>
<span style="font-weight: lighter">│</span> {dataset:mnist,dataset:image-net} <span style="font-weight: lighter">│</span>
<span style="font-weight: lighter">╭─</span><span style="font-weight: lighter"> optional subcommands </span><span style="font-weight: lighter">───────────────────────────</span><span style="font-weight: lighter">─╮</span>
<span style="font-weight: lighter">│</span> <span style="font-weight: bold">Dataset to train on. (default: dataset:mnist) </span> <span style="font-weight: lighter">│</span>
<span style="font-weight: lighter">│</span> <span style="font-weight: lighter">───────────────────────────────────────────── </span> <span style="font-weight: lighter">│</span>
<span style="font-weight: lighter">│</span> [{dataset:mnist,dataset:image-net}] <span style="font-weight: lighter">│</span>
<span style="font-weight: lighter">│</span> dataset:mnist <span style="font-weight: lighter">│</span>
<span style="font-weight: lighter">│</span> dataset:image-net <span style="font-weight: lighter">│</span>
<span style="font-weight: lighter">╰───────────────────────────────────────────────────╯</span>
Expand All @@ -307,18 +307,19 @@ pushes all arguments to the end of the command:
<pre class="highlight" style="padding: 1em; box-sizing: border-box; font-size: 0.85em; line-height: 1.2em;">
<strong style="opacity: 0.7; padding-bottom: 0.5em; display: inline-block"><span style="user-select: none">$ </span>python ./03_multiple_subcommands.py dataset:mnist --help</strong>
<span style="font-weight: bold">usage</span>: 03_multiple_subcommands.py dataset:mnist [-h]
<span style="font-weight: bold">{optimizer:adam,optimizer:sgd}</span>
<span style="font-weight: bold">[{optimizer:adam,optimizer:sgd</span>
<span style="font-weight: bold">}]</span>

<span style="font-weight: lighter">╭─</span><span style="font-weight: lighter"> options </span><span style="font-weight: lighter">────────────────────────────────────────</span><span style="font-weight: lighter">─╮</span>
<span style="font-weight: lighter">│</span> -h, --help <span style="font-weight: lighter">show this help message and exit</span> <span style="font-weight: lighter">│</span>
<span style="font-weight: lighter">╰───────────────────────────────────────────────────╯</span>
<span style="font-weight: lighter">╭─</span><span style="font-weight: lighter"> subcommands </span><span style="font-weight: lighter">────────────────────────────────────</span><span style="font-weight: lighter">─╮</span>
<span style="font-weight: lighter">│</span> <span style="font-weight: bold">Optimizer to train with. </span> <span style="font-weight: lighter">│</span>
<span style="font-weight: lighter">│</span> <span style="font-weight: lighter">────────────────────────────── </span> <span style="font-weight: lighter">│</span>
<span style="font-weight: lighter">│</span> {optimizer:adam,optimizer:sgd} <span style="font-weight: lighter">│</span>
<span style="font-weight: lighter">│</span> optimizer:adam <span style="font-weight: lighter">│</span>
<span style="font-weight: lighter">│</span> optimizer:sgd <span style="font-weight: lighter">│</span>
<span style="font-weight: lighter">╰───────────────────────────────────────────────────╯</span>
<span style="font-weight: lighter">╭─</span><span style="font-weight: lighter"> options </span><span style="font-weight: lighter">────────────────────────────────────────</span><span style="font-weight: lighter">─╮</span>
<span style="font-weight: lighter">│</span> -h, --help <span style="font-weight: lighter">show this help message and exit</span> <span style="font-weight: lighter">│</span>
<span style="font-weight: lighter">╰───────────────────────────────────────────────────╯</span>
<span style="font-weight: lighter">╭─</span><span style="font-weight: lighter"> optional subcommands </span><span style="font-weight: lighter">────────────────────────────</span><span style="font-weight: lighter">─╮</span>
<span style="font-weight: lighter">│</span> <span style="font-weight: bold">Optimizer to train with. (default: optimizer:adam)</span> <span style="font-weight: lighter">│</span>
<span style="font-weight: lighter">│</span> <span style="font-weight: lighter">──────────────────────────────────────────────────</span> <span style="font-weight: lighter">│</span>
<span style="font-weight: lighter">│</span> [{optimizer:adam,optimizer:sgd}] <span style="font-weight: lighter">│</span>
<span style="font-weight: lighter">│</span> optimizer:adam <span style="font-weight: lighter">│</span>
<span style="font-weight: lighter">│</span> optimizer:sgd <span style="font-weight: lighter">│</span>
<span style="font-weight: lighter">╰───────────────────────────────────────────────────╯</span>
</pre>


Expand Down
6 changes: 3 additions & 3 deletions src/tyro/conf/_confstruct.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ def subcommand(
.. code-block:: python
# For the first subcommand, StructType(1) will be used as the default.
# For the first subcommand, StructTypeA(1) will be used as the default.
# The second subcommand, whose type is inconsistent with the field
# default, will be unaffected.
x: Union[
Annotated[
StructTypeA, subcommand(default=StructTypeA(0)
StructTypeA, subcommand(default=StructTypeA(0))
],
Annotated[
StructTypeB, subcommand(default=StructTypeB(0)
StructTypeB, subcommand(default=StructTypeB(0))
],
] = StructTypeA(1)
Expand Down

0 comments on commit 0c2cb26

Please sign in to comment.