From 8eba627b29fb97e1449480b0c994e4230d16ba0e Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Tue, 30 Jan 2024 23:55:18 +0100 Subject: [PATCH] scripts: make.py clean implementation --- Vagrantfile | 2 +- scripts/make.py | 40 ++++++++++++++++++++++++++++++++++++++++ setup.py | 33 +++------------------------------ 3 files changed, 44 insertions(+), 31 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index f4fbc0e1..6173298c 100644 --- a/Vagrantfile +++ b/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 diff --git a/scripts/make.py b/scripts/make.py index 7bb3ce14..a5d197eb 100644 --- a/scripts/make.py +++ b/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": diff --git a/setup.py b/setup.py index 453b7fbf..e640f535 100644 --- a/setup.py +++ b/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:] )