If all my __init__.py
files are empty, do I have to store them into version control, or is there a way to make distutils create empty __init__.py
files during installation?
views:
446answers:
2In Python, __init__.py
files actually have a meaning! They mean that the folder they are in is a Python module. As such, they have a real role in your code and should most probably be stored in Version Control.
You could well imagine a folder in your source tree that is NOT a Python module, for example a folder containing only resources (e.g. images) and no code. That folder would not need to have a __init__.py
file in it. Now how do you make the difference between folders where distutils should create those files and folders where it should not ?
Is there a reason you want to avoid putting empty __init__.py
files in version control? If you do this you won't be able to import
your packages from the source directory wihout first running distutils.
If you really want to, I suppose you can create __init__.py
in setup.py
. It has to be before running distutils.setup
, so setup
itself is able to find your packages:
from distutils import setup
import os
for path in [my_package_directories]:
filename = os.path.join(pagh, '__init__.py')
if not os.path.exists(filename):
init = open(filename, 'w')
init.close()
setup(
...
)
but... what would you gain from this, compared to having the empty __init__.py
files there in the first place?