Skip to main content
Help us improve PyPI by participating in user testing. All experience levels needed!

Making clean more useful.

Project description

Version Downloads Status License

Extends the clean command to remove stuff generated by the development process.

Wait… Why? What??

So clean is useful for developers of C extensions or anything else that takes advantage of the build command. Pure Python packages generate their own set of artifacts that clutter up the source tree. This package extends the clean command so that it removes the following artifacts as well:

  • The distribution directory as generated by the sdist and bdist* commands
  • Top-level .egg-info and .egg directories that creates
  • Local virtual environment directories
  • __pycache__ directories

I come from a C/C++ background where the Makefile usually provide house keeping targets such as clean, dist-clean, and maintainer-clean. This extension is inspired by the same desire for a clean working environment.


The setuptools package contains a number of interesting ways in which it can be extended. If you develop Python packages, then you can include extension packages using the setup_requires and cmdclass keyword parameters to the setup function call. This is a little more difficult than it should be since the setupext package needs to be imported into so that it can be passed as a keyword parameter before it is downloaded. The easiest way to do this is to catch the ImportError that happens if it is not already downloaded:

import setuptools
   from setupext import janitor
   CleanCommand = janitor.CleanCommand
except ImportError:
   CleanCommand = None

cmd_classes = {}
if CleanCommand is not None:
   cmd_classes['clean'] = CleanCommand

   # normal parameters

You can use a different approach if you are simply a developer that wants to have this functionality available for your own use, then you can install it into your working environment. This package installs itself into the environment as a distutils extension so that it is available to any script as if by magic.


Once the extension is installed, the clean command will accept a few new command line parameters. clean --dist
Removes directories that the various dist commands produce. clean --egg
Removes .egg and .egg-info directories. clean --environment
Removes the currently active virtual environment as indicated by the $VIRTUAL_ENV environment variable. The name of the directory can also be specified using the --virtualenv-dir command line option. clean --pycache
Recursively removes directories named __pycache__. clean --all
Remove all of by-products. This is the same as using --dist --egg --environment --pycache.

Project details

Release history Release notifications

This version
History Node


History Node


History Node


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
setupext_janitor-1.0.0-py2.py3-none-any.whl (8.5 kB) Copy SHA256 hash SHA256 Wheel 3.4 Nov 20, 2014
setupext-janitor-1.0.0.tar.gz (9.9 kB) Copy SHA256 hash SHA256 Source None Nov 20, 2014

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page