Skip to content

Commit

Permalink
run black and isort
Browse files Browse the repository at this point in the history
  • Loading branch information
bckohan committed Jan 9, 2024
1 parent b9e0e3d commit 3473d2f
Show file tree
Hide file tree
Showing 15 changed files with 49 additions and 46 deletions.
50 changes: 24 additions & 26 deletions django_typer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
import inspect
import sys
import typing as t
from copy import deepcopy
from dataclasses import dataclass
from importlib import import_module
from types import MethodType, SimpleNamespace
from copy import deepcopy

import click
from django.conf import settings
Expand All @@ -42,7 +42,7 @@
Version,
)

VERSION = (0, 3, "0b")
VERSION = (0, 4, "0b")

__title__ = "Django Typer"
__version__ = ".".join(str(i) for i in VERSION)
Expand All @@ -63,7 +63,6 @@

"""
TODO
- add translation support in helps
- useful django types (app label, etc)
- documentation
- linting
Expand Down Expand Up @@ -118,12 +117,17 @@ def _common_options(
# cache common params to avoid this extra work on every command
# we cant resolve these at module scope because translations break it
_common_params = []


def _get_common_params():
global _common_params
if not _common_params:
_common_params = get_params_convertors_ctx_param_name_from_function(_common_options)[0]
_common_params = get_params_convertors_ctx_param_name_from_function(
_common_options
)[0]
return _common_params


COMMON_DEFAULTS = {
key: value.default
for key, value in inspect.signature(_common_options).parameters.items()
Expand Down Expand Up @@ -202,7 +206,7 @@ def __init__(
*args,
callback: t.Optional[ # pylint: disable=redefined-outer-name
t.Callable[..., t.Any]
] = None,
],
params: t.Optional[t.List[click.Parameter]] = None,
**kwargs,
):
Expand All @@ -212,26 +216,20 @@ def __init__(
self_arg = params[0].name if params else "self"

def call_with_self(*args, **kwargs):
if callback:
return callback(
*args,
**{
param: val for param, val in kwargs.items() if param in expected
},
**(
{
self_arg: getattr(
click.get_current_context(), "django_command", None
)
}
if self.callback_is_method
else {}
),
)
return None
return callback(
*args,
**{param: val for param, val in kwargs.items() if param in expected},
**(
{
self_arg: getattr(
click.get_current_context(), "django_command", None
)
}
if self.callback_is_method
else {}
),
)

from django.utils.translation import gettext_lazy
bool(gettext_lazy('test'))
super().__init__( # type: ignore
*args,
params=[
Expand Down Expand Up @@ -310,7 +308,7 @@ def command(
deprecated: bool = False,
# Rich settings
rich_help_panel: t.Union[str, None] = Default(None),
**kwargs
**kwargs,
):
return super().command(
name=name,
Expand All @@ -325,7 +323,7 @@ def command(
hidden=hidden,
deprecated=deprecated,
rich_help_panel=rich_help_panel,
**kwargs
**kwargs,
)

def group(
Expand Down
4 changes: 4 additions & 0 deletions django_typer/locale/de/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,7 @@ msgstr "Die Befehlsausgabe nicht einfärben."
#: types.py:102
msgid "Skip system checks."
msgstr "Systemprüfungen überspringen."


msgid "Show this message and exit."
msgstr "Zeige diese Nachricht und beende."
4 changes: 2 additions & 2 deletions django_typer/tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
https://docs.djangoproject.com/en/3.2/ref/settings/
"""

from pathlib import Path
import os
from pathlib import Path

# Set default terminal width for help outputs - necessary for
# testing help output in CI environments.
Expand Down Expand Up @@ -106,7 +106,7 @@
# https://docs.djangoproject.com/en/3.2/topics/i18n/

LANGUAGE_CODE = "en-us"
#LANGUAGE_CODE = 'de'
# LANGUAGE_CODE = 'de'


TIME_ZONE = "UTC"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json

from django_typer import TyperCommand, initialize, command
from django_typer import TyperCommand, command, initialize


class Command(TyperCommand, invoke_without_command=True):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.core.management import CommandError

from django_typer import TyperCommand, initialize, command, types
from django_typer import TyperCommand, command, initialize, types
from django_typer.tests.utils import log_django_parameters


Expand Down
2 changes: 1 addition & 1 deletion django_typer/tests/test_app/management/commands/groups.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import typing as t

from django.utils.translation import gettext_lazy as _
from typer import Argument

from django_typer import TyperCommand, command, group
from django.utils.translation import gettext_lazy as _


class Command(TyperCommand):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django.utils.translation import gettext_lazy as _

from django_typer import TyperCommand, initialize, command
from django_typer import TyperCommand, command, initialize


class Command(TyperCommand, help=_("Test minimal TyperCommand subclass - typer param")):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django.utils.translation import gettext_lazy as _

from django_typer import TyperCommand, initialize, command
from django_typer import TyperCommand, command, initialize


class Command(TyperCommand):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

from django.utils.translation import gettext_lazy as _

from django_typer import TyperCommand, initialize, command
from django_typer import TyperCommand, command, initialize


class Command(TyperCommand):

@initialize(help=_("Test minimal TyperCommand subclass - callback method"))
def init(self, verbosity: int = 1):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

from django.utils.translation import gettext_lazy as _

from django_typer import TyperCommand, initialize, command
from django_typer import TyperCommand, command, initialize


class Command(TyperCommand):

@initialize()
def init(self, verbosity: int = 1):
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json

from django_typer import TyperCommand, initialize, command
from django_typer import TyperCommand, command, initialize


class Command(TyperCommand, add_completion=False):
Expand Down
4 changes: 2 additions & 2 deletions django_typer/tests/test_app2/management/commands/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

from typer import Argument

from django_typer import initialize, command, types
from django_typer import command, initialize, types
from django_typer.tests.test_app.management.commands.groups import (
Command as GroupsCommand,
)

class Command(GroupsCommand, add_completion=False, epilog="Overridden from test_app."):

class Command(GroupsCommand, add_completion=False, epilog="Overridden from test_app."):
help = "Test groups command inheritance."

precision = 2
Expand Down
7 changes: 4 additions & 3 deletions django_typer/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,7 @@ class TestGroups(TestCase):
A collection of tests that test complex grouping commands and also that
command inheritance behaves as expected.
"""

@override_settings(
INSTALLED_APPS=[
"django_typer.tests.test_app",
Expand Down Expand Up @@ -771,13 +772,13 @@ def test_command_line(self, settings=None):

self.assertEqual(
run_command("groups", *settings, "echo", "hey!").strip(),
call_command("groups", "echo", 'hey!').strip(),
"hey!"
call_command("groups", "echo", "hey!").strip(),
"hey!",
)
self.assertEqual(
get_command("groups", "echo")("hey!").strip(),
get_command("groups", "echo")(message="hey!").strip(),
"hey!"
"hey!",
)

result = run_command("groups", *settings, "echo", "hey!", "5")
Expand Down
6 changes: 4 additions & 2 deletions django_typer/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import sys
from pathlib import Path
from typing import Annotated, Optional
from django.utils.translation import gettext_lazy as _

from django.utils.translation import gettext_lazy as _
from typer import Option

COMMON_PANEL = "Django"
Expand Down Expand Up @@ -99,5 +99,7 @@ def print_version(context, _, value):

SkipChecks = Annotated[
bool,
Option("--skip-checks", help=_("Skip system checks."), rich_help_panel=COMMON_PANEL),
Option(
"--skip-checks", help=_("Skip system checks."), rich_help_panel=COMMON_PANEL
),
]
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 = "0.3.0b"
version = "0.4.0b"
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 3473d2f

Please sign in to comment.