
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
A Sphinx directive for auto generating docs for Typer (and Click commands!) using the rich console formatting available in Typer. This package generates concise command documentation in text, html or svg formats out of the box, but if your goal is to greatly customize the generated documentation sphinx-click may be more appropriate and will also work for Typer commands.
Install with pip::
pip install sphinxcontrib-typer
Add sphinxcontrib.typer
to your conf.py
file:
# be sure that the commands you want to document are importable
# from the python path when building the docs
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent / '../path/to/your/commands'))
extensions = [
...
'sphinxcontrib.typer',
...
]
Say you have a command in the file examples/example.py
that looks like
this:
import typer
import typing as t
app = typer.Typer(add_completion=False)
@app.callback()
def callback(
flag1: bool = typer.Option(False, help="Flag 1."),
flag2: bool = typer.Option(False, help="Flag 2.")
):
"""This is the callback function."""
pass
@app.command()
def foo(
name: str = typer.Option(..., help="The name of the item to foo.")
):
"""This is the foo command."""
pass
@app.command()
def bar(
names: t.List[str] = typer.Option(..., help="The names of the items to bar."),
):
"""This is the bar command."""
pass
if __name__ == "__main__":
app()
You can generate documentation for this command using the typer
directive
like so:
.. typer:: examples.example.app
:prog: example1
:width: 70
:preferred: html
This would generate html that looks like this:
You could change :preferred:
to svg, to generate svg instead:
|
Or to text
Usage: example [OPTIONS] COMMAND [ARGS]...
This is the callback function.
╭─ Options ──────────────────────────────────────────────────────────╮
│ --flag1 --no-flag1 Flag 1. [default: no-flag1] │
│ --flag2 --no-flag2 Flag 2. [default: no-flag2] │
│ --help Show this message and exit. │
╰────────────────────────────────────────────────────────────────────╯
╭─ Commands ─────────────────────────────────────────────────────────╮
│ bar This is the bar command. │
│ foo This is the foo command. │
╰────────────────────────────────────────────────────────────────────╯
The typer
directive has options for generating docs for all subcommands as well
and optionally generating independent sections for each. There are also mechanisms
for passing options to the underlying console and svg generation functions. See the
official documentation for more information.
FAQs
Auto generate docs for typer commands.
We found that sphinxcontrib-typer demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.