瀏覽代碼

setup.py clean to remove compiled files

Marian Beermann 8 年之前
父節點
當前提交
0a295dd753
共有 1 個文件被更改,包括 21 次插入1 次删除
  1. 21 1
      setup.py

+ 21 - 1
setup.py

@@ -48,6 +48,7 @@ if sys.platform.startswith('freebsd'):
 
 from setuptools import setup, find_packages, Extension
 from setuptools.command.sdist import sdist
+from distutils.command.clean import clean
 
 compress_source = 'src/borg/compress.pyx'
 crypto_ll_source = 'src/borg/crypto/low_level.pyx'
@@ -567,11 +568,30 @@ class build_man(Command):
             write(option.ljust(padding), desc)
 
 
+class Clean(clean):
+    def run(self):
+        super().run()
+        for source in cython_sources:
+            genc = source.replace('.pyx', '.c')
+            try:
+                os.unlink(genc)
+                print('rm', genc)
+            except FileNotFoundError:
+                pass
+            compiled_glob = source.replace('.pyx', '.cpython*')
+            for compiled in glob(compiled_glob):
+                try:
+                    os.unlink(compiled)
+                    print('rm', compiled)
+                except FileNotFoundError:
+                    pass
+
 cmdclass = {
     'build_ext': build_ext,
     'build_usage': build_usage,
     'build_man': build_man,
-    'sdist': Sdist
+    'sdist': Sdist,
+    'clean': Clean,
 }
 
 ext_modules = []