Skip to main content

Helper to develop Django projects.

Project description

manage_django_project

tests codecov manage_django_project @ PyPi Python Versions License GPL-3.0-or-later

Helper to develop Django projects:

  • Easy bootstrap a virtual environment:
    • Just get the sources and call ./manage.py
    • Only python3-pip and python3-venv package needed to bootstarp
  • Alle Django manage commands useable as normal CLI and via cmd2 shell
  • cmd2 shell with autocomplete of all existing manage commands and all options
  • Auto switching Django settings between local and tests settings.
  • Helpful manage commands for developing:

Included Django management commands:

  • code_style - Check/Fix project code style
  • coverage - Run tests with coverage and report
  • install - Just install the project as editable via pip (Useful if version has been changed)
  • project_info - Information about the current Django project
  • publish - Build a new release and publish it to PyPi
  • run_dev_server - Setup test project and run django developer server
  • safety - Run safety check against current requirements files
  • shell - Go into cmd2 shell with all registered Django manage commands
  • tox - Run tests via tox
  • update_req - Update project requirements via pip-tools

How to use it

Some steps are needed to use manage_django_project in your project.

Here a overview and below details:

  • add manage_django_project to your dev dependencies
  • You Django project should have separate settings for prod, local and tests (Last two ones are used by manage_django_project)
  • Add the bootstrap manage.py
  • Add a __main__.py with a ManageConfig and the execute_django_from_command_line() call.
  • Add the __main__-file as [project.scripts]
  • Add the name of your [project.scripts] into bootstrap manage.py

All examples below used manage_django_project_example. You have to rename this string/path to your Django package name.

Full example is here: https://github.com/jedie/manage_django_project/tree/main/manage_django_project_example

If everything works as expected you can just call the ./manage.py file and the magic happens ;)

main.py

Add a .../manage_django_project_example/__main__.py file, looks like:

from pathlib import Path

import manage_django_project_example
from manage_django_project.config import ManageConfig
from manage_django_project.manage import execute_django_from_command_line


def main():
    """
    entrypoint installed via pyproject.toml and [project.scripts] section.
    Must be set in ./manage.py and PROJECT_SHELL_SCRIPT
    """
    execute_django_from_command_line(
        config=ManageConfig(
            module=manage_django_project_example,
            #
            # Path that contains your `pyproject.toml`:
            project_root_path=Path(manage_django_project_example.__file__).parent.parent,
            #
            # Django settings used for all commands except test/coverage/tox:
            local_settings='manage_django_project_example.settings.local',
            #
            # Django settings used for test/coverage/tox commands:
            test_settings='manage_django_project_example.settings.tests',
        )
    )


if __name__ == '__main__':
    main()

pyproject.toml

[project.scripts]
manage_django_project_example = "manage_django_project_example.__main__:main"

./manage.py

Add a copy of manage.py file to your project source root.

Change only manage_django_project_example in this line:

PROJECT_SHELL_SCRIPT = BIN_PATH / 'manage_django_project_example'

Start hacking

Just clone the project and start ./manage.py to bootstrap a virtual environment:

# Install base requirements:
~$ sudo apt install python3-pip python3-venv

# Get the sources:
~$ git clone https://github.com/jedie/manage_django_project.git
~$ cd manage_django_project/

# Just call manage.py and the magic happen:
~/manage_django_project$ ./manage.py

# start local dev. web server:
~/django-for-runners$ ./manage.py run_dev_server

# run tests:
~/django-for-runners$ ./manage.py test
# or with coverage
~/django-for-runners$ ./manage.py coverage
# or via tox:
~/django-for-runners$ ./manage.py tox

history

  • dev
    • TBC
  • v0.2.1 - 16.03.2023
    • Add more tests
    • Enhance README
    • Code cleanup
  • v0.2.0 - 14.03.2023
    • Add a optional shell via cmd2
  • v0.1.1 - 13.03.2023
    • Add ProjectInfo.distribution_name and set if from pyproject.toml
    • publish command: Use distribution_name in publish call
    • publish command: Display used settings for publish_package()
  • v0.1.0 - 12.03.2023
    • publish command: Bugfix test run before publishing: use the "test" settings
    • coverage command: Remove a existing .coverage before create a new one
  • v0.0.1 - 12.03.2023
    • Init first version

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

manage_django_project-0.2.1.tar.gz (32.0 kB view details)

Uploaded Source

Built Distribution

manage_django_project-0.2.1-py3-none-any.whl (44.6 kB view details)

Uploaded Python 3

File details

Details for the file manage_django_project-0.2.1.tar.gz.

File metadata

  • Download URL: manage_django_project-0.2.1.tar.gz
  • Upload date:
  • Size: 32.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for manage_django_project-0.2.1.tar.gz
Algorithm Hash digest
SHA256 2aa8727f2321b4cde8c2162403d084fbfc98208767dfd4b4e5a33fcf2024c574
MD5 f7d5de12d8bff89bd44a322008587c83
BLAKE2b-256 ae12038bb9bbb46a6ba5545cfcc284a9dbd691a075250a72b96e9a194db8d819

See more details on using hashes here.

File details

Details for the file manage_django_project-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for manage_django_project-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 eb1a87659f7f5e59b82615dad81d4797deb1a2247c702e978bbffd4882591e0c
MD5 ac9b4ff33afe143b7b86ea575d641b48
BLAKE2b-256 cc22ca213adea25f6dd716a5c925a3473f0bfb4789bc3f805a6e778a26d3a78a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page