cs-djutils


Namecs-djutils JSON
Version 20241222.3 PyPI version JSON
download
home_pageNone
SummaryMy collection of things for working with Django.
upload_time2024-12-21 22:03:48
maintainerNone
docs_urlNone
authorNone
requires_pythonNone
licenseGNU General Public License v3 or later (GPLv3+)
keywords python3
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            My collection of things for working with Django.

*Latest release 20241222.3*:
Autocall settings.configure() if required because Django's settings object is a royal PITA.

## <a name="BaseCommand"></a>Class `BaseCommand(cs.cmdutils.BaseCommand, django.core.management.base.BaseCommand)`

A drop in class for `django.core.management.base.BaseCommand`
which subclasses `cs.cmdutils.BaseCommand`.

This lets me write management commands more easily, particularly
if there are subcommands.

This is a drop in in the sense that you still make a management command
in nearly the same way:

    from cs.djutils import BaseCommand

    class Command(BaseCommand):

and `manage.py` will find it and run it as normal.
But from that point on the style is as for `cs.cmdutils.BaseCommand`:
- no `aegparse` setup
- direct support for subcommands as methods
- succinct option parsing, if you want command line options

A simple command looks like this:

    class Command(BaseCommand):

        def main(self, argv):
            ... do stuff based on the CLI args `argv` ...

A command with subcommands looks like this:

    class Command(BaseCommand):

        def cmd_this(self, argv):
            ... do the "this" subcommand ...

        def cmd_that(self, argv):
            ... do the "that" subcommand ...

If want some kind of app/client specific "overcommand" composed
from other management commands you can import them and make
them subcommands of the overcommand:

    from .other_command import Command as OtherCommand

    class Command(BaseCommand):

        # provide it as the "other" subcommand
        cmd_other = OtherCommand

Option parsing is inline in the command. `self` comes
presupplied with a `.options` attribute which is an instance
of `cs.cmdutils.BaseCommandOptions` (or some subclass).

Parsing options is simple:

    class Command(BaseCommand):

        def cmd_this(self, argv):
            options = self.options
            # parsing options:
            #
            # boolean -x option, makes options.x
            #
            # --thing-limit n option taking an int
            # makes options.thing_limit
            # help text is "Thing limit."
            #
            # a --mode foo option taking a string
            # makes options.mode
            # help text is "The run mode."
            options.popopts(
                argv,
                x=None,
                thing_limit_=int,
                mode_='The run mode.',
            )
            ... now consult options.x or whatever
            ... argv is now the remaining arguments after the options

Usage summary:

    Usage: base [common-options...] [options...]
      A drop in class for `django.core.management.base.BaseCommand`
      which subclasses `cs.cmdutils.BaseCommand`.
      Subcommands:
        help [common-options...] [-l] [-s] [subcommand-names...]
          Print help for subcommands.
          This outputs the full help for the named subcommands,
          or the short help for all subcommands if no names are specified.
          Options:
            -l  Long listing.
            -r  Recurse into subcommands.
            -s  Short listing.
        info [common-options...] [field-names...]
          Recite general information.
          Explicit field names may be provided to override the default listing.
        repl [common-options...]
          Run a REPL (Read Evaluate Print Loop), an interactive Python prompt.
          Options:
            --banner banner  Banner.
        shell [common-options...]
          Run a command prompt via cmd.Cmd using this command's subcommands.

*`BaseCommand.Options`*

*`BaseCommand.SubCommandClass`*

*`BaseCommand.add_arguments(self, parser)`*:
Add the `Options.COMMON_OPT_SPECS` to the `argparse` parser.
This is basicly to support the Django `call_command` function.

*`BaseCommand.handle(*, argv, **options)`*:
The Django `BaseComand.handle` method.
This creates another instance for `argv` and runs it.

*`BaseCommand.run_from_argv(argv)`*:
Intercept `django.core.management.base.BaseCommand.run_from_argv`.
Construct an instance of `cs.djutils.DjangoBaseCommand` and run it.

## <a name="DjangoSpecificSubCommand"></a>Class `DjangoSpecificSubCommand(cs.cmdutils.SubCommand)`

A subclass of `cs.cmdutils.SubCOmmand` with additional support
for Django's `BaseCommand`.

*`DjangoSpecificSubCommand.__call__(self, argv: List[str])`*:
Run this `SubCommand` with `argv`.
This calls Django's `BaseCommand.run_from_argv` for pure Django commands.

*`DjangoSpecificSubCommand.is_pure_django_command`*:
Whether this subcommand is a pure Django `BaseCommand`.

*`DjangoSpecificSubCommand.usage_text(self, *, cmd=None, **kw)`*:
Return the usage text for this subcommand.

# Release Log



*Release 20241222.3*:
Autocall settings.configure() if required because Django's settings object is a royal PITA.

*Release 20241222.2*:
BaseCommand.Options.settings: call settings.configure() on init if that has not already been done.

*Release 20241222.1*:
Placate the dataclass - upgrade BaseCommand.Options.settings to be a field() with a default_factory.

*Release 20241222*:
BaseCommand.Options: include .settings with the public django.conf.settings names, mostly for cmd_info and cmd_repl.

*Release 20241119*:
New DjangoSpecificSubCommand(CSBaseCommand.SubCommandClass) to include support for pure Django BaseCommands.

*Release 20241111*:
Rename DjangoBaseCommand to just BaseCommand so that we go `from cs.djutils import BaseCommand`. Less confusing.

*Release 20241110*:
Initial PyPI release with DjangoBaseCommand, cs.cmdutils.BaseCommand subclass suppplanting django.core.management.base.BaseCommand.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "cs-djutils",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "python3",
    "author": null,
    "author_email": "Cameron Simpson <cs@cskk.id.au>",
    "download_url": "https://files.pythonhosted.org/packages/8d/ad/f7a91d3f2021dd27cde4a2dff288635b5b20f7c930cdc27267a8a65e156f/cs_djutils-20241222.3.tar.gz",
    "platform": null,
    "description": "My collection of things for working with Django.\n\n*Latest release 20241222.3*:\nAutocall settings.configure() if required because Django's settings object is a royal PITA.\n\n## <a name=\"BaseCommand\"></a>Class `BaseCommand(cs.cmdutils.BaseCommand, django.core.management.base.BaseCommand)`\n\nA drop in class for `django.core.management.base.BaseCommand`\nwhich subclasses `cs.cmdutils.BaseCommand`.\n\nThis lets me write management commands more easily, particularly\nif there are subcommands.\n\nThis is a drop in in the sense that you still make a management command\nin nearly the same way:\n\n    from cs.djutils import BaseCommand\n\n    class Command(BaseCommand):\n\nand `manage.py` will find it and run it as normal.\nBut from that point on the style is as for `cs.cmdutils.BaseCommand`:\n- no `aegparse` setup\n- direct support for subcommands as methods\n- succinct option parsing, if you want command line options\n\nA simple command looks like this:\n\n    class Command(BaseCommand):\n\n        def main(self, argv):\n            ... do stuff based on the CLI args `argv` ...\n\nA command with subcommands looks like this:\n\n    class Command(BaseCommand):\n\n        def cmd_this(self, argv):\n            ... do the \"this\" subcommand ...\n\n        def cmd_that(self, argv):\n            ... do the \"that\" subcommand ...\n\nIf want some kind of app/client specific \"overcommand\" composed\nfrom other management commands you can import them and make\nthem subcommands of the overcommand:\n\n    from .other_command import Command as OtherCommand\n\n    class Command(BaseCommand):\n\n        # provide it as the \"other\" subcommand\n        cmd_other = OtherCommand\n\nOption parsing is inline in the command. `self` comes\npresupplied with a `.options` attribute which is an instance\nof `cs.cmdutils.BaseCommandOptions` (or some subclass).\n\nParsing options is simple:\n\n    class Command(BaseCommand):\n\n        def cmd_this(self, argv):\n            options = self.options\n            # parsing options:\n            #\n            # boolean -x option, makes options.x\n            #\n            # --thing-limit n option taking an int\n            # makes options.thing_limit\n            # help text is \"Thing limit.\"\n            #\n            # a --mode foo option taking a string\n            # makes options.mode\n            # help text is \"The run mode.\"\n            options.popopts(\n                argv,\n                x=None,\n                thing_limit_=int,\n                mode_='The run mode.',\n            )\n            ... now consult options.x or whatever\n            ... argv is now the remaining arguments after the options\n\nUsage summary:\n\n    Usage: base [common-options...] [options...]\n      A drop in class for `django.core.management.base.BaseCommand`\n      which subclasses `cs.cmdutils.BaseCommand`.\n      Subcommands:\n        help [common-options...] [-l] [-s] [subcommand-names...]\n          Print help for subcommands.\n          This outputs the full help for the named subcommands,\n          or the short help for all subcommands if no names are specified.\n          Options:\n            -l  Long listing.\n            -r  Recurse into subcommands.\n            -s  Short listing.\n        info [common-options...] [field-names...]\n          Recite general information.\n          Explicit field names may be provided to override the default listing.\n        repl [common-options...]\n          Run a REPL (Read Evaluate Print Loop), an interactive Python prompt.\n          Options:\n            --banner banner  Banner.\n        shell [common-options...]\n          Run a command prompt via cmd.Cmd using this command's subcommands.\n\n*`BaseCommand.Options`*\n\n*`BaseCommand.SubCommandClass`*\n\n*`BaseCommand.add_arguments(self, parser)`*:\nAdd the `Options.COMMON_OPT_SPECS` to the `argparse` parser.\nThis is basicly to support the Django `call_command` function.\n\n*`BaseCommand.handle(*, argv, **options)`*:\nThe Django `BaseComand.handle` method.\nThis creates another instance for `argv` and runs it.\n\n*`BaseCommand.run_from_argv(argv)`*:\nIntercept `django.core.management.base.BaseCommand.run_from_argv`.\nConstruct an instance of `cs.djutils.DjangoBaseCommand` and run it.\n\n## <a name=\"DjangoSpecificSubCommand\"></a>Class `DjangoSpecificSubCommand(cs.cmdutils.SubCommand)`\n\nA subclass of `cs.cmdutils.SubCOmmand` with additional support\nfor Django's `BaseCommand`.\n\n*`DjangoSpecificSubCommand.__call__(self, argv: List[str])`*:\nRun this `SubCommand` with `argv`.\nThis calls Django's `BaseCommand.run_from_argv` for pure Django commands.\n\n*`DjangoSpecificSubCommand.is_pure_django_command`*:\nWhether this subcommand is a pure Django `BaseCommand`.\n\n*`DjangoSpecificSubCommand.usage_text(self, *, cmd=None, **kw)`*:\nReturn the usage text for this subcommand.\n\n# Release Log\n\n\n\n*Release 20241222.3*:\nAutocall settings.configure() if required because Django's settings object is a royal PITA.\n\n*Release 20241222.2*:\nBaseCommand.Options.settings: call settings.configure() on init if that has not already been done.\n\n*Release 20241222.1*:\nPlacate the dataclass - upgrade BaseCommand.Options.settings to be a field() with a default_factory.\n\n*Release 20241222*:\nBaseCommand.Options: include .settings with the public django.conf.settings names, mostly for cmd_info and cmd_repl.\n\n*Release 20241119*:\nNew DjangoSpecificSubCommand(CSBaseCommand.SubCommandClass) to include support for pure Django BaseCommands.\n\n*Release 20241111*:\nRename DjangoBaseCommand to just BaseCommand so that we go `from cs.djutils import BaseCommand`. Less confusing.\n\n*Release 20241110*:\nInitial PyPI release with DjangoBaseCommand, cs.cmdutils.BaseCommand subclass suppplanting django.core.management.base.BaseCommand.\n",
    "bugtrack_url": null,
    "license": "GNU General Public License v3 or later (GPLv3+)",
    "summary": "My collection of things for working with Django.",
    "version": "20241222.3",
    "project_urls": {
        "MonoRepo Commits": "https://bitbucket.org/cameron_simpson/css/commits/branch/main",
        "Monorepo Git Mirror": "https://github.com/cameron-simpson/css",
        "Monorepo Hg/Mercurial Mirror": "https://hg.sr.ht/~cameron-simpson/css",
        "Source": "https://github.com/cameron-simpson/css/blob/main/lib/python/cs/djutils.py"
    },
    "split_keywords": [
        "python3"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b87e2af3a80970e832d5b7f278302ce2d1a6a5b75dcbe7e2dc023cd66f1d38f6",
                "md5": "0d4d4d5cbf0089539a5564c10fb808e1",
                "sha256": "97a597c52d4c2aaa7d2973ec8f9bc321d801fb9e8fd034fe78c358a5ad1e409b"
            },
            "downloads": -1,
            "filename": "cs_djutils-20241222.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0d4d4d5cbf0089539a5564c10fb808e1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 5838,
            "upload_time": "2024-12-21T22:03:45",
            "upload_time_iso_8601": "2024-12-21T22:03:45.514635Z",
            "url": "https://files.pythonhosted.org/packages/b8/7e/2af3a80970e832d5b7f278302ce2d1a6a5b75dcbe7e2dc023cd66f1d38f6/cs_djutils-20241222.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8dadf7a91d3f2021dd27cde4a2dff288635b5b20f7c930cdc27267a8a65e156f",
                "md5": "5c79063ad9b9772a2fdff14371aba3fa",
                "sha256": "78a2c7f6eea4278e52c288259edc647fc26744d8cc0ee070f2d44a03708432f7"
            },
            "downloads": -1,
            "filename": "cs_djutils-20241222.3.tar.gz",
            "has_sig": false,
            "md5_digest": "5c79063ad9b9772a2fdff14371aba3fa",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 5462,
            "upload_time": "2024-12-21T22:03:48",
            "upload_time_iso_8601": "2024-12-21T22:03:48.124544Z",
            "url": "https://files.pythonhosted.org/packages/8d/ad/f7a91d3f2021dd27cde4a2dff288635b5b20f7c930cdc27267a8a65e156f/cs_djutils-20241222.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-21 22:03:48",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "cameron-simpson",
    "github_project": "css",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "cs-djutils"
}
        
Elapsed time: 0.39333s