Alex
Alex

Reputation: 44345

What does "setup.py clean" exactly do?

Invoking a call to setup from setuptools with version 0.9.6 I can run the following command:

python setup.py clean

But what does this exactly do? The help on this command is a bit sparse, and running

python setup.py clean --all

gives useless statements like

'build/lib.linux-i686-2.7' does not exist -- can't clean it

Is there a possibility to use this clean command to e.g. cleanup automatically temporary python files ending in .pyc and .~? Can this be done with this command, does it need to be configured, ...?

Upvotes: 12

Views: 12012

Answers (1)

user707650
user707650

Reputation:

As far as I know, it just removes the the build subdirectory, where Python puts all the files to be installed, including extensions that need to be compiled.

There shouldn't be any *.pyc files elsewhere, unless you ran Python on some scripts in the source directory (which may happen if you run tests), or imported modules directly from the source directory. *~ files are emacs backup files, and thus wouldn't be cleaned up by setup.py anyway. (If you've seen this behaviour from make clean, than that's simply because someone coded that into the Makefile.)

You probably could override the clean command in a way to (recursively) remove *.pyc files, but I doubt if there's a need. In general, Python is smart enough to recompile *.py files into *.pyc files if the former have changed, and otherwise using the latter will simply be faster.

There is one caveat I've come across, and that is when doing a setup.py build_ext --inplace, cleaning won't remove the compiled module(s), since these are not in the build directory. Which to me feels like shortcoming of the clean command.

Overall, it looks like the clean command was added to be in line with make's behaviour, but it doesn't seem to add much.

Upvotes: 8

Related Questions