Skip to main content

Making setup.py 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 setup.py clean is useful for developers of C extensions or anything else that takes advantage of the setup.py 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 setup.py 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.

Installation

The setuptools package contains a number of interesting ways in which it can be extended. The simplest way to use this extension is to install it into the environment and use it. The package extends the clean command by installing a distutils extension:

$ pip install -q 'setupext-janitor'
$ ./setup.py clean --dist --eggs
running clean
removing './my_package.egg-info' (and everything under it)
removing 'dist' (and everything under it)

You can also install the command from within your setup.py 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_janitor package needs to be imported into setup.py 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
try:
   from setupext_janitor import janitor
   CleanCommand = janitor.CleanCommand
except ImportError:
   CleanCommand = None

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

setup(
   # normal parameters
   setup_requires=['setupext_janitor'],
   cmdclass=cmd_classes,
   entry_points={
      # normal parameters, ie. console_scripts[]
      'distutils.commands': [
         ' clean = setupext_janitor.janitor:CleanCommand']
      }
)

This approach is not recommended since the install_requires keyword will install setupext_janitor into a target environment when installing your package from a source distribution. Not to mention that amount of gynmastics required to safely use it from within setup.py,

Usage

Once the extension is installed, the clean command will accept a few new command line parameters.

setup.py clean --build

Removes directories that various build commands produce.

setup.py clean --dist

Removes directories that the various dist commands produce.

setup.py clean --eggs

Removes .egg and .egg-info directories.

setup.py 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.

setup.py clean --pycache

Recursively removes directories named __pycache__.

setup.py clean --all

Remove all of by-products. This is the same as using --dist --egg --environment --pycache.

Where can I get this extension from?

Source

https://github.com/dave-shawley/setupext-janitor

Status

https://travis-ci.org/dave-shawley/setupext-janitor

Download

https://pypi.org/project/setupext-janitor

Documentation

http://setupext-janitor.readthedocs.io/en/latest

Issues

https://github.com/dave-shawley/setupext-janitor

Project details


Download files

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

Source Distribution

setupext-janitor-1.1.2.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

setupext_janitor-1.1.2-py2.py3-none-any.whl (7.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file setupext-janitor-1.1.2.tar.gz.

File metadata

  • Download URL: setupext-janitor-1.1.2.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/3.7.1

File hashes

Hashes for setupext-janitor-1.1.2.tar.gz
Algorithm Hash digest
SHA256 4bdb0c1c71b541b44edb7f9eb4949694d570cafdf8e5939d1b532a070c70414c
MD5 fe785c543fd645fadbac970f00bfa989
BLAKE2b-256 8ff7e1ebdeffa20d4bce591a79a7d9fa0feaf73c585a55dd97737f1fbefe9d34

See more details on using hashes here.

File details

Details for the file setupext_janitor-1.1.2-py2.py3-none-any.whl.

File metadata

  • Download URL: setupext_janitor-1.1.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/3.7.1

File hashes

Hashes for setupext_janitor-1.1.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 9cb4b72323c58b5a691d7bbb5b44079b0171c32297634b43b3ec21452bfa68ef
MD5 10c77f9108c0f0dec4efe459ef1f0571
BLAKE2b-256 fe7c21ab50164321e657d7ca281bc827b317351b0504dca72025b1e8063d4b91

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page