index
execution_count
cell_type
toolbar
started_at
completed_at
source
loc
metadata
outputs
1
unexecuted
In
[
]
markdown
# integrating `typer` into the blog
in this blog, posts are programs and they are designed to be reused in python.
that means that we want to be able to reuse code and narrative as much as possible.
* add command to __main__
metadata
8
in this blog, posts are programs and they are designed to be reused in python.
that means that we want to be able to reuse code and narrative as much as possible.
2
executed
In
[
44
]
code
IMPORTED , MAIN = "__file__" in locals (), __name__ == "__main__" ; Ø = not IMPORTED and MAIN
metadata
1
0 outputs.
Out
[
44
]
3
unexecuted
In
[
]
markdown
## a small example
the first example we'll describe is a simple function with little consequence.
this will validate our integration.
metadata
4
the first example we'll describe is a simple function with little consequence.
this will validate our integration.
4
executed
In
[
45
]
code
def main ( greeting : str = "howdy" , name : str = "tony" ):
"""a nothing function that says hi to the audience"""
print ( greeting , name )
metadata
3
0 outputs.
Out
[
45
]
5
unexecuted
In
[
]
markdown
invoking the command line
metadata
1
invoking the command line
6
executed
In
[
25
]
code
if Ø :
! python - m tonyfast
metadata
2
1 outputs.
Out
[
25
]
[1m [0m
[1m [0m[1;33mUsage: [0m[1mpython [0m[1;32m-m[0m[1m tonyfast [OPTIONS] COMMAND [ARGS]...[0m[1m [0m[1m [0m
[1m [0m
[2mâ•─[0m[2m Options [0m[2m───────────────────────────────────────────────────────────────────[0m[2m─â•®[0m
[2m│[0m [1;36m-[0m[1;36m-help[0m [1;32m-h[0m Show this message and exit. [2m│[0m
[2mâ•°──────────────────────────────────────────────────────────────────────────────╯[0m
[2mâ•─[0m[2m Commands [0m[2m──────────────────────────────────────────────────────────────────[0m[2m─â•®[0m
[2m│[0m [1;36mhello [0m[1;36m [0m a nothing function that says hi to the audience [2m│[0m
[2m│[0m [1;36mtasks [0m[1;36m [0m run doit tasks [2m│[0m
[2mâ•°──────────────────────────────────────────────────────────────────────────────╯[0m
7
executed
In
[
26
]
code
if Ø :
! python - m tonyfast hello -- name y \'all
metadata
2
1 outputs.
Out
[
26
]
8
unexecuted
In
[
]
markdown
this is a nice example to start with because it allows us to consider what our works look like as literature.
metadata
1
this is a nice example to start with because it allows us to consider what our works look like as literature.
9
unexecuted
In
[
]
markdown
## a more complex example
in a recent post, we made it possible add `doit` tasks to the blog.
metadata
3
in a recent post, we made it possible add
doit
tasks to the blog.
10
executed
In
[
46
]
code
from typer import Typer , Context
app = Typer ( rich_markup_mode = "rich" )
@app . command ( context_settings = { "allow_extra_args" : True , "ignore_unknown_options" : True })
def tasks ( ctx : Context ):
"""run doit tasks"""
from doit.doit_cmd import DoitMain
from doit.cmd_base import ModuleTaskLoader
from tonyfast import dodo
return DoitMain ( ModuleTaskLoader ( dodo )) . run ( ctx . args )
metadata
11
0 outputs.
Out
[
46
]
11
unexecuted
In
[
]
markdown
verifying the `doit` commands
metadata
1
verifying the
doit
commands
12
executed
In
[
47
]
code
if Ø :
! python - m tonyfast tasks list -- status -- all
metadata
2
1 outputs.
Out
[
47
]
R mkdocs build document with mkdocs
R mkdocs:build
R mkdocs:toc
13
unexecuted
In
[
]
markdown
## invoking this document as a standalone script
metadata
2
14
executed
In
[
42
]
code
if IMPORTED and MAIN :
app . command ( name = "hello" )( main )
app ()
metadata
3
0 outputs.
Out
[
42
]
15
executed
In
[
43
]
code
if Ø :
! importnb 2022 - 12 - 19 - integrating - typer . ipynb -- help
metadata
2
1 outputs.
Out
[
43
]
[1m [0m
[1m [0m[1;33mUsage: [0m[1m2022-12-19-integrating-typer.ipynb [OPTIONS] COMMAND [ARGS]...[0m[1m [0m[1m [0m
[1m [0m
[2mâ•─[0m[2m Options [0m[2m───────────────────────────────────────────────────────────────────[0m[2m─â•®[0m
[2m│[0m [1;36m-[0m[1;36m-install[0m[1;36m-completion[0m Install completion for the current shell. [2m│[0m
[2m│[0m [1;36m-[0m[1;36m-show[0m[1;36m-completion[0m Show completion for the current shell, to copy [2m│[0m
[2m│[0m it or customize the installation. [2m│[0m
[2m│[0m [1;36m-[0m[1;36m-help[0m Show this message and exit. [2m│[0m
[2mâ•°──────────────────────────────────────────────────────────────────────────────╯[0m
[2mâ•─[0m[2m Commands [0m[2m──────────────────────────────────────────────────────────────────[0m[2m─â•®[0m
[2m│[0m [1;36mhello [0m[1;36m [0m a nothing function that says hi to the audience [2m│[0m
[2m│[0m [1;36mtasks [0m[1;36m [0m run doit tasks [2m│[0m
[2mâ•°──────────────────────────────────────────────────────────────────────────────╯[0m