简体   繁体   English

“setup.py clean”究竟做了什么?

[英]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: 从版本0.9.6的setuptools调用setup进行调用我可以运行以下命令:

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 eg cleanup automatically temporary python files ending in .pyc and .~ ? 是否有可能使用这个clean命令来自动清理以.pyc.~结尾的临时python文件.~ Can this be done with this command, does it need to be configured, ...? 可以使用此命令完成此操作,是否需要配置,...?

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. 据我所知,它只是删除了build子目录,其中Python放置了所有要安装的文件,包括需要编译的扩展。

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. 除非您在源目录中的某些脚本上运行Python(如果运行测试可能会发生这种情况),或者直接从源目录导入模块,否则其他地方不应该有任何*.pyc文件。 *~ files are emacs backup files, and thus wouldn't be cleaned up by setup.py anyway. *~文件是emacs备份文件,因此无论如何都不会被setup.py清理。 (If you've seen this behaviour from make clean , than that's simply because someone coded that into the Makefile.) (如果你从make clean看到过这种行为,那只是因为有人将其编码到Makefile中。)

You probably could override the clean command in a way to (recursively) remove *.pyc files, but I doubt if there's a need. 您可能会以(递归)删除*.pyc文件的方式覆盖clean命令,但我怀疑是否需要。 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. 在一般情况下,Python是足够聪明的编译*.py文件转换成*.pyc文件,如果前者已经改变,否则使用后者只会更快。

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. 我遇到过一个警告,那就是在执行setup.py build_ext --inplace ,清理不会删除已编译的模块,因为这些模块不在构建目录中。 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. 总的来说,看起来添加了干净的命令以符合make的行为,但它似乎没有增加太多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM