2009-10-20 39 views

回答

6

對於預刪除,只調用安裝之前distutils.dir_util.remove_tree刪除。

對於後刪除,我假設你只想在選定的命令後進行後刪除。對各個命令進行子類化,覆蓋其運行方法(在調用基本運行後調用remove_tree),並將新命令傳遞到安裝程序的cmdclass字典中。

73

請問this回答嗎? IIRC,你需要使用--all標誌得到的build/lib外擺脫的東西:

python setup.py clean --all 
+0

似乎並非所有'setup.py'腳本都支持'clean'。例如:NumPy – kevinarpe 2016-06-15 07:14:11

3

這裏是一個融合了馬丁的回答的編程方法與馬特的答案的功能的答案(一clean是負責所有可能的堆積區):

from distutils.core import setup 
from distutils.command.clean import clean 
from distutils.command.install import install 

class MyInstall(install): 

    # Calls the default run command, then deletes the build area 
    # (equivalent to "setup clean --all"). 
    def run(self): 
     install.run(self) 
     c = clean(self.distribution) 
     c.all = True 
     c.finalize_options() 
     c.run() 

if __name__ == '__main__': 

    setup(
     name="myname", 
     ... 
     cmdclass={'install': MyInstall} 
    ) 
2

這將清除安裝

之前構建目錄
python setup.py clean --all install 

但根據您的要求:這會前做,之後

python setup.py clean --all install clean --all