What I mean by an "installable Django package": a reusable component that can be shared across Django projects, allowing us to combine our own efforts with others. Some examples include:
Ever want to quickly create a similarly installable Django package to submit to PyPI and Django Packages? One that goes beyond the basics described in the Django tutorial? Specifically, a package that includes:
django-admin.py startappthat are hard to remember.
Well, here's how I do it.
First, get Cookiecutter. Trust me, it's awesome:
$ pip install cookiecutter
Now run it against this repo:
$ cookiecutter https://github.com/pydanny/cookiecutter-djangopackage.git
You'll be prompted to enter some values. Enter them. Then an installable Django package will be built for you.
app_name must be a valid Python module name or you will
have issues on imports.
Enter the new package (in my case, I called it 'newpackage') and look
around. Open up the
README.rst files and
you'll see your input inserted into the appropriate locations.
newpackage ├── .editorconfig ├── .gitignore ├── .travis.yml ├── AUTHORS.rst ├── CONTRIBUTING.rst ├── HISTORY.rst ├── LICENSE ├── MANIFEST.in ├── Makefile ├── README.rst ├── newpackage │ ├── __init__.py │ ├── models.py │ ├── static │ │ ├── css │ │ │ └── newpackage.css │ │ ├── img │ │ │ └── .gitignore │ │ └── js │ │ └── newpackage.js │ └── templates │ └── cheese │ └── base.html ├── docs │ ├── Makefile │ ├── authors.rst │ ├── conf.py │ ├── contributing.rst │ ├── history.rst │ ├── index.rst │ ├── installation.rst │ ├── make.bat │ ├── readme.rst │ └── usage.rst ├── requirements-test.txt ├── requirements.txt ├── requirements_dev.txt ├── runtests.py ├── setup.cfg ├── setup.py ├── tests │ ├── __init__.py │ └── test_models.py └── tox.ini
Now, instead of monkeying around for awhile doing copy/paste package setup, I'm immediately ready to write code.
cookiecutter-djangopackage does a lot, but even with its tight focus on package creation it could do more. Some of the things I would love to see included in the future:
Try it out and let me know what you think. I'm open to new ideas and receiving pull requests.
Published: 2015-11-20 18:30
Content Copyright © 2012-2018 Daniel Greenfeld. Proudly harnessed by Mountain, powered by Flask, and rendered by Frozen Flask, all of which take great advantage of Python.