-
-
Notifications
You must be signed in to change notification settings - Fork 671
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ignoring an argument for typer command #506
Comments
I assume you solved it, thanks for closing the issue 👍 |
Hiya @tiangolo! I assumed I solved it, but re-opening as I am still unable to skip the argument. |
Any ideas on how to solve this one? For the moment being I omitted my type hints but it's far from ideal. |
Have a look at my little package sitk-cli . I do something very similar, just for images. The function make_cli replaces arguments of type image with pathlib.Path and does loading/saving. I use this concept with typer to create command lines from library code. import SimpleITK as sitk
import typer
from sitk_cli import make_cli
def fill_holes_slice_by_slice(mask: sitk.Image) -> sitk.Image:
mask = mask != 0
output = sitk.Image(mask.GetSize(), mask.GetPixelID())
output.CopyInformation(mask)
for k in range(mask.GetSize()[2]):
output[:, :, k] = sitk.BinaryFillhole(mask[:, :, k], fullyConnected=False)
return output
if __name__ == "__main__":
typer.run(make_cli(fill_holes_slice_by_slice)) |
Just a quick note for anyone else that I ran into this, and the simplest way I could find to skip an option is the below annotation. skipped_option = typer.Option(parser=lambda _: _, hidden=True, expose_value=False) Which you can use as e.g. def foo(a: int, b: Annotate[str, skipped_option] = 'some default'): ... This works because
(The parser argument is the key part missing from the start of this issue). It would be great to have this as a simpler documented feature - but I'm not sure how easy this would be? |
First Check
Commit to Help
Example Code
Description
I have a few functions that I want to type that handle dataframes (both as input and output). I do have a decorator that allows for specifying the dataframes as paths (as opposed to the objects).
Out of this decorator, I now wish to construct a Typer command. Though I keep getting the following error:
Is there an option to completely ignore an argument to the Typer CLI? I tried:
Operating System
macOS
Operating System Details
No response
Typer Version
typer==0.6.1
Python Version
3.9
Additional Context
No response
The text was updated successfully, but these errors were encountered: