Skip to content

Instantly share code, notes, and snippets.

@bartekbrak
Created November 14, 2015 15:18
Show Gist options
  • Save bartekbrak/42d59fd43a9af14a0cc5 to your computer and use it in GitHub Desktop.
Save bartekbrak/42d59fd43a9af14a0cc5 to your computer and use it in GitHub Desktop.
# pseudo django project, the bare minimum
$ tree
.
├── manage.py
├── settings.py
├── setup.py
└── urls.py
# mae this a package
$ cat setup.py
from setuptools import setup
setup(
name='blossom',
version='1',
py_modules=['settings', 'urls']
)
# Install it, editable mode allows you to modify the code without reinstalling
$ pip install -e .
# Oh look, egg-info is there, it got installed
$ tree .
.
├── blossom.egg-info
│   ├── dependency_links.txt
│   ├── PKG-INFO
│   ├── SOURCES.txt
│   └── top_level.txt
├── manage.py
├── settings.py
├── setup.py
└── urls.py
# Let's see if sys.path got our new package
$ python -c 'import sys; print([_ for _ in sys.path if _.endswith("blossom")])'
['/home/bartek/workspace/blossom']
# Does importing settings work?
$ python -c 'import settings; print settings'
<module 'settings' from 'settings.pyc'>
# It does, because we were in the same dir, but will it work from another dir?
$ cd subdir
$ python -c 'import settings; print settings'
<module 'settings' from '/home/bartek/workspace/blossom/settings.pyc'>
# That's what we wanted!
$ export DJANGO_SETTINGS_MODULE='settings'
$ django-admin some_sub_command #
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment