scripts: make.py clean implementation

This commit is contained in:
Thomas Waldmann 2024-01-30 23:55:18 +01:00
parent 8bf7ad575a
commit ef2728a6a6
No known key found for this signature in database
GPG Key ID: 243ACFA951F78E01
3 changed files with 43 additions and 31 deletions

2
Vagrantfile vendored
View File

@ -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

View File

@ -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":

View File

@ -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(