From ef2728a6a61aeb3dce671e0484067e4184a9ab2a 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 | 32 ++------------------------------ 3 files changed, 43 insertions(+), 31 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index 8b31b316..b022d964 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -194,7 +194,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 57bfe640..c90e1bec 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 @@ -518,9 +519,46 @@ 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/algorithms/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 """)) @@ -531,6 +569,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 697f0fea..ed940885 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: @@ -113,36 +112,9 @@ 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, } ext_modules = [] @@ -213,7 +185,7 @@ if not on_rtd: # sometimes there's no need to cythonize # 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 '--help' not in sys.argv[1:] + ('clean', 'egg_info', '--help-commands', '--version')) and '--help' not in sys.argv[1:] if cythonize and cythonizing: cython_opts = dict(