Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
e3rd committed Sep 11, 2024
1 parent f8f2d32 commit 865a773
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,5 +223,6 @@ m.form(my_dictionary)






31 changes: 19 additions & 12 deletions mininterface/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,26 @@ class Env:
You cay context manager the function by a `with` statement.
The stdout will be redirected to the interface (ex. a GUI window).
TODO add wrap example
Undocumented experimental: The `env_class` may be a function as well. We invoke its parameters.
However, as Mininterface.env stores the output of the function instead of the Argparse namespace,
methods like `Mininterface.form(None)` (to ask for editing the env values) will work unpredictibly.
Also, the config file seems to be fetched only for positional (missing) parameters,
and ignored for keyword (filled) parameters.
It seems to be this is the tyro's deal and hence it might start working any time.
If not, we might help it this way:
`if isinstance(config, FunctionType): config = lambda: config(**kwargs["default"])`
Undocumented experimental: `default` keyword argument for tyro may serve for default values instead of a config file.
```python
with run(Env) as m:
print(f"Your important number is {m.env.important_number}")
boolean = m.is_yes("Is that alright?")
```
![Small window with the text 'Your important number'](asset/hello-with-statement.webp "With statement to redirect the output")
![The same in terminal'](asset/hello-with-statement-tui.avif "With statement in TUI fallback")
"""
# Undocumented experimental: The `env_class` may be a function as well. We invoke its parameters.
# However, as Mininterface.env stores the output of the function instead of the Argparse namespace,
# methods like `Mininterface.form(None)` (to ask for editing the env values) will work unpredictibly.
# Also, the config file seems to be fetched only for positional (missing) parameters,
# and ignored for keyword (filled) parameters.
# It seems to be this is the tyro's deal and hence it might start working any time.
# If not, we might help it this way:
# `if isinstance(config, FunctionType): config = lambda: config(**kwargs["default"])`
#
# Undocumented experimental: `default` keyword argument for tyro may serve for default values instead of a config file.

# Prepare the config file
if config_file is True and not kwargs.get("default") and env_class:
Expand Down

0 comments on commit 865a773

Please sign in to comment.