Search code examples
pythonversion-controldistutils

Can distutils create empty __init__.py files?


If all of 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?


Solution

  • 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?