Parcourir la source

Merge pull request #8065 from ThomasWaldmann/less-setuppy-1.4

Use less setup.py (1.4-maint)
TW il y a 1 an
Parent
commit
206f90f56a
8 fichiers modifiés avec 62 ajouts et 56 suppressions
  1. 7 3
      docs/development.rst
  2. 1 1
      docs/installation.rst
  3. 2 3
      docs/usage/mount.rst
  4. 1 1
      pyproject.toml
  5. 32 42
      scripts/gendocs.py
  6. 17 4
      setup.py
  7. 1 1
      src/borg/archiver.py
  8. 1 1
      src/borg/helpers/msgpack.py

+ 7 - 3
docs/development.rst

@@ -220,8 +220,8 @@ for easier use by packagers downstream.
 When a command is added, a command line flag changed, added or removed,
 When a command is added, a command line flag changed, added or removed,
 the usage docs need to be rebuilt as well::
 the usage docs need to be rebuilt as well::
 
 
-  python setup.py build_usage
-  python setup.py build_man
+  python scripts/gendocs.py build_usage
+  python scripts/gendocs.py build_man
 
 
 However, we prefer to do this as part of our :ref:`releasing`
 However, we prefer to do this as part of our :ref:`releasing`
 preparations, so it is generally not necessary to update these when
 preparations, so it is generally not necessary to update these when
@@ -311,7 +311,11 @@ Checklist:
 - Check version number of upcoming release in ``CHANGES.rst``.
 - Check version number of upcoming release in ``CHANGES.rst``.
 - Render ``CHANGES.rst`` via ``make html`` and check for markup errors.
 - Render ``CHANGES.rst`` via ``make html`` and check for markup errors.
 - Verify that ``MANIFEST.in``, ``pyproject.toml`` and ``setup.py`` are complete.
 - Verify that ``MANIFEST.in``, ``pyproject.toml`` and ``setup.py`` are complete.
-- ``python setup.py build_usage ; python setup.py build_man`` and commit.
+- Run these commands and commit::
+
+  python scripts/gendocs.py build_usage
+  python scripts/gendocs.py build_man
+
 - Tag the release::
 - Tag the release::
 
 
     git tag -s -m "tagged/signed release X.Y.Z" X.Y.Z
     git tag -s -m "tagged/signed release X.Y.Z" X.Y.Z

+ 1 - 1
docs/installation.rst

@@ -180,7 +180,7 @@ following dependencies first:
 
 
   - Either pyfuse3_ (preferably, newer and maintained) or llfuse_ (older,
   - Either pyfuse3_ (preferably, newer and maintained) or llfuse_ (older,
     unmaintained now). See also the BORG_FUSE_IMPL env variable.
     unmaintained now). See also the BORG_FUSE_IMPL env variable.
-  - See setup.py about the version requirements.
+  - See pyproject.toml about the version requirements.
 
 
 If you have troubles finding the right package names, have a look at the
 If you have troubles finding the right package names, have a look at the
 distribution specific sections below or the Vagrantfile in the git repository,
 distribution specific sections below or the Vagrantfile in the git repository,

+ 2 - 3
docs/usage/mount.rst

@@ -59,6 +59,5 @@ borgfs
 .. Note::
 .. Note::
 
 
     ``borgfs`` will be automatically provided if you used a distribution
     ``borgfs`` will be automatically provided if you used a distribution
-    package, ``pip`` or ``setup.py`` to install Borg. Users of the
-    standalone binary will have to manually create a symlink (see
-    :ref:`pyinstaller-binary`).
+    package or ``pip`` to install Borg. Users of the standalone binary will have
+    to manually create a symlink (see :ref:`pyinstaller-binary`).

+ 1 - 1
pyproject.toml

@@ -127,7 +127,7 @@ dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
 # ruff failures that appear with your change.
 # ruff failures that appear with your change.
 [tool.ruff.per-file-ignores]
 [tool.ruff.per-file-ignores]
 "setup.py" = ["E501"]
 "setup.py" = ["E501"]
-"setup_docs.py" = ["E501"]
+"scripts/gendocs.py" = ["E501"]
 "src/borg/archive.py" = ["E501", "F401"]
 "src/borg/archive.py" = ["E501", "F401"]
 "src/borg/archiver.py" = ["E501", "F401", "E722", "E741"]
 "src/borg/archiver.py" = ["E501", "F401", "E722", "E741"]
 "src/borg/cache.py" = ["E501", "E722"]
 "src/borg/cache.py" = ["E501", "E722"]

+ 32 - 42
setup_docs.py → scripts/gendocs.py

@@ -9,22 +9,6 @@ from collections import OrderedDict
 from datetime import datetime, timezone
 from datetime import datetime, timezone
 import time
 import time
 
 
-from setuptools import Command
-
-
-def long_desc_from_readme():
-    with open('README.rst') as fd:
-        long_description = fd.read()
-        # remove header, but have one \n before first headline
-        start = long_description.find('What is BorgBackup?')
-        assert start >= 0
-        long_description = '\n' + long_description[start:]
-        # remove badges
-        long_description = re.compile(r'^\.\. start-badges.*^\.\. end-badges', re.M | re.S).sub('', long_description)
-        # remove unknown directives
-        long_description = re.compile(r'^\.\. highlight:: \w+$', re.M).sub('', long_description)
-        return long_description
-
 
 
 def format_metavar(option):
 def format_metavar(option):
     if option.nargs in ('*', '...'):
     if option.nargs in ('*', '...'):
@@ -37,18 +21,8 @@ def format_metavar(option):
         raise ValueError(f'Can\'t format metavar {option.metavar}, unknown nargs {option.nargs}!')
         raise ValueError(f'Can\'t format metavar {option.metavar}, unknown nargs {option.nargs}!')
 
 
 
 
-class build_usage(Command):
-    description = "generate usage for each command"
-
-    user_options = [
-        ('output=', 'O', 'output directory'),
-    ]
-
-    def initialize_options(self):
-        pass
-
-    def finalize_options(self):
-        pass
+class BuildUsage:
+    """generate usage docs for each command"""
 
 
     def run(self):
     def run(self):
         print('generating usage docs')
         print('generating usage docs')
@@ -64,6 +38,7 @@ class build_usage(Command):
         #borgfs_parser = Archiver(prog='borgfs').build_parser()
         #borgfs_parser = Archiver(prog='borgfs').build_parser()
 
 
         self.generate_level("", parser, Archiver)
         self.generate_level("", parser, Archiver)
+        return 0
 
 
     def generate_level(self, prefix, parser, Archiver, extra_choices=None):
     def generate_level(self, prefix, parser, Archiver, extra_choices=None):
         is_subcommand = False
         is_subcommand = False
@@ -133,10 +108,6 @@ class build_usage(Command):
         # HTML output:
         # HTML output:
         # A table using some column-spans
         # A table using some column-spans
 
 
-        def html_write(s):
-            for line in s.splitlines():
-                fp.write('    ' + line + '\n')
-
         rows = []
         rows = []
         for group in parser._action_groups:
         for group in parser._action_groups:
             if group.title == 'Common options':
             if group.title == 'Common options':
@@ -271,10 +242,8 @@ class build_usage(Command):
             fp.write(indent + option.ljust(padding) + desc + '\n')
             fp.write(indent + option.ljust(padding) + desc + '\n')
 
 
 
 
-class build_man(Command):
-    description = 'build man pages'
-
-    user_options = []
+class BuildMan:
+    """build man pages"""
 
 
     see_also = {
     see_also = {
         'create': ('delete', 'prune', 'check', 'patterns', 'placeholders', 'compression'),
         'create': ('delete', 'prune', 'check', 'patterns', 'placeholders', 'compression'),
@@ -315,12 +284,6 @@ class build_man(Command):
         'umount': 'mount',
         'umount': 'mount',
     }
     }
 
 
-    def initialize_options(self):
-        pass
-
-    def finalize_options(self):
-        pass
-
     def run(self):
     def run(self):
         print('building man pages (in docs/man)', file=sys.stderr)
         print('building man pages (in docs/man)', file=sys.stderr)
         import borg
         import borg
@@ -334,6 +297,7 @@ class build_man(Command):
         self.generate_level('', parser, Archiver, {'borgfs': borgfs_parser})
         self.generate_level('', parser, Archiver, {'borgfs': borgfs_parser})
         self.build_topic_pages(Archiver)
         self.build_topic_pages(Archiver)
         self.build_intro_page()
         self.build_intro_page()
+        return 0
 
 
     def generate_level(self, prefix, parser, Archiver, extra_choices=None):
     def generate_level(self, prefix, parser, Archiver, extra_choices=None):
         is_subcommand = False
         is_subcommand = False
@@ -552,3 +516,29 @@ class build_man(Command):
 
 
         for option, desc in opts.items():
         for option, desc in opts.items():
             write(option.ljust(padding), desc)
             write(option.ljust(padding), desc)
+
+
+def usage():
+    print(textwrap.dedent("""
+        Usage:
+            python scripts/gendocs.py build_usage  # build usage documentation
+            python scripts/gendocs.py build_man    # build man pages
+    """))
+
+
+def main(argv):
+    if len(argv) < 2 or len(argv) == 2 and argv[1] in ("-h", "--help"):
+        usage()
+        return 0
+    command = argv[1]
+    if command == "build_usage":
+        return BuildUsage().run()
+    if command == "build_man":
+        return BuildMan().run()
+    usage()
+    return 1
+
+
+if __name__ == '__main__':
+    rc = main(sys.argv)
+    sys.exit(rc)

+ 17 - 4
setup.py

@@ -1,6 +1,7 @@
 # borgbackup - main setup code (see also pyproject.toml and other setup_*.py files)
 # borgbackup - main setup code (see also pyproject.toml and other setup_*.py files)
 
 
 import os
 import os
+import re
 import sys
 import sys
 from collections import defaultdict
 from collections import defaultdict
 from glob import glob
 from glob import glob
@@ -23,7 +24,6 @@ sys.path += [os.path.dirname(__file__)]
 import setup_checksums
 import setup_checksums
 import setup_compress
 import setup_compress
 import setup_crypto
 import setup_crypto
-import setup_docs
 
 
 is_win32 = sys.platform.startswith('win32')
 is_win32 = sys.platform.startswith('win32')
 
 
@@ -141,8 +141,6 @@ class Clean(Command):
 
 
 cmdclass = {
 cmdclass = {
     'build_ext': build_ext,
     'build_ext': build_ext,
-    'build_usage': setup_docs.build_usage,
-    'build_man': setup_docs.build_man,
     'sdist': Sdist,
     'sdist': Sdist,
     'clean2': Clean,
     'clean2': Clean,
 }
 }
@@ -233,4 +231,19 @@ if not on_rtd:
         # generate C code from Cython for THIS platform (and for all platform-independent Cython parts).
         # generate C code from Cython for THIS platform (and for all platform-independent Cython parts).
         ext_modules = cythonize(ext_modules, **cython_opts)
         ext_modules = cythonize(ext_modules, **cython_opts)
 
 
-setup(cmdclass=cmdclass, ext_modules=ext_modules, long_description=setup_docs.long_desc_from_readme())
+
+def long_desc_from_readme():
+    with open('README.rst') as fd:
+        long_description = fd.read()
+        # remove header, but have one \n before first headline
+        start = long_description.find('What is BorgBackup?')
+        assert start >= 0
+        long_description = '\n' + long_description[start:]
+        # remove badges
+        long_description = re.compile(r'^\.\. start-badges.*^\.\. end-badges', re.M | re.S).sub('', long_description)
+        # remove unknown directives
+        long_description = re.compile(r'^\.\. highlight:: \w+$', re.M).sub('', long_description)
+        return long_description
+
+
+setup(cmdclass=cmdclass, ext_modules=ext_modules, long_description=long_desc_from_readme())

+ 1 - 1
src/borg/archiver.py

@@ -5198,7 +5198,7 @@ class Archiver:
         self.prerun_checks(logger, is_serve)
         self.prerun_checks(logger, is_serve)
         if not is_supported_msgpack():
         if not is_supported_msgpack():
             logger.error("You do not have a supported version of the msgpack python package installed. Terminating.")
             logger.error("You do not have a supported version of the msgpack python package installed. Terminating.")
-            logger.error("This should never happen as specific, supported versions are required by our setup.py.")
+            logger.error("This should never happen as specific, supported versions are required by our pyproject.toml.")
             logger.error("Do not contact borgbackup support about this.")
             logger.error("Do not contact borgbackup support about this.")
             raise Error("unsupported msgpack version")
             raise Error("unsupported msgpack version")
         if is_slow_msgpack():
         if is_slow_msgpack():

+ 1 - 1
src/borg/helpers/msgpack.py

@@ -135,7 +135,7 @@ def is_slow_msgpack():
 
 
 
 
 def is_supported_msgpack():
 def is_supported_msgpack():
-    # DO NOT CHANGE OR REMOVE! See also requirements and comments in setup.py.
+    # DO NOT CHANGE OR REMOVE! See also requirements and comments in pyproject.toml.
     import msgpack
     import msgpack
     return (1, 0, 3) <= msgpack.version <= (1, 0, 7) and \
     return (1, 0, 3) <= msgpack.version <= (1, 0, 7) and \
            msgpack.version not in []  # < add bad releases here to deny list
            msgpack.version not in []  # < add bad releases here to deny list