Parcourir la source

scripts: make.py clean implementation

Thomas Waldmann il y a 1 an
Parent
commit
8eba627b29
3 fichiers modifiés avec 44 ajouts et 31 suppressions
  1. 1 1
      Vagrantfile
  2. 40 0
      scripts/make.py
  3. 3 30
      setup.py

+ 1 - 1
Vagrantfile

@@ -200,7 +200,7 @@ def install_borg(fuse)
     pip install -U wheel  # upgrade wheel, might be too old
     cd borg
     pip install -r requirements.d/development.lock.txt
-    python setup.py clean clean2
+    python3 scripts/make.py clean
     pip install -e .[#{fuse}]
   EOF
 end

+ 40 - 0
scripts/make.py

@@ -1,5 +1,6 @@
 # Support code for building docs (build_usage, build_man)
 
+import glob
 import os
 import io
 import re
@@ -530,11 +531,48 @@ class BuildMan:
             write(option.ljust(padding), desc)
 
 
+cython_sources = """
+src/borg/compress.pyx
+src/borg/crypto/low_level.pyx
+src/borg/chunker.pyx
+src/borg/hashindex.pyx
+src/borg/item.pyx
+src/borg/checksums.pyx
+src/borg/platform/posix.pyx
+src/borg/platform/linux.pyx
+src/borg/platform/syncfilerange.pyx
+src/borg/platform/darwin.pyx
+src/borg/platform/freebsd.pyx
+src/borg/platform/windows.pyx
+""".strip().splitlines()
+
+
+def rm(file):
+    try:
+        os.unlink(file)
+    except FileNotFoundError:
+        return False
+    else:
+        return True
+
+
+class Clean:
+    def run(self):
+        for source in cython_sources:
+            genc = source.replace(".pyx", ".c")
+            rm(genc)
+            compiled_glob = source.replace(".pyx", ".cpython*")
+            for compiled in sorted(glob.glob(compiled_glob)):
+                rm(compiled)
+        return 0
+
+
 def usage():
     print(
         textwrap.dedent(
             """
         Usage:
+            python scripts/make.py clean        # clean workdir (remove generated files)
             python scripts/make.py build_usage  # build usage documentation
             python scripts/make.py build_man    # build man pages
     """
@@ -547,6 +585,8 @@ def main(argv):
         usage()
         return 0
     command = argv[1]
+    if command == "clean":
+        return Clean().run()
     if command == "build_usage":
         return BuildUsage().run()
     if command == "build_man":

+ 3 - 30
setup.py

@@ -4,7 +4,6 @@ import os
 import re
 import sys
 from collections import defaultdict
-from glob import glob
 
 try:
     import multiprocessing
@@ -12,7 +11,7 @@ except ImportError:
     multiprocessing = None
 
 from setuptools.command.build_ext import build_ext
-from setuptools import setup, Extension, Command
+from setuptools import setup, Extension
 from setuptools.command.sdist import sdist
 
 try:
@@ -84,33 +83,7 @@ else:
         raise ImportError("The GIT version of Borg needs Cython. Install Cython or use a released version.")
 
 
-def rm(file):
-    try:
-        os.unlink(file)
-        print("rm", file)
-    except FileNotFoundError:
-        pass
-
-
-class Clean(Command):
-    user_options = []
-
-    def initialize_options(self):
-        pass
-
-    def finalize_options(self):
-        pass
-
-    def run(self):
-        for source in cython_sources:
-            genc = source.replace(".pyx", ".c")
-            rm(genc)
-            compiled_glob = source.replace(".pyx", ".cpython*")
-            for compiled in sorted(glob(compiled_glob)):
-                rm(compiled)
-
-
-cmdclass = {"build_ext": build_ext, "sdist": Sdist, "clean2": Clean}
+cmdclass = {"build_ext": build_ext, "sdist": Sdist}
 
 
 ext_modules = []
@@ -228,7 +201,7 @@ if not on_rtd:
     # this breaks chained commands like 'clean sdist'
     cythonizing = (
         len(sys.argv) > 1
-        and sys.argv[1] not in (("clean", "clean2", "egg_info", "--help-commands", "--version"))
+        and sys.argv[1] not in (("clean", "egg_info", "--help-commands", "--version"))
         and "--help" not in sys.argv[1:]
     )