Skip to content

Commit da750ce

Browse files
committed
add tabs to docs
1 parent fef63fd commit da750ce

File tree

5 files changed

+64
-39
lines changed

5 files changed

+64
-39
lines changed

django_typer/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,6 +1322,7 @@ def __getattr__(self, name: str) -> t.Any:
13221322
"""
13231323
if hasattr(self.proxied, name):
13241324
attr = getattr(self.proxied, name)
1325+
# want to avoid recursive binding
13251326
if isinstance(attr, (Typer, typer.models.CommandInfo)):
13261327
return BoundProxy(self.command, attr)
13271328
return attr
@@ -1332,6 +1333,9 @@ def __getattr__(self, name: str) -> t.Any:
13321333
)
13331334
)
13341335

1336+
# def __repr__(self) -> str:
1337+
# return f'<{self.__class__.__module__}.{self.__class__.__name__} for {repr(self.proxied)}>'
1338+
13351339

13361340
def initialize(
13371341
name: t.Optional[str] = Default(None),

doc/source/conf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@
5050
'sphinx_rtd_theme',
5151
'sphinx.ext.autodoc',
5252
'sphinx.ext.todo',
53-
'sphinxcontrib.typer'
53+
'sphinxcontrib.typer',
54+
'sphinx_tabs.tabs'
5455
]
5556

5657
# Add any paths that contain templates here, relative to this directory.

doc/source/index.rst

Lines changed: 55 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -54,58 +54,73 @@ replacement.
5454
5555
*You only need to install django_typer as an app if you want to use the shellcompletion command
5656
to enable tab-completion or if you would like django-typer to install*
57-
:ref:`rich traceback rendering <configure-rich-exception-tracebacks>` *for you - which it does by
58-
default if rich is also installed.*
57+
:ref:`rich traceback rendering <configure-rich-exception-tracebacks>` *for you - which it does
58+
by default if rich is also installed.*
59+
60+
.. note::
61+
62+
This documentation shows all examples using both the function orientied Typer-style interface
63+
and the class based Django-style interface using tabs. Each interface is equivalent so the
64+
choice of which to use is a matter of preference.
5965

6066
:big:`Basic Example`
6167

6268
For example TyperCommands can be a very simple drop in replacement for BaseCommands. All of the
63-
documented features of BaseCommand_ work!
69+
documented features of BaseCommand_ work! Or, you may also use an interface identitical to Typer's.
70+
Simply import Typer from django_typer instead of typer.
6471

72+
.. tabs::
6573

66-
.. literalinclude:: ../../django_typer/tests/apps/examples/basic/management/commands/basic.py
67-
:language: python
68-
:caption: A Basic Command
69-
:linenos:
74+
.. tab:: Django-style
7075

71-
Or, you may also use an interface identitical to Typer's. Simply import Typer from django_typer
72-
instead of typer:
76+
.. literalinclude:: ../../django_typer/tests/apps/examples/basic/management/commands/basic.py
77+
:language: python
78+
:caption: management/commands/basic.py
79+
:linenos:
7380

74-
.. literalinclude:: ../../django_typer/tests/apps/examples/typer/management/commands/basic.py
75-
:language: python
76-
:caption: A Typer-style Basic Command
77-
:linenos:
81+
.. tab:: Typer-style
82+
83+
.. literalinclude:: ../../django_typer/tests/apps/examples/typer/management/commands/basic.py
84+
:language: python
85+
:caption: management/commands/basic.py
86+
:linenos:
7887

7988

8089
.. typer:: django_typer.tests.apps.examples.basic.management.commands.basic.Command:typer_app
8190
:prog: ./manage.py basic
8291
:width: 80
8392
:convert-png: latex
93+
:theme: dark
8494

8595
|
8696
8797
:big:`Multiple Subcommands Example`
8898

8999
Commands with multiple subcommands can be defined:
90100

91-
.. literalinclude:: ../../django_typer/tests/apps/examples/basic/management/commands/multi.py
92-
:language: python
93-
:caption: A Command w/Subcommands
94-
:linenos:
101+
.. tabs::
102+
103+
.. tab:: Django-style
95104

96-
Or using the typer-style interface this could be written:
105+
.. literalinclude:: ../../django_typer/tests/apps/examples/basic/management/commands/multi.py
106+
:language: python
107+
:caption: management/commands/multi.py
108+
:linenos:
97109

98-
.. literalinclude:: ../../django_typer/tests/apps/examples/typer/management/commands/multi.py
99-
:language: python
100-
:caption: A Typer-style Command w/Subcommands
101-
:linenos:
110+
.. tab:: Typer-style
111+
112+
.. literalinclude:: ../../django_typer/tests/apps/examples/typer/management/commands/multi.py
113+
:language: python
114+
:caption: management/commands/multi.py
115+
:linenos:
102116

103117

104118
.. typer:: django_typer.tests.apps.examples.basic.management.commands.multi.Command:typer_app
105119
:prog: ./manage.py multi
106120
:width: 80
107121
:show-nested:
108122
:convert-png: latex
123+
:theme: dark
109124

110125
|
111126
@@ -124,29 +139,33 @@ command like so:
124139
./manage.py hierarchy math multiply 10 2
125140
20.00
126141
127-
Any number of groups and subcommands and subgroups of other groups can be defined allowing
128-
for arbitrarily complex command hierarchies. Using the class-based interface we could define
129-
the command like this:
142+
Any number of groups and subcommands and subgroups of other groups can be defined allowing for
143+
arbitrarily complex command hierarchies. The Typer-style interface builds a TyperCommand class for
144+
us. **This allows you to optionally accept the self argument in your commands.** We could define
145+
the above command using the typer interface like this:
146+
147+
.. tabs::
148+
149+
.. tab:: Django-style
130150

131-
.. literalinclude:: ../../django_typer/tests/apps/examples/basic/management/commands/hierarchy.py
132-
:language: python
133-
:caption: A Command w/Grouping Hierarchy
134-
:linenos:
151+
.. literalinclude:: ../../django_typer/tests/apps/examples/basic/management/commands/hierarchy.py
152+
:language: python
153+
:caption: management/commands/hierarchy.py
154+
:linenos:
135155

136-
The typer-style interface builds a TyperCommand class for us. This allows you to optionally
137-
accept the self argument in your commands. We could define the above command using the typer
138-
interface like this:
156+
.. tab:: Typer-style
139157

140-
.. literalinclude:: ../../django_typer/tests/apps/examples/typer/management/commands/hierarchy.py
141-
:language: python
142-
:caption: A Typer-style Command w/Grouping Hierarchy
143-
:linenos:
158+
.. literalinclude:: ../../django_typer/tests/apps/examples/typer/management/commands/hierarchy.py
159+
:language: python
160+
:caption: management/commands/hierarchy.py
161+
:linenos:
144162

145163
.. typer:: django_typer.tests.apps.examples.basic.management.commands.hierarchy.Command:typer_app
146164
:prog: ./manage.py hierarchy
147165
:width: 80
148166
:show-nested:
149167
:convert-png: latex
168+
:theme: dark
150169

151170
|
152171

doc/source/reference.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ django_typer
2323
:members: initialize, callback, command, group, echo, secho, print_help, get_subcommand
2424

2525
.. autoclass:: django_typer.CommandNode
26-
:members: name, click_command, context, parent, children, get_command, print_help
26+
:members: name, click_command, context, children, get_command, print_help
2727

2828
.. autoclass:: django_typer.TyperCommandMeta
2929

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pylint = "^3.0"
7373
doc8 = "^1.1.1"
7474
aiohttp = "^3.9.1"
7575
readme-renderer = {extras = ["md"], version = ">=42,<44"}
76-
sphinxcontrib-typer = {extras = ["html", "pdf", "png"], version = "^0.2.3", markers="python_version >= '3.9'"}
76+
sphinxcontrib-typer = {extras = ["html", "pdf", "png"], version = "^0.2.5", markers="python_version >= '3.9'"}
7777
scikit-learn = "^1.0.0"
7878
pytest-env = "^1.0.0"
7979
numpy = [
@@ -89,6 +89,7 @@ pexpect = "^4.9.0"
8989
pyright = "^1.1.357"
9090
ruff = "^0.4.1"
9191
graphviz = "^0.20.3"
92+
sphinx-tabs = "^3.4.5"
9293

9394
[tool.poetry.extras]
9495
rich = ["rich"]

0 commit comments

Comments
 (0)