Skip to content

Commit

Permalink
Merge pull request #57 from bckohan/v1.1.x
Browse files Browse the repository at this point in the history
Pull in version 1.1.2
  • Loading branch information
bckohan committed Apr 22, 2024
2 parents 8dedb01 + 72a7a84 commit 00756c8
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 3 deletions.
4 changes: 2 additions & 2 deletions django_typer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
from typing import ParamSpec


VERSION = (1, 1, 1)
VERSION = (1, 1, 2)

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

def _get_kwargs(self):
return {"args": self.args, **COMMON_DEFAULTS}
return {**COMMON_DEFAULTS, **vars(self)}


class Context(TyperContext):
Expand Down
40 changes: 40 additions & 0 deletions django_typer/tests/test_app/management/commands/override.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import sys

from django_typer import TyperCommand

if sys.version_info < (3, 9):
from typing_extensions import Annotated
else:
from typing import Annotated

import typing as t
from enum import Enum
from pathlib import Path

from typer import Argument, Option


class VersionEnum(str, Enum):

VERSION1 = "1"
VERSION1_1 = "1.1"
VERSION2 = "2"


class Command(TyperCommand):
help = "Override some default django options."

def handle(
self,
settings: Annotated[Path, Argument(help="Override default settings argument.")],
optional_arg: Annotated[int, Argument(help="An optional argument.")] = 0,
version: Annotated[
t.Optional[VersionEnum],
Option("--version", help="Override default version argument."),
] = None,
):
return {
"settings": settings,
"version": version,
**({"optional_arg": optional_arg} if optional_arg else {}),
}
42 changes: 42 additions & 0 deletions django_typer/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2914,3 +2914,45 @@ def test_call_group_with_prompt_value(self):
),
"test_flag bckohan test_password4",
)


class TestDefaultParamOverrides(TestCase):
"""
Tests that overloaded group/command names work as expected.
"""

def test_override_direct(self):
from django_typer.tests.test_app.management.commands.override import VersionEnum

override = get_command("override")
self.assertDictEqual(
override("path/to/settings", version="1.1"),
{"settings": "path/to/settings", "version": "1.1"},
)

def test_override_cli(self):
from django_typer.tests.test_app.management.commands.override import VersionEnum

result = run_command("override", "path/to/settings", "--version", "1.1")[0]
self.assertEqual(
result.strip(),
str(
{
"settings": Path("path/to/settings"),
"version": VersionEnum.VERSION1_1,
}
).strip(),
)

def test_override_call_command(self):
from django_typer.tests.test_app.management.commands.override import VersionEnum

call_command("override", "path/to/settings", 1, version="1.1")
self.assertDictEqual(
call_command("override", "path/to/settings", 1, version="1.1"),
{
"settings": Path("path/to/settings"),
"version": VersionEnum.VERSION1_1,
"optional_arg": 1,
},
)
5 changes: 5 additions & 0 deletions doc/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
Change Log
==========

v1.1.2
======

* Fixed `Overridden common Django arguments fail to pass through when passed through call_command <https://github.com/bckohan/django-typer/issues/54>`_

v1.1.1
======

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "django-typer"
version = "1.1.1"
version = "1.1.2"
description = "Use Typer to define the CLI for your Django management commands."
authors = ["Brian Kohan <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit 00756c8

Please sign in to comment.