We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
cythonize crashes on macOS with py39
Found this issue on the macOS vagrant machine after upgrading python to 3.9.1:

https://github.com/cython/cython/issues/3262


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `setup.py`
Content:
```
1 # borgbackup - main setup code (see also other setup_*.py files)
2 
3 import os
4 import sys
5 from collections import defaultdict
6 from glob import glob
7 
8 try:
9     import multiprocessing
10 except ImportError:
11     multiprocessing = None
12 
13 from setuptools.command.build_ext import build_ext
14 from setuptools import setup, find_packages, Extension
15 from setuptools.command.sdist import sdist
16 from distutils.command.clean import clean
17 
18 try:
19     from Cython.Build import cythonize
20 except ImportError:
21     cythonize = None
22 
23 import setup_checksums
24 import setup_compress
25 import setup_crypto
26 import setup_docs
27 
28 is_win32 = sys.platform.startswith('win32')
29 
30 # How the build process finds the system libs / uses the bundled code:
31 #
32 # 1. it will try to use (system) libs (see 1.1. and 1.2.),
33 #    except if you use these env vars to force using the bundled code:
34 #    BORG_USE_BUNDLED_XXX undefined  -->  try using system lib
35 #    BORG_USE_BUNDLED_XXX=YES        -->  use the bundled code
36 #    Note: do not use =NO, that is not supported!
37 # 1.1. if BORG_LIBXXX_PREFIX is set, it will use headers and libs from there.
38 # 1.2. if not and pkg-config can locate the lib, the lib located by
39 #      pkg-config will be used. We use the pkg-config tool via the pkgconfig
40 #      python package, which must be installed before invoking setup.py.
41 #      if pkgconfig is not installed, this step is skipped.
42 # 2. if no system lib could be located via 1.1. or 1.2., it will fall back
43 #    to using the bundled code.
44 
45 # OpenSSL is required as a (system) lib in any case as we do not bundle it.
46 # Thus, only step 1.1. and 1.2. apply to openssl (but not 1. and 2.).
47 # needed: openssl >=1.0.2 or >=1.1.0 (or compatible)
48 system_prefix_openssl = os.environ.get('BORG_OPENSSL_PREFIX')
49 
50 # needed: blake2 (>= 0.98.1)
51 prefer_system_libb2 = not bool(os.environ.get('BORG_USE_BUNDLED_B2'))
52 system_prefix_libb2 = os.environ.get('BORG_LIBB2_PREFIX')
53 
54 # needed: lz4 (>= 1.7.0 / r129)
55 prefer_system_liblz4 = not bool(os.environ.get('BORG_USE_BUNDLED_LZ4'))
56 system_prefix_liblz4 = os.environ.get('BORG_LIBLZ4_PREFIX')
57 
58 # needed: zstd (>= 1.3.0)
59 prefer_system_libzstd = not bool(os.environ.get('BORG_USE_BUNDLED_ZSTD'))
60 system_prefix_libzstd = os.environ.get('BORG_LIBZSTD_PREFIX')
61 
62 prefer_system_libxxhash = not bool(os.environ.get('BORG_USE_BUNDLED_XXHASH'))
63 system_prefix_libxxhash = os.environ.get('BORG_LIBXXHASH_PREFIX')
64 
65 # Number of threads to use for cythonize, not used on windows
66 cpu_threads = multiprocessing.cpu_count() if multiprocessing else 1
67 
68 # Are we building on ReadTheDocs?
69 on_rtd = os.environ.get('READTHEDOCS')
70 
71 install_requires = [
72     # we are rather picky about msgpack versions, because a good working msgpack is
73     # very important for borg, see: https://github.com/borgbackup/borg/issues/3753
74     'msgpack >=0.5.6, <=1.0.0',
75     # Please note:
76     # using any other version is not supported by borg development and
77     # any feedback related to issues caused by this will be ignored.
78 ]
79 
80 # note for package maintainers: if you package borgbackup for distribution,
81 # please (if available) add pyfuse3 (preferably) or llfuse (not maintained any more)
82 # as a *requirement*. "borg mount" needs one of them to work.
83 # if neither is available, do not require it, most of borgbackup will work.
84 extras_require = {
85     'llfuse': [
86         'llfuse >= 1.3.8',
87     ],
88     'pyfuse3': [
89         'pyfuse3 >= 3.1.1',
90     ],
91     'nofuse': [],
92 }
93 
94 compress_source = 'src/borg/compress.pyx'
95 crypto_ll_source = 'src/borg/crypto/low_level.pyx'
96 crypto_helpers = 'src/borg/crypto/_crypto_helpers.c'
97 chunker_source = 'src/borg/chunker.pyx'
98 hashindex_source = 'src/borg/hashindex.pyx'
99 item_source = 'src/borg/item.pyx'
100 checksums_source = 'src/borg/algorithms/checksums.pyx'
101 platform_posix_source = 'src/borg/platform/posix.pyx'
102 platform_linux_source = 'src/borg/platform/linux.pyx'
103 platform_syncfilerange_source = 'src/borg/platform/syncfilerange.pyx'
104 platform_darwin_source = 'src/borg/platform/darwin.pyx'
105 platform_freebsd_source = 'src/borg/platform/freebsd.pyx'
106 platform_windows_source = 'src/borg/platform/windows.pyx'
107 
108 cython_sources = [
109     compress_source,
110     crypto_ll_source,
111     chunker_source,
112     hashindex_source,
113     item_source,
114     checksums_source,
115 
116     platform_posix_source,
117     platform_linux_source,
118     platform_syncfilerange_source,
119     platform_freebsd_source,
120     platform_darwin_source,
121     platform_windows_source,
122 ]
123 
124 if cythonize:
125     Sdist = sdist
126 else:
127     class Sdist(sdist):
128         def __init__(self, *args, **kwargs):
129             raise Exception('Cython is required to run sdist')
130 
131     cython_c_files = [fn.replace('.pyx', '.c') for fn in cython_sources]
132     if not on_rtd and not all(os.path.exists(path) for path in cython_c_files):
133         raise ImportError('The GIT version of Borg needs Cython. Install Cython or use a released version.')
134 
135 
136 def rm(file):
137     try:
138         os.unlink(file)
139         print('rm', file)
140     except FileNotFoundError:
141         pass
142 
143 
144 class Clean(clean):
145     def run(self):
146         super().run()
147         for source in cython_sources:
148             genc = source.replace('.pyx', '.c')
149             rm(genc)
150             compiled_glob = source.replace('.pyx', '.cpython*')
151             for compiled in sorted(glob(compiled_glob)):
152                 rm(compiled)
153 
154 
155 cmdclass = {
156     'build_ext': build_ext,
157     'build_usage': setup_docs.build_usage,
158     'build_man': setup_docs.build_man,
159     'sdist': Sdist,
160     'clean': Clean,
161 }
162 
163 ext_modules = []
164 if not on_rtd:
165 
166     def members_appended(*ds):
167         result = defaultdict(list)
168         for d in ds:
169             for k, v in d.items():
170                 assert isinstance(v, list)
171                 result[k].extend(v)
172         return result
173 
174     try:
175         import pkgconfig as pc
176     except ImportError:
177         print('Warning: can not import pkgconfig python package.')
178         pc = None
179 
180     crypto_ext_kwargs = members_appended(
181         dict(sources=[crypto_ll_source, crypto_helpers]),
182         setup_crypto.crypto_ext_kwargs(pc, system_prefix_openssl),
183         setup_crypto.b2_ext_kwargs(pc, prefer_system_libb2, system_prefix_libb2),
184     )
185 
186     compress_ext_kwargs = members_appended(
187         dict(sources=[compress_source]),
188         setup_compress.lz4_ext_kwargs(pc, prefer_system_liblz4, system_prefix_liblz4),
189         setup_compress.zstd_ext_kwargs(pc, prefer_system_libzstd, system_prefix_libzstd,
190                                        multithreaded=False, legacy=False),
191     )
192 
193     checksums_ext_kwargs = members_appended(
194         dict(sources=[checksums_source]),
195         setup_checksums.xxhash_ext_kwargs(pc, prefer_system_libxxhash, system_prefix_libxxhash),
196     )
197 
198     ext_modules += [
199         Extension('borg.crypto.low_level', **crypto_ext_kwargs),
200         Extension('borg.compress', **compress_ext_kwargs),
201         Extension('borg.hashindex', [hashindex_source]),
202         Extension('borg.item', [item_source]),
203         Extension('borg.chunker', [chunker_source]),
204         Extension('borg.algorithms.checksums', **checksums_ext_kwargs),
205     ]
206 
207     posix_ext = Extension('borg.platform.posix', [platform_posix_source])
208     linux_ext = Extension('borg.platform.linux', [platform_linux_source], libraries=['acl'])
209     syncfilerange_ext = Extension('borg.platform.syncfilerange', [platform_syncfilerange_source])
210     freebsd_ext = Extension('borg.platform.freebsd', [platform_freebsd_source])
211     darwin_ext = Extension('borg.platform.darwin', [platform_darwin_source])
212     windows_ext = Extension('borg.platform.windows', [platform_windows_source])
213 
214     if not is_win32:
215         ext_modules.append(posix_ext)
216     else:
217         ext_modules.append(windows_ext)
218     if sys.platform == 'linux':
219         ext_modules.append(linux_ext)
220         ext_modules.append(syncfilerange_ext)
221     elif sys.platform.startswith('freebsd'):
222         ext_modules.append(freebsd_ext)
223     elif sys.platform == 'darwin':
224         ext_modules.append(darwin_ext)
225 
226     # sometimes there's no need to cythonize
227     # this breaks chained commands like 'clean sdist'
228     cythonizing = len(sys.argv) > 1 and sys.argv[1] not in ('clean', 'egg_info', '--help-commands', '--version') \
229                   and '--help' not in sys.argv[1:]
230 
231     if cythonize and cythonizing:
232         cython_opts = dict(
233             # default language_level will be '3str' starting from Cython 3.0.0,
234             # but old cython versions (< 0.29) do not know that, thus we use 3 for now.
235             compiler_directives={'language_level': 3},
236         )
237         if not is_win32:
238             # compile .pyx extensions to .c in parallel, does not work on windows
239             cython_opts['nthreads'] = cpu_threads + 1
240 
241         # generate C code from Cython for ALL supported platforms, so we have them in the sdist.
242         # the sdist does not require Cython at install time, so we need all as C.
243         cythonize([posix_ext, linux_ext, syncfilerange_ext, freebsd_ext, darwin_ext, windows_ext], **cython_opts)
244         # generate C code from Cython for THIS platform (and for all platform-independent Cython parts).
245         ext_modules = cythonize(ext_modules, **cython_opts)
246 
247 
248 setup(
249     name='borgbackup',
250     use_scm_version={
251         'write_to': 'src/borg/_version.py',
252     },
253     author='The Borg Collective (see AUTHORS file)',
254     author_email='borgbackup@python.org',
255     url='https://borgbackup.readthedocs.io/',
256     description='Deduplicated, encrypted, authenticated and compressed backups',
257     long_description=setup_docs.long_desc_from_readme(),
258     license='BSD',
259     platforms=['Linux', 'MacOS X', 'FreeBSD', 'OpenBSD', 'NetBSD', ],
260     classifiers=[
261         'Development Status :: 3 - Alpha',
262         'Environment :: Console',
263         'Intended Audience :: System Administrators',
264         'License :: OSI Approved :: BSD License',
265         'Operating System :: POSIX :: BSD :: FreeBSD',
266         'Operating System :: POSIX :: BSD :: OpenBSD',
267         'Operating System :: POSIX :: BSD :: NetBSD',
268         'Operating System :: MacOS :: MacOS X',
269         'Operating System :: POSIX :: Linux',
270         'Programming Language :: Python',
271         'Programming Language :: Python :: 3',
272         'Programming Language :: Python :: 3.6',
273         'Programming Language :: Python :: 3.7',
274         'Programming Language :: Python :: 3.8',
275         'Programming Language :: Python :: 3.9',
276         'Topic :: Security :: Cryptography',
277         'Topic :: System :: Archiving :: Backup',
278     ],
279     packages=find_packages('src'),
280     package_dir={'': 'src'},
281     zip_safe=False,
282     entry_points={
283         'console_scripts': [
284             'borg = borg.archiver:main',
285             'borgfs = borg.archiver:main',
286         ]
287     },
288     # See also the MANIFEST.in file.
289     # We want to install all the files in the package directories...
290     include_package_data=True,
291     # ...except the source files which have been compiled (C extensions):
292     exclude_package_data={
293         '': ['*.c', '*.h', '*.pyx', ],
294     },
295     cmdclass=cmdclass,
296     ext_modules=ext_modules,
297     setup_requires=['setuptools_scm>=1.7'],
298     install_requires=install_requires,
299     extras_require=extras_require,
300     python_requires='>=3.6',
301 )
302
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -63,7 +63,7 @@
 system_prefix_libxxhash = os.environ.get('BORG_LIBXXHASH_PREFIX')
 
 # Number of threads to use for cythonize, not used on windows
-cpu_threads = multiprocessing.cpu_count() if multiprocessing else 1
+cpu_threads = multiprocessing.cpu_count() if multiprocessing and multiprocessing.get_start_method() != 'spawn' else None
 
 # Are we building on ReadTheDocs?
 on_rtd = os.environ.get('READTHEDOCS')
@@ -236,7 +236,7 @@
         )
         if not is_win32:
             # compile .pyx extensions to .c in parallel, does not work on windows
-            cython_opts['nthreads'] = cpu_threads + 1
+            cython_opts['nthreads'] = cpu_threads
 
         # generate C code from Cython for ALL supported platforms, so we have them in the sdist.
         # the sdist does not require Cython at install time, so we need all as C.

{"golden_diff": "diff --git a/setup.py b/setup.py\n--- a/setup.py\n+++ b/setup.py\n@@ -63,7 +63,7 @@\n system_prefix_libxxhash = os.environ.get('BORG_LIBXXHASH_PREFIX')\n \n # Number of threads to use for cythonize, not used on windows\n-cpu_threads = multiprocessing.cpu_count() if multiprocessing else 1\n+cpu_threads = multiprocessing.cpu_count() if multiprocessing and multiprocessing.get_start_method() != 'spawn' else None\n \n # Are we building on ReadTheDocs?\n on_rtd = os.environ.get('READTHEDOCS')\n@@ -236,7 +236,7 @@\n         )\n         if not is_win32:\n             # compile .pyx extensions to .c in parallel, does not work on windows\n-            cython_opts['nthreads'] = cpu_threads + 1\n+            cython_opts['nthreads'] = cpu_threads\n \n         # generate C code from Cython for ALL supported platforms, so we have them in the sdist.\n         # the sdist does not require Cython at install time, so we need all as C.\n", "issue": "cythonize crashes on macOS with py39\nFound this issue on the macOS vagrant machine after upgrading python to 3.9.1:\r\n\r\nhttps://github.com/cython/cython/issues/3262\r\n\n", "before_files": [{"content": "# borgbackup - main setup code (see also other setup_*.py files)\n\nimport os\nimport sys\nfrom collections import defaultdict\nfrom glob import glob\n\ntry:\n    import multiprocessing\nexcept ImportError:\n    multiprocessing = None\n\nfrom setuptools.command.build_ext import build_ext\nfrom setuptools import setup, find_packages, Extension\nfrom setuptools.command.sdist import sdist\nfrom distutils.command.clean import clean\n\ntry:\n    from Cython.Build import cythonize\nexcept ImportError:\n    cythonize = None\n\nimport setup_checksums\nimport setup_compress\nimport setup_crypto\nimport setup_docs\n\nis_win32 = sys.platform.startswith('win32')\n\n# How the build process finds the system libs / uses the bundled code:\n#\n# 1. it will try to use (system) libs (see 1.1. and 1.2.),\n#    except if you use these env vars to force using the bundled code:\n#    BORG_USE_BUNDLED_XXX undefined  -->  try using system lib\n#    BORG_USE_BUNDLED_XXX=YES        -->  use the bundled code\n#    Note: do not use =NO, that is not supported!\n# 1.1. if BORG_LIBXXX_PREFIX is set, it will use headers and libs from there.\n# 1.2. if not and pkg-config can locate the lib, the lib located by\n#      pkg-config will be used. We use the pkg-config tool via the pkgconfig\n#      python package, which must be installed before invoking setup.py.\n#      if pkgconfig is not installed, this step is skipped.\n# 2. if no system lib could be located via 1.1. or 1.2., it will fall back\n#    to using the bundled code.\n\n# OpenSSL is required as a (system) lib in any case as we do not bundle it.\n# Thus, only step 1.1. and 1.2. apply to openssl (but not 1. and 2.).\n# needed: openssl >=1.0.2 or >=1.1.0 (or compatible)\nsystem_prefix_openssl = os.environ.get('BORG_OPENSSL_PREFIX')\n\n# needed: blake2 (>= 0.98.1)\nprefer_system_libb2 = not bool(os.environ.get('BORG_USE_BUNDLED_B2'))\nsystem_prefix_libb2 = os.environ.get('BORG_LIBB2_PREFIX')\n\n# needed: lz4 (>= 1.7.0 / r129)\nprefer_system_liblz4 = not bool(os.environ.get('BORG_USE_BUNDLED_LZ4'))\nsystem_prefix_liblz4 = os.environ.get('BORG_LIBLZ4_PREFIX')\n\n# needed: zstd (>= 1.3.0)\nprefer_system_libzstd = not bool(os.environ.get('BORG_USE_BUNDLED_ZSTD'))\nsystem_prefix_libzstd = os.environ.get('BORG_LIBZSTD_PREFIX')\n\nprefer_system_libxxhash = not bool(os.environ.get('BORG_USE_BUNDLED_XXHASH'))\nsystem_prefix_libxxhash = os.environ.get('BORG_LIBXXHASH_PREFIX')\n\n# Number of threads to use for cythonize, not used on windows\ncpu_threads = multiprocessing.cpu_count() if multiprocessing else 1\n\n# Are we building on ReadTheDocs?\non_rtd = os.environ.get('READTHEDOCS')\n\ninstall_requires = [\n    # we are rather picky about msgpack versions, because a good working msgpack is\n    # very important for borg, see: https://github.com/borgbackup/borg/issues/3753\n    'msgpack >=0.5.6, <=1.0.0',\n    # Please note:\n    # using any other version is not supported by borg development and\n    # any feedback related to issues caused by this will be ignored.\n]\n\n# note for package maintainers: if you package borgbackup for distribution,\n# please (if available) add pyfuse3 (preferably) or llfuse (not maintained any more)\n# as a *requirement*. \"borg mount\" needs one of them to work.\n# if neither is available, do not require it, most of borgbackup will work.\nextras_require = {\n    'llfuse': [\n        'llfuse >= 1.3.8',\n    ],\n    'pyfuse3': [\n        'pyfuse3 >= 3.1.1',\n    ],\n    'nofuse': [],\n}\n\ncompress_source = 'src/borg/compress.pyx'\ncrypto_ll_source = 'src/borg/crypto/low_level.pyx'\ncrypto_helpers = 'src/borg/crypto/_crypto_helpers.c'\nchunker_source = 'src/borg/chunker.pyx'\nhashindex_source = 'src/borg/hashindex.pyx'\nitem_source = 'src/borg/item.pyx'\nchecksums_source = 'src/borg/algorithms/checksums.pyx'\nplatform_posix_source = 'src/borg/platform/posix.pyx'\nplatform_linux_source = 'src/borg/platform/linux.pyx'\nplatform_syncfilerange_source = 'src/borg/platform/syncfilerange.pyx'\nplatform_darwin_source = 'src/borg/platform/darwin.pyx'\nplatform_freebsd_source = 'src/borg/platform/freebsd.pyx'\nplatform_windows_source = 'src/borg/platform/windows.pyx'\n\ncython_sources = [\n    compress_source,\n    crypto_ll_source,\n    chunker_source,\n    hashindex_source,\n    item_source,\n    checksums_source,\n\n    platform_posix_source,\n    platform_linux_source,\n    platform_syncfilerange_source,\n    platform_freebsd_source,\n    platform_darwin_source,\n    platform_windows_source,\n]\n\nif cythonize:\n    Sdist = sdist\nelse:\n    class Sdist(sdist):\n        def __init__(self, *args, **kwargs):\n            raise Exception('Cython is required to run sdist')\n\n    cython_c_files = [fn.replace('.pyx', '.c') for fn in cython_sources]\n    if not on_rtd and not all(os.path.exists(path) for path in cython_c_files):\n        raise ImportError('The GIT version of Borg needs Cython. Install Cython or use a released version.')\n\n\ndef rm(file):\n    try:\n        os.unlink(file)\n        print('rm', file)\n    except FileNotFoundError:\n        pass\n\n\nclass Clean(clean):\n    def run(self):\n        super().run()\n        for source in cython_sources:\n            genc = source.replace('.pyx', '.c')\n            rm(genc)\n            compiled_glob = source.replace('.pyx', '.cpython*')\n            for compiled in sorted(glob(compiled_glob)):\n                rm(compiled)\n\n\ncmdclass = {\n    'build_ext': build_ext,\n    'build_usage': setup_docs.build_usage,\n    'build_man': setup_docs.build_man,\n    'sdist': Sdist,\n    'clean': Clean,\n}\n\next_modules = []\nif not on_rtd:\n\n    def members_appended(*ds):\n        result = defaultdict(list)\n        for d in ds:\n            for k, v in d.items():\n                assert isinstance(v, list)\n                result[k].extend(v)\n        return result\n\n    try:\n        import pkgconfig as pc\n    except ImportError:\n        print('Warning: can not import pkgconfig python package.')\n        pc = None\n\n    crypto_ext_kwargs = members_appended(\n        dict(sources=[crypto_ll_source, crypto_helpers]),\n        setup_crypto.crypto_ext_kwargs(pc, system_prefix_openssl),\n        setup_crypto.b2_ext_kwargs(pc, prefer_system_libb2, system_prefix_libb2),\n    )\n\n    compress_ext_kwargs = members_appended(\n        dict(sources=[compress_source]),\n        setup_compress.lz4_ext_kwargs(pc, prefer_system_liblz4, system_prefix_liblz4),\n        setup_compress.zstd_ext_kwargs(pc, prefer_system_libzstd, system_prefix_libzstd,\n                                       multithreaded=False, legacy=False),\n    )\n\n    checksums_ext_kwargs = members_appended(\n        dict(sources=[checksums_source]),\n        setup_checksums.xxhash_ext_kwargs(pc, prefer_system_libxxhash, system_prefix_libxxhash),\n    )\n\n    ext_modules += [\n        Extension('borg.crypto.low_level', **crypto_ext_kwargs),\n        Extension('borg.compress', **compress_ext_kwargs),\n        Extension('borg.hashindex', [hashindex_source]),\n        Extension('borg.item', [item_source]),\n        Extension('borg.chunker', [chunker_source]),\n        Extension('borg.algorithms.checksums', **checksums_ext_kwargs),\n    ]\n\n    posix_ext = Extension('borg.platform.posix', [platform_posix_source])\n    linux_ext = Extension('borg.platform.linux', [platform_linux_source], libraries=['acl'])\n    syncfilerange_ext = Extension('borg.platform.syncfilerange', [platform_syncfilerange_source])\n    freebsd_ext = Extension('borg.platform.freebsd', [platform_freebsd_source])\n    darwin_ext = Extension('borg.platform.darwin', [platform_darwin_source])\n    windows_ext = Extension('borg.platform.windows', [platform_windows_source])\n\n    if not is_win32:\n        ext_modules.append(posix_ext)\n    else:\n        ext_modules.append(windows_ext)\n    if sys.platform == 'linux':\n        ext_modules.append(linux_ext)\n        ext_modules.append(syncfilerange_ext)\n    elif sys.platform.startswith('freebsd'):\n        ext_modules.append(freebsd_ext)\n    elif sys.platform == 'darwin':\n        ext_modules.append(darwin_ext)\n\n    # sometimes there's no need to cythonize\n    # this breaks chained commands like 'clean sdist'\n    cythonizing = len(sys.argv) > 1 and sys.argv[1] not in ('clean', 'egg_info', '--help-commands', '--version') \\\n                  and '--help' not in sys.argv[1:]\n\n    if cythonize and cythonizing:\n        cython_opts = dict(\n            # default language_level will be '3str' starting from Cython 3.0.0,\n            # but old cython versions (< 0.29) do not know that, thus we use 3 for now.\n            compiler_directives={'language_level': 3},\n        )\n        if not is_win32:\n            # compile .pyx extensions to .c in parallel, does not work on windows\n            cython_opts['nthreads'] = cpu_threads + 1\n\n        # generate C code from Cython for ALL supported platforms, so we have them in the sdist.\n        # the sdist does not require Cython at install time, so we need all as C.\n        cythonize([posix_ext, linux_ext, syncfilerange_ext, freebsd_ext, darwin_ext, windows_ext], **cython_opts)\n        # generate C code from Cython for THIS platform (and for all platform-independent Cython parts).\n        ext_modules = cythonize(ext_modules, **cython_opts)\n\n\nsetup(\n    name='borgbackup',\n    use_scm_version={\n        'write_to': 'src/borg/_version.py',\n    },\n    author='The Borg Collective (see AUTHORS file)',\n    author_email='borgbackup@python.org',\n    url='https://borgbackup.readthedocs.io/',\n    description='Deduplicated, encrypted, authenticated and compressed backups',\n    long_description=setup_docs.long_desc_from_readme(),\n    license='BSD',\n    platforms=['Linux', 'MacOS X', 'FreeBSD', 'OpenBSD', 'NetBSD', ],\n    classifiers=[\n        'Development Status :: 3 - Alpha',\n        'Environment :: Console',\n        'Intended Audience :: System Administrators',\n        'License :: OSI Approved :: BSD License',\n        'Operating System :: POSIX :: BSD :: FreeBSD',\n        'Operating System :: POSIX :: BSD :: OpenBSD',\n        'Operating System :: POSIX :: BSD :: NetBSD',\n        'Operating System :: MacOS :: MacOS X',\n        'Operating System :: POSIX :: Linux',\n        'Programming Language :: Python',\n        'Programming Language :: Python :: 3',\n        'Programming Language :: Python :: 3.6',\n        'Programming Language :: Python :: 3.7',\n        'Programming Language :: Python :: 3.8',\n        'Programming Language :: Python :: 3.9',\n        'Topic :: Security :: Cryptography',\n        'Topic :: System :: Archiving :: Backup',\n    ],\n    packages=find_packages('src'),\n    package_dir={'': 'src'},\n    zip_safe=False,\n    entry_points={\n        'console_scripts': [\n            'borg = borg.archiver:main',\n            'borgfs = borg.archiver:main',\n        ]\n    },\n    # See also the MANIFEST.in file.\n    # We want to install all the files in the package directories...\n    include_package_data=True,\n    # ...except the source files which have been compiled (C extensions):\n    exclude_package_data={\n        '': ['*.c', '*.h', '*.pyx', ],\n    },\n    cmdclass=cmdclass,\n    ext_modules=ext_modules,\n    setup_requires=['setuptools_scm>=1.7'],\n    install_requires=install_requires,\n    extras_require=extras_require,\n    python_requires='>=3.6',\n)\n", "path": "setup.py"}], "after_files": [{"content": "# borgbackup - main setup code (see also other setup_*.py files)\n\nimport os\nimport sys\nfrom collections import defaultdict\nfrom glob import glob\n\ntry:\n    import multiprocessing\nexcept ImportError:\n    multiprocessing = None\n\nfrom setuptools.command.build_ext import build_ext\nfrom setuptools import setup, find_packages, Extension\nfrom setuptools.command.sdist import sdist\nfrom distutils.command.clean import clean\n\ntry:\n    from Cython.Build import cythonize\nexcept ImportError:\n    cythonize = None\n\nimport setup_checksums\nimport setup_compress\nimport setup_crypto\nimport setup_docs\n\nis_win32 = sys.platform.startswith('win32')\n\n# How the build process finds the system libs / uses the bundled code:\n#\n# 1. it will try to use (system) libs (see 1.1. and 1.2.),\n#    except if you use these env vars to force using the bundled code:\n#    BORG_USE_BUNDLED_XXX undefined  -->  try using system lib\n#    BORG_USE_BUNDLED_XXX=YES        -->  use the bundled code\n#    Note: do not use =NO, that is not supported!\n# 1.1. if BORG_LIBXXX_PREFIX is set, it will use headers and libs from there.\n# 1.2. if not and pkg-config can locate the lib, the lib located by\n#      pkg-config will be used. We use the pkg-config tool via the pkgconfig\n#      python package, which must be installed before invoking setup.py.\n#      if pkgconfig is not installed, this step is skipped.\n# 2. if no system lib could be located via 1.1. or 1.2., it will fall back\n#    to using the bundled code.\n\n# OpenSSL is required as a (system) lib in any case as we do not bundle it.\n# Thus, only step 1.1. and 1.2. apply to openssl (but not 1. and 2.).\n# needed: openssl >=1.0.2 or >=1.1.0 (or compatible)\nsystem_prefix_openssl = os.environ.get('BORG_OPENSSL_PREFIX')\n\n# needed: blake2 (>= 0.98.1)\nprefer_system_libb2 = not bool(os.environ.get('BORG_USE_BUNDLED_B2'))\nsystem_prefix_libb2 = os.environ.get('BORG_LIBB2_PREFIX')\n\n# needed: lz4 (>= 1.7.0 / r129)\nprefer_system_liblz4 = not bool(os.environ.get('BORG_USE_BUNDLED_LZ4'))\nsystem_prefix_liblz4 = os.environ.get('BORG_LIBLZ4_PREFIX')\n\n# needed: zstd (>= 1.3.0)\nprefer_system_libzstd = not bool(os.environ.get('BORG_USE_BUNDLED_ZSTD'))\nsystem_prefix_libzstd = os.environ.get('BORG_LIBZSTD_PREFIX')\n\nprefer_system_libxxhash = not bool(os.environ.get('BORG_USE_BUNDLED_XXHASH'))\nsystem_prefix_libxxhash = os.environ.get('BORG_LIBXXHASH_PREFIX')\n\n# Number of threads to use for cythonize, not used on windows\ncpu_threads = multiprocessing.cpu_count() if multiprocessing and multiprocessing.get_start_method() != 'spawn' else None\n\n# Are we building on ReadTheDocs?\non_rtd = os.environ.get('READTHEDOCS')\n\ninstall_requires = [\n    # we are rather picky about msgpack versions, because a good working msgpack is\n    # very important for borg, see: https://github.com/borgbackup/borg/issues/3753\n    'msgpack >=0.5.6, <=1.0.0',\n    # Please note:\n    # using any other version is not supported by borg development and\n    # any feedback related to issues caused by this will be ignored.\n]\n\n# note for package maintainers: if you package borgbackup for distribution,\n# please (if available) add pyfuse3 (preferably) or llfuse (not maintained any more)\n# as a *requirement*. \"borg mount\" needs one of them to work.\n# if neither is available, do not require it, most of borgbackup will work.\nextras_require = {\n    'llfuse': [\n        'llfuse >= 1.3.8',\n    ],\n    'pyfuse3': [\n        'pyfuse3 >= 3.1.1',\n    ],\n    'nofuse': [],\n}\n\ncompress_source = 'src/borg/compress.pyx'\ncrypto_ll_source = 'src/borg/crypto/low_level.pyx'\ncrypto_helpers = 'src/borg/crypto/_crypto_helpers.c'\nchunker_source = 'src/borg/chunker.pyx'\nhashindex_source = 'src/borg/hashindex.pyx'\nitem_source = 'src/borg/item.pyx'\nchecksums_source = 'src/borg/algorithms/checksums.pyx'\nplatform_posix_source = 'src/borg/platform/posix.pyx'\nplatform_linux_source = 'src/borg/platform/linux.pyx'\nplatform_syncfilerange_source = 'src/borg/platform/syncfilerange.pyx'\nplatform_darwin_source = 'src/borg/platform/darwin.pyx'\nplatform_freebsd_source = 'src/borg/platform/freebsd.pyx'\nplatform_windows_source = 'src/borg/platform/windows.pyx'\n\ncython_sources = [\n    compress_source,\n    crypto_ll_source,\n    chunker_source,\n    hashindex_source,\n    item_source,\n    checksums_source,\n\n    platform_posix_source,\n    platform_linux_source,\n    platform_syncfilerange_source,\n    platform_freebsd_source,\n    platform_darwin_source,\n    platform_windows_source,\n]\n\nif cythonize:\n    Sdist = sdist\nelse:\n    class Sdist(sdist):\n        def __init__(self, *args, **kwargs):\n            raise Exception('Cython is required to run sdist')\n\n    cython_c_files = [fn.replace('.pyx', '.c') for fn in cython_sources]\n    if not on_rtd and not all(os.path.exists(path) for path in cython_c_files):\n        raise ImportError('The GIT version of Borg needs Cython. Install Cython or use a released version.')\n\n\ndef rm(file):\n    try:\n        os.unlink(file)\n        print('rm', file)\n    except FileNotFoundError:\n        pass\n\n\nclass Clean(clean):\n    def run(self):\n        super().run()\n        for source in cython_sources:\n            genc = source.replace('.pyx', '.c')\n            rm(genc)\n            compiled_glob = source.replace('.pyx', '.cpython*')\n            for compiled in sorted(glob(compiled_glob)):\n                rm(compiled)\n\n\ncmdclass = {\n    'build_ext': build_ext,\n    'build_usage': setup_docs.build_usage,\n    'build_man': setup_docs.build_man,\n    'sdist': Sdist,\n    'clean': Clean,\n}\n\next_modules = []\nif not on_rtd:\n\n    def members_appended(*ds):\n        result = defaultdict(list)\n        for d in ds:\n            for k, v in d.items():\n                assert isinstance(v, list)\n                result[k].extend(v)\n        return result\n\n    try:\n        import pkgconfig as pc\n    except ImportError:\n        print('Warning: can not import pkgconfig python package.')\n        pc = None\n\n    crypto_ext_kwargs = members_appended(\n        dict(sources=[crypto_ll_source, crypto_helpers]),\n        setup_crypto.crypto_ext_kwargs(pc, system_prefix_openssl),\n        setup_crypto.b2_ext_kwargs(pc, prefer_system_libb2, system_prefix_libb2),\n    )\n\n    compress_ext_kwargs = members_appended(\n        dict(sources=[compress_source]),\n        setup_compress.lz4_ext_kwargs(pc, prefer_system_liblz4, system_prefix_liblz4),\n        setup_compress.zstd_ext_kwargs(pc, prefer_system_libzstd, system_prefix_libzstd,\n                                       multithreaded=False, legacy=False),\n    )\n\n    checksums_ext_kwargs = members_appended(\n        dict(sources=[checksums_source]),\n        setup_checksums.xxhash_ext_kwargs(pc, prefer_system_libxxhash, system_prefix_libxxhash),\n    )\n\n    ext_modules += [\n        Extension('borg.crypto.low_level', **crypto_ext_kwargs),\n        Extension('borg.compress', **compress_ext_kwargs),\n        Extension('borg.hashindex', [hashindex_source]),\n        Extension('borg.item', [item_source]),\n        Extension('borg.chunker', [chunker_source]),\n        Extension('borg.algorithms.checksums', **checksums_ext_kwargs),\n    ]\n\n    posix_ext = Extension('borg.platform.posix', [platform_posix_source])\n    linux_ext = Extension('borg.platform.linux', [platform_linux_source], libraries=['acl'])\n    syncfilerange_ext = Extension('borg.platform.syncfilerange', [platform_syncfilerange_source])\n    freebsd_ext = Extension('borg.platform.freebsd', [platform_freebsd_source])\n    darwin_ext = Extension('borg.platform.darwin', [platform_darwin_source])\n    windows_ext = Extension('borg.platform.windows', [platform_windows_source])\n\n    if not is_win32:\n        ext_modules.append(posix_ext)\n    else:\n        ext_modules.append(windows_ext)\n    if sys.platform == 'linux':\n        ext_modules.append(linux_ext)\n        ext_modules.append(syncfilerange_ext)\n    elif sys.platform.startswith('freebsd'):\n        ext_modules.append(freebsd_ext)\n    elif sys.platform == 'darwin':\n        ext_modules.append(darwin_ext)\n\n    # sometimes there's no need to cythonize\n    # this breaks chained commands like 'clean sdist'\n    cythonizing = len(sys.argv) > 1 and sys.argv[1] not in ('clean', 'egg_info', '--help-commands', '--version') \\\n                  and '--help' not in sys.argv[1:]\n\n    if cythonize and cythonizing:\n        cython_opts = dict(\n            # default language_level will be '3str' starting from Cython 3.0.0,\n            # but old cython versions (< 0.29) do not know that, thus we use 3 for now.\n            compiler_directives={'language_level': 3},\n        )\n        if not is_win32:\n            # compile .pyx extensions to .c in parallel, does not work on windows\n            cython_opts['nthreads'] = cpu_threads\n\n        # generate C code from Cython for ALL supported platforms, so we have them in the sdist.\n        # the sdist does not require Cython at install time, so we need all as C.\n        cythonize([posix_ext, linux_ext, syncfilerange_ext, freebsd_ext, darwin_ext, windows_ext], **cython_opts)\n        # generate C code from Cython for THIS platform (and for all platform-independent Cython parts).\n        ext_modules = cythonize(ext_modules, **cython_opts)\n\n\nsetup(\n    name='borgbackup',\n    use_scm_version={\n        'write_to': 'src/borg/_version.py',\n    },\n    author='The Borg Collective (see AUTHORS file)',\n    author_email='borgbackup@python.org',\n    url='https://borgbackup.readthedocs.io/',\n    description='Deduplicated, encrypted, authenticated and compressed backups',\n    long_description=setup_docs.long_desc_from_readme(),\n    license='BSD',\n    platforms=['Linux', 'MacOS X', 'FreeBSD', 'OpenBSD', 'NetBSD', ],\n    classifiers=[\n        'Development Status :: 3 - Alpha',\n        'Environment :: Console',\n        'Intended Audience :: System Administrators',\n        'License :: OSI Approved :: BSD License',\n        'Operating System :: POSIX :: BSD :: FreeBSD',\n        'Operating System :: POSIX :: BSD :: OpenBSD',\n        'Operating System :: POSIX :: BSD :: NetBSD',\n        'Operating System :: MacOS :: MacOS X',\n        'Operating System :: POSIX :: Linux',\n        'Programming Language :: Python',\n        'Programming Language :: Python :: 3',\n        'Programming Language :: Python :: 3.6',\n        'Programming Language :: Python :: 3.7',\n        'Programming Language :: Python :: 3.8',\n        'Programming Language :: Python :: 3.9',\n        'Topic :: Security :: Cryptography',\n        'Topic :: System :: Archiving :: Backup',\n    ],\n    packages=find_packages('src'),\n    package_dir={'': 'src'},\n    zip_safe=False,\n    entry_points={\n        'console_scripts': [\n            'borg = borg.archiver:main',\n            'borgfs = borg.archiver:main',\n        ]\n    },\n    # See also the MANIFEST.in file.\n    # We want to install all the files in the package directories...\n    include_package_data=True,\n    # ...except the source files which have been compiled (C extensions):\n    exclude_package_data={\n        '': ['*.c', '*.h', '*.pyx', ],\n    },\n    cmdclass=cmdclass,\n    ext_modules=ext_modules,\n    setup_requires=['setuptools_scm>=1.7'],\n    install_requires=install_requires,\n    extras_require=extras_require,\n    python_requires='>=3.6',\n)\n", "path": "setup.py"}]}