Why does “python setup.py sdist” create unwanted “PROJECT-egg.info” in project root directory?

This directory is created intentionally as part of the build process for a source distribution. A little gander at the developer guide for setuptools gives you a hint as to why:

But, be sure to ignore any part of the
distutils documentation that deals
with MANIFEST or how it’s generated
from MANIFEST.in; setuptools shields
you from these issues and doesn’t work
the same way in any case. Unlike the
distutils, setuptools regenerates the
source distribution manifest file
every time you build a source
distribution, and it builds it inside
the project’s .egg-info directory, out
of the way of your main project
directory. You therefore need not
worry about whether it is up-to-date
or not.

You may safely delete the directory after your build has completed.

Bonus edit:

I customize the clean command within my setup.py on many of my Python projects to delete *.egg-info, dist, build, and *.pyc and other files. Here’s an example of how it’s done in setup.py:

import os
from setuptools import setup, Command

class CleanCommand(Command):
    """Custom clean command to tidy up the project root."""
    user_options = []
    def initialize_options(self):
        pass
    def finalize_options(self):
        pass
    def run(self):
        os.system('rm -vrf ./build ./dist ./*.pyc ./*.tgz ./*.egg-info')

# Further down when you call setup()
setup(
    # ... Other setup options
    cmdclass={
        'clean': CleanCommand,
    }
)

To illustrate, after running python setup.py build on a dummy project called “poop” (Yes, I’m very mature), this happens:

$ python setup.py build
running build
running build_py
creating build
creating build/lib
creating build/lib/poop
copying poop/__init__.py -> build/lib/poop

And now if we run python setup.py clean:

$ python setup.py clean
running clean
removed `./build/lib/poop/__init__.py'
removed directory: `./build/lib/poop'
removed directory: `./build/lib'
removed directory: `./build'

Tada!

Leave a Comment