[Django] #25736: Define management commands via function

28 views
Skip to first unread message

Django

unread,
Nov 11, 2015, 9:00:14 PM11/11/15
to django-...@googlegroups.com
#25736: Define management commands via function
--------------------------------------------+--------------------
Reporter: olethanh | Owner: nobody
Type: New feature | Status: new
Component: Core (Management commands) | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------------+--------------------
Creating a new management command currently require a lot of boilerplate
to remember, a small part of it is having to subclass a command. This is
often overkill when you just have a function and don't need complex
arguments parsing.

So I'm proposing to allow using function for Command.

I'm attaching an idea of an implementation but I'm not really set on it.
This would allow to write:


{{{
from django.core.management.base import LabelCommand

def print_label(label):
"Help message"
print label

Command = LabelCommand.from_func(print_label,
can_import_settings=False)
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/25736>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 11, 2015, 9:04:26 PM11/11/15
to django-...@googlegroups.com
#25736: Define management commands via function
-------------------------------------+-------------------------------------

Reporter: olethanh | Owner: nobody
Type: New feature | Status: new
Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by olethanh):

* needs_docs: => 0
* has_patch: 0 => 1
* needs_tests: => 0
* needs_better_patch: => 0


Old description:

> Creating a new management command currently require a lot of boilerplate
> to remember, a small part of it is having to subclass a command. This is
> often overkill when you just have a function and don't need complex
> arguments parsing.
>
> So I'm proposing to allow using function for Command.
>
> I'm attaching an idea of an implementation but I'm not really set on it.
> This would allow to write:
>

> {{{
> from django.core.management.base import LabelCommand
>
> def print_label(label):
> "Help message"
> print label
>
> Command = LabelCommand.from_func(print_label,
> can_import_settings=False)
> }}}

New description:

Creating a new management command currently require a lot of boilerplate
to remember, a small part of it is having to subclass a command. This is
often overkill when you just have a function and don't need complex
arguments parsing.

So I'm proposing to allow using function for Command.

I'm attaching an idea of an implementation but I'm not really set on it.
This would allow to write:


{{{
from django.core.management.base import LabelCommand

def print_label(label):
"Help message"
print label

Command = LabelCommand.from_func(print_label,
can_import_settings=False)
}}}

Proposed implementation:
https://github.com/django/django/compare/master...olethanh:ticket_27536?expand=1

--

--
Ticket URL: <https://code.djangoproject.com/ticket/25736#comment:1>

Django

unread,
Nov 11, 2015, 9:04:59 PM11/11/15
to django-...@googlegroups.com
#25736: Define management commands via function
-------------------------------------+-------------------------------------

Reporter: olethanh | Owner: nobody
Type: New feature | Status: new
Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by olethanh):

* needs_better_patch: 0 => 1
* needs_tests: 0 => 1
* needs_docs: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/25736#comment:2>

Django

unread,
Nov 11, 2015, 9:06:10 PM11/11/15
to django-...@googlegroups.com
#25736: Define management commands via function
-------------------------------------+-------------------------------------

Reporter: olethanh | Owner: nobody
Type: New feature | Status: new
Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed

Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by olethanh):

* Attachment "e.patch" added.

Django

unread,
Nov 13, 2015, 12:37:36 PM11/13/15
to django-...@googlegroups.com
#25736: Define management commands via function
-------------------------------------+-------------------------------------

Reporter: olethanh | Owner: nobody
Type: New feature | Status: new
Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed

Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by timgraham):

Could you raise the idea on the DevelopersMailingList to get more feedback
on the idea?

--
Ticket URL: <https://code.djangoproject.com/ticket/25736#comment:3>

Django

unread,
Nov 17, 2015, 12:33:49 PM11/17/15
to django-...@googlegroups.com
#25736: Define management commands via function
-------------------------------------+-------------------------------------
Reporter: olethanh | Owner: nobody
Type: New feature | Status: closed

Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed

Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* status: new => closed
* resolution: => wontfix


Comment:

Please reopen if you can start a discussion and get a consensus to add
this. Thanks!

--
Ticket URL: <https://code.djangoproject.com/ticket/25736#comment:4>

Reply all
Reply to author
Forward
0 new messages