2
0
Эх сурвалжийг харах

Merge pull request #8069 from ThomasWaldmann/less-setuppy2-1.4

Use less setup.py, continued (1.4-maint)
TW 1 жил өмнө
parent
commit
ad44430b2a
5 өөрчлөгдсөн 50 нэмэгдсэн , 38 устгасан
  1. 1 1
      Vagrantfile
  2. 4 4
      docs/development.rst
  3. 1 1
      pyproject.toml
  4. 42 2
      scripts/make.py
  5. 2 30
      setup.py

+ 1 - 1
Vagrantfile

@@ -194,7 +194,7 @@ def install_borg(fuse)
     pip install -U wheel  # upgrade wheel, might be too old
     pip install -U wheel  # upgrade wheel, might be too old
     cd borg
     cd borg
     pip install -r requirements.d/development.lock.txt
     pip install -r requirements.d/development.lock.txt
-    python setup.py clean clean2
+    python3 scripts/make.py clean
     pip install -e .[#{fuse}]
     pip install -e .[#{fuse}]
   EOF
   EOF
 end
 end

+ 4 - 4
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 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`
 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
@@ -313,8 +313,8 @@ Checklist:
 - Verify that ``MANIFEST.in``, ``pyproject.toml`` and ``setup.py`` are complete.
 - Verify that ``MANIFEST.in``, ``pyproject.toml`` and ``setup.py`` are complete.
 - Run these commands and commit::
 - 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::
 - Tag the release::
 
 

+ 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"]
-"scripts/gendocs.py" = ["E501"]
+"scripts/make.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"]

+ 42 - 2
scripts/gendocs.py → scripts/make.py

@@ -1,5 +1,6 @@
 # Support code for building docs (build_usage, build_man)
 # Support code for building docs (build_usage, build_man)
 
 
+import glob
 import os
 import os
 import io
 import io
 import re
 import re
@@ -518,11 +519,48 @@ class BuildMan:
             write(option.ljust(padding), desc)
             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():
 def usage():
     print(textwrap.dedent("""
     print(textwrap.dedent("""
         Usage:
         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
     """))
     """))
 
 
 
 
@@ -531,6 +569,8 @@ def main(argv):
         usage()
         usage()
         return 0
         return 0
     command = argv[1]
     command = argv[1]
+    if command == "clean":
+        return Clean().run()
     if command == "build_usage":
     if command == "build_usage":
         return BuildUsage().run()
         return BuildUsage().run()
     if command == "build_man":
     if command == "build_man":

+ 2 - 30
setup.py

@@ -4,7 +4,6 @@ import os
 import re
 import re
 import sys
 import sys
 from collections import defaultdict
 from collections import defaultdict
-from glob import glob
 
 
 try:
 try:
     import multiprocessing
     import multiprocessing
@@ -12,7 +11,7 @@ except ImportError:
     multiprocessing = None
     multiprocessing = None
 
 
 from setuptools.command.build_ext import build_ext
 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
 from setuptools.command.sdist import sdist
 
 
 try:
 try:
@@ -113,36 +112,9 @@ else:
         raise ImportError('The GIT version of Borg needs Cython. Install Cython or use a released version.')
         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 = {
 cmdclass = {
     'build_ext': build_ext,
     'build_ext': build_ext,
     'sdist': Sdist,
     'sdist': Sdist,
-    'clean2': Clean,
 }
 }
 
 
 ext_modules = []
 ext_modules = []
@@ -213,7 +185,7 @@ if not on_rtd:
     # sometimes there's no need to cythonize
     # sometimes there's no need to cythonize
     # this breaks chained commands like 'clean sdist'
     # this breaks chained commands like 'clean sdist'
     cythonizing = len(sys.argv) > 1 and sys.argv[1] not in (
     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:
     if cythonize and cythonizing:
         cython_opts = dict(
         cython_opts = dict(