Skip to content

Commit a8d5997

Browse files
committed
fix #145 and #149
1 parent d1e2d5f commit a8d5997

File tree

5 files changed

+39
-8
lines changed

5 files changed

+39
-8
lines changed

django_typer/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
model_parser_completer, # noqa: F401
4848
)
4949

50-
VERSION = (2, 4, 0)
50+
VERSION = (2, 5, 0)
5151

5252
__title__ = "Django Typer"
5353
__version__ = ".".join(str(i) for i in VERSION)

django_typer/management/__init__.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,8 @@ def __init__(
531531
]
532532

533533
def call_with_self(*args, **kwargs):
534-
assert callback
534+
if not callback:
535+
return
535536
ctx = t.cast(Context, click.get_current_context())
536537
return callback(
537538
*args,
@@ -620,6 +621,10 @@ def grp(self):
620621
information.
621622
"""
622623

624+
def __init__(self, *args, **kwargs):
625+
self._name = kwargs.get("name", None)
626+
super().__init__(*args, **kwargs)
627+
623628
def list_commands(self, ctx: click.Context) -> t.List[str]:
624629
"""
625630
Do our best to list commands in definition order.
@@ -632,6 +637,18 @@ def list_commands(self, ctx: click.Context) -> t.List[str]:
632637
cmds.remove(defined)
633638
return ordered + cmds
634639

640+
@property
641+
def name(self) -> t.Optional[str]:
642+
return (
643+
self._name or self._callback.__name__.replace("_", "-")
644+
if self._callback
645+
else None
646+
)
647+
648+
@name.setter
649+
def name(self, name: t.Optional[str]):
650+
self._name = name
651+
635652

636653
# staticmethod objects are not picklable which causes problems with deepcopy
637654
# hence the following mishegoss

doc/source/changelog.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
Change Log
33
==========
44

5+
v2.5.0 (2024-11-29)
6+
===================
7+
8+
* Implemented `Support Typer >=0.14 <https://github.com/django-commons/django-typer/issues/149>`_
9+
* Fixed `Typer-style interface throws an assertion when no callback is present on a subgroup. <https://github.com/django-commons/django-typer/issues/145>`_
10+
511
v2.4.0 (2024-11-07)
612
===================
713

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
44

55
[tool.poetry]
66
name = "django-typer"
7-
version = "2.4.0"
7+
version = "2.5.0"
88
description = "Use Typer to define the CLI for your Django management commands."
99
authors = [
1010
"Brian Kohan <[email protected]>",
@@ -63,7 +63,7 @@ click = "^8.1.0"
6363
# typer's release history is full of breaking changes for minor versions
6464
# given the reliance on some of its private internals we peg the typer
6565
# version very strictly to bug fix releases for specific minor lines.
66-
typer-slim = ">=0.13.0,<0.14.0"
66+
typer-slim = ">=0.14.0,<0.15.0"
6767

6868
# this should track typer's rich dependency, so long as our console
6969
# patches still work - so be sure to test on the low end of the range

tests/test_interface.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ def test_typer_command_interface_matches(self):
6666
)
6767

6868
def test_typer_callback_interface_matches(self):
69-
dt_params = set(get_named_arguments(Typer.callback))
69+
dt_params = set(get_named_arguments(Typer.callback)) - {
70+
"name"
71+
} # todo fix in 3.0
7072
typer_params = set(get_named_arguments(typer.Typer.callback))
7173

7274
self.assertFalse(dt_params.symmetric_difference(typer_params))
@@ -76,7 +78,9 @@ def test_typer_callback_interface_matches(self):
7678
)
7779

7880
def test_typer_initialize_interface_matches(self):
79-
dt_params = set(get_named_arguments(Typer.initialize))
81+
dt_params = set(get_named_arguments(Typer.initialize)) - {
82+
"name"
83+
} # todo fix in 3.0
8084
typer_params = set(get_named_arguments(typer.Typer.callback))
8185

8286
self.assertFalse(dt_params.symmetric_difference(typer_params))
@@ -132,7 +136,9 @@ def test_group_interface_matches(self):
132136
def test_initialize_interface_matches(self):
133137
from django_typer.management import callback
134138

135-
initialize_params = set(get_named_arguments(initialize))
139+
initialize_params = set(get_named_arguments(initialize)) - {
140+
"name"
141+
} # todo fix in 3.0
136142
typer_params = set(get_named_arguments(typer.Typer.callback))
137143

138144
self.assertFalse(initialize_params.symmetric_difference(typer_params))
@@ -205,7 +211,9 @@ def test_base_class_command_interface_matches(self):
205211
def test_base_class_initialize_interface_matches(self):
206212
from django_typer.management import TyperCommand
207213

208-
command_params = set(get_named_arguments(TyperCommand.initialize))
214+
command_params = set(get_named_arguments(TyperCommand.initialize)) - {
215+
"name"
216+
} # todo fix in 3.0
209217
typer_params = set(get_named_arguments(typer.Typer.callback))
210218

211219
self.assertFalse(command_params.symmetric_difference(typer_params))

0 commit comments

Comments
 (0)