Blob Blame History Raw
commit 17cdeebe701c46acb3125a8f46c105ef917d6af7
Author: Your Name <you@example.com>
Date:   Thu May 9 21:23:29 2019 +0200

    use msgpack

diff --git a/setup.py b/setup.py
index edbccae..93c0c2e 100644
--- a/setup.py
+++ b/setup.py
@@ -39,7 +39,7 @@ install_requires = [
     # we are rather picky about msgpack versions, because a good working msgpack is
     # very important for borg, see https://github.com/borgbackup/borg/issues/3753
     # best versions seem to be 0.4.6, 0.4.7, 0.4.8 and 0.5.6:
-    'msgpack-python >=0.4.6, <=0.5.6, !=0.5.0, !=0.5.1, !=0.5.2, !=0.5.3, !=0.5.4, !=0.5.5',
+    #'msgpack-python >=0.4.6, <=0.5.6, !=0.5.0, !=0.5.1, !=0.5.2, !=0.5.3, !=0.5.4, !=0.5.5',
     # if you can't satisfy the above requirement, these are versions that might
     # also work ok, IF you make sure to use the COMPILED version of msgpack-python,
     # NOT the PURE PYTHON fallback implementation: ==0.5.1, ==0.5.4
@@ -88,6 +88,8 @@ platform_posix_source = 'src/borg/platform/posix.pyx'
 platform_linux_source = 'src/borg/platform/linux.pyx'
 platform_darwin_source = 'src/borg/platform/darwin.pyx'
 platform_freebsd_source = 'src/borg/platform/freebsd.pyx'
+msgpack_packer_source = 'src/borg/_msgpack/_packer.pyx'
+msgpack_unpacker_source = 'src/borg/_msgpack/_unpacker.pyx'
 
 cython_sources = [
     compress_source,
@@ -129,6 +131,8 @@ try:
                 'src/borg/platform/linux.c',
                 'src/borg/platform/freebsd.c',
                 'src/borg/platform/darwin.c',
+                'src/borg/_msgpack/_packer.cpp',
+                'src/borg/_msgpack/_unpacker.cpp',
             ])
             super().make_distribution()
 
@@ -147,10 +151,15 @@ except ImportError:
     platform_linux_source = platform_linux_source.replace('.pyx', '.c')
     platform_freebsd_source = platform_freebsd_source.replace('.pyx', '.c')
     platform_darwin_source = platform_darwin_source.replace('.pyx', '.c')
+
+    msgpack_packer_source = msgpack_packer_source.replace('.pyx', '.cpp')
+    msgpack_unpacker_source = msgpack_unpacker_source.replace('.pyx', '.cpp')
+
     from distutils.command.build_ext import build_ext
     if not on_rtd and not all(os.path.exists(path) for path in [
         compress_source, crypto_ll_source, chunker_source, hashindex_source, item_source, checksums_source,
-        platform_posix_source, platform_linux_source, platform_freebsd_source, platform_darwin_source]):
+        platform_posix_source, platform_linux_source, platform_freebsd_source, platform_darwin_source,
+        msgpack_packer_source, msgpack_unpacker_source]):
         raise ImportError('The GIT version of Borg needs Cython. Install Cython or use a released version.')
 
 
@@ -788,7 +797,32 @@ if not on_rtd:
     crypto_ext_kwargs = setup_b2.b2_ext_kwargs(bundled_path='src/borg/algorithms/blake2',
                                                system_prefix=libb2_prefix, system=libb2_system,
                                                **crypto_ext_kwargs)
+
+    def cythonize_cpp(src):
+        sys.stderr.write("cythonize: %r\n" % (src,))
+        cython_compiler.compile([src], cplus=True)
+        return src.replace('.pyx', '.cpp')
+
+    msgpack_packer_cpp_source = cythonize_cpp(msgpack_packer_source)
+    _msgpack_endian = '__BIG_ENDIAN__' if (sys.byteorder == 'big') else '__LITTLE_ENDIAN__'
+    _msgpack_macros = [(_msgpack_endian, '1')]
+    _msgpack_packer_ext_kwargs = dict(
+        sources=[msgpack_packer_cpp_source],
+        include_dirs=include_dirs,
+        library_dirs=library_dirs,
+        define_macros=_msgpack_macros,
+    )
+    msgpack_unpacker_cpp_source = cythonize_cpp(msgpack_unpacker_source)
+    _msgpack_unpacker_ext_kwargs = dict(
+        sources=[msgpack_unpacker_cpp_source],
+        include_dirs=include_dirs,
+        library_dirs=library_dirs,
+        define_macros=_msgpack_macros,
+    )
+
     ext_modules += [
+        Extension('borg._msgpack._packer', **_msgpack_packer_ext_kwargs),
+        Extension('borg._msgpack._unpacker', **_msgpack_unpacker_ext_kwargs),
         Extension('borg.compress', **compress_ext_kwargs),
         Extension('borg.crypto.low_level', **crypto_ext_kwargs),
         Extension('borg.hashindex', [hashindex_source]),