Skip to content

Commit

Permalink
Merge pull request #8069 from ThomasWaldmann/less-setuppy2-1.4
Browse files Browse the repository at this point in the history
Use less setup.py, continued (1.4-maint)
  • Loading branch information
ThomasWaldmann committed Jan 31, 2024
2 parents 376ad6d + ef2728a commit ad44430
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 38 deletions.
2 changes: 1 addition & 1 deletion Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions docs/development.rst
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ for easier use by packagers downstream.
When a command is added, a command line flag changed, added or removed,
the usage docs need to be rebuilt as well::

python scripts/gendocs.py build_usage
python scripts/gendocs.py build_man
python scripts/make.py build_usage
python scripts/make.py build_man

However, we prefer to do this as part of our :ref:`releasing`
preparations, so it is generally not necessary to update these when
Expand Down Expand Up @@ -313,8 +313,8 @@ Checklist:
- Verify that ``MANIFEST.in``, ``pyproject.toml`` and ``setup.py`` are complete.
- Run these commands and commit::

python scripts/gendocs.py build_usage
python scripts/gendocs.py build_man
python scripts/make.py build_usage
python scripts/make.py build_man

- Tag the release::

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
# ruff failures that appear with your change.
[tool.ruff.per-file-ignores]
"setup.py" = ["E501"]
"scripts/gendocs.py" = ["E501"]
"scripts/make.py" = ["E501"]
"src/borg/archive.py" = ["E501", "F401"]
"src/borg/archiver.py" = ["E501", "F401", "E722", "E741"]
"src/borg/cache.py" = ["E501", "E722"]
Expand Down
44 changes: 42 additions & 2 deletions scripts/gendocs.py → scripts/make.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Support code for building docs (build_usage, build_man)

import glob
import os
import io
import re
Expand Down Expand Up @@ -518,11 +519,48 @@ def is_positional_group(group):
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/gendocs.py build_usage # build usage documentation
python scripts/gendocs.py build_man # build man pages
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
"""))


Expand All @@ -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":
Expand Down
32 changes: 2 additions & 30 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
import re
import sys
from collections import defaultdict
from glob import glob

try:
import multiprocessing
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:
Expand Down Expand Up @@ -113,36 +112,9 @@ def __init__(self, *args, **kwargs):
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 = []
Expand Down Expand Up @@ -213,7 +185,7 @@ def members_appended(*ds):
# 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(
Expand Down

0 comments on commit ad44430

Please sign in to comment.