Skip to content

Commit 00756c8

Browse files
authored
Merge pull request #57 from bckohan/v1.1.x
Pull in version 1.1.2
2 parents 8dedb01 + 72a7a84 commit 00756c8

File tree

5 files changed

+90
-3
lines changed

5 files changed

+90
-3
lines changed

django_typer/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
from typing import ParamSpec
115115

116116

117-
VERSION = (1, 1, 1)
117+
VERSION = (1, 1, 2)
118118

119119
__title__ = "Django Typer"
120120
__version__ = ".".join(str(i) for i in VERSION)
@@ -311,7 +311,7 @@ def __init__(self, args: t.Sequence[t.Any], **kwargs):
311311
self.traceback = kwargs.get("traceback", TyperCommand._traceback)
312312

313313
def _get_kwargs(self):
314-
return {"args": self.args, **COMMON_DEFAULTS}
314+
return {**COMMON_DEFAULTS, **vars(self)}
315315

316316

317317
class Context(TyperContext):
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import sys
2+
3+
from django_typer import TyperCommand
4+
5+
if sys.version_info < (3, 9):
6+
from typing_extensions import Annotated
7+
else:
8+
from typing import Annotated
9+
10+
import typing as t
11+
from enum import Enum
12+
from pathlib import Path
13+
14+
from typer import Argument, Option
15+
16+
17+
class VersionEnum(str, Enum):
18+
19+
VERSION1 = "1"
20+
VERSION1_1 = "1.1"
21+
VERSION2 = "2"
22+
23+
24+
class Command(TyperCommand):
25+
help = "Override some default django options."
26+
27+
def handle(
28+
self,
29+
settings: Annotated[Path, Argument(help="Override default settings argument.")],
30+
optional_arg: Annotated[int, Argument(help="An optional argument.")] = 0,
31+
version: Annotated[
32+
t.Optional[VersionEnum],
33+
Option("--version", help="Override default version argument."),
34+
] = None,
35+
):
36+
return {
37+
"settings": settings,
38+
"version": version,
39+
**({"optional_arg": optional_arg} if optional_arg else {}),
40+
}

django_typer/tests/tests.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2914,3 +2914,45 @@ def test_call_group_with_prompt_value(self):
29142914
),
29152915
"test_flag bckohan test_password4",
29162916
)
2917+
2918+
2919+
class TestDefaultParamOverrides(TestCase):
2920+
"""
2921+
Tests that overloaded group/command names work as expected.
2922+
"""
2923+
2924+
def test_override_direct(self):
2925+
from django_typer.tests.test_app.management.commands.override import VersionEnum
2926+
2927+
override = get_command("override")
2928+
self.assertDictEqual(
2929+
override("path/to/settings", version="1.1"),
2930+
{"settings": "path/to/settings", "version": "1.1"},
2931+
)
2932+
2933+
def test_override_cli(self):
2934+
from django_typer.tests.test_app.management.commands.override import VersionEnum
2935+
2936+
result = run_command("override", "path/to/settings", "--version", "1.1")[0]
2937+
self.assertEqual(
2938+
result.strip(),
2939+
str(
2940+
{
2941+
"settings": Path("path/to/settings"),
2942+
"version": VersionEnum.VERSION1_1,
2943+
}
2944+
).strip(),
2945+
)
2946+
2947+
def test_override_call_command(self):
2948+
from django_typer.tests.test_app.management.commands.override import VersionEnum
2949+
2950+
call_command("override", "path/to/settings", 1, version="1.1")
2951+
self.assertDictEqual(
2952+
call_command("override", "path/to/settings", 1, version="1.1"),
2953+
{
2954+
"settings": Path("path/to/settings"),
2955+
"version": VersionEnum.VERSION1_1,
2956+
"optional_arg": 1,
2957+
},
2958+
)

doc/source/changelog.rst

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

5+
v1.1.2
6+
======
7+
8+
* Fixed `Overridden common Django arguments fail to pass through when passed through call_command <https://github.com/bckohan/django-typer/issues/54>`_
9+
510
v1.1.1
611
======
712

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "django-typer"
3-
version = "1.1.1"
3+
version = "1.1.2"
44
description = "Use Typer to define the CLI for your Django management commands."
55
authors = ["Brian Kohan <bckohan@gmail.com>"]
66
license = "MIT"

0 commit comments

Comments
 (0)