contrib/python-zstandard/setup.py
changeset 43994 de7838053207
parent 42937 69de49c4e39c
child 44147 5e84a96d865b
equal deleted inserted replaced
43993:873d0fecb9a3 43994:de7838053207
    14 
    14 
    15 # Need change in 1.10 for ffi.from_buffer() to handle all buffer types
    15 # Need change in 1.10 for ffi.from_buffer() to handle all buffer types
    16 # (like memoryview).
    16 # (like memoryview).
    17 # Need feature in 1.11 for ffi.gc() to declare size of objects so we avoid
    17 # Need feature in 1.11 for ffi.gc() to declare size of objects so we avoid
    18 # garbage collection pitfalls.
    18 # garbage collection pitfalls.
    19 MINIMUM_CFFI_VERSION = '1.11'
    19 MINIMUM_CFFI_VERSION = "1.11"
    20 
    20 
    21 try:
    21 try:
    22     import cffi
    22     import cffi
    23 
    23 
    24     # PyPy (and possibly other distros) have CFFI distributed as part of
    24     # PyPy (and possibly other distros) have CFFI distributed as part of
    25     # them. The install_requires for CFFI below won't work. We need to sniff
    25     # them. The install_requires for CFFI below won't work. We need to sniff
    26     # out the CFFI version here and reject CFFI if it is too old.
    26     # out the CFFI version here and reject CFFI if it is too old.
    27     cffi_version = LooseVersion(cffi.__version__)
    27     cffi_version = LooseVersion(cffi.__version__)
    28     if cffi_version < LooseVersion(MINIMUM_CFFI_VERSION):
    28     if cffi_version < LooseVersion(MINIMUM_CFFI_VERSION):
    29         print('CFFI 1.11 or newer required (%s found); '
    29         print(
    30               'not building CFFI backend' % cffi_version,
    30             "CFFI 1.11 or newer required (%s found); "
    31               file=sys.stderr)
    31             "not building CFFI backend" % cffi_version,
       
    32             file=sys.stderr,
       
    33         )
    32         cffi = None
    34         cffi = None
    33 
    35 
    34 except ImportError:
    36 except ImportError:
    35     cffi = None
    37     cffi = None
    36 
    38 
    38 
    40 
    39 SUPPORT_LEGACY = False
    41 SUPPORT_LEGACY = False
    40 SYSTEM_ZSTD = False
    42 SYSTEM_ZSTD = False
    41 WARNINGS_AS_ERRORS = False
    43 WARNINGS_AS_ERRORS = False
    42 
    44 
    43 if os.environ.get('ZSTD_WARNINGS_AS_ERRORS', ''):
    45 if os.environ.get("ZSTD_WARNINGS_AS_ERRORS", ""):
    44     WARNINGS_AS_ERRORS = True
    46     WARNINGS_AS_ERRORS = True
    45 
    47 
    46 if '--legacy' in sys.argv:
    48 if "--legacy" in sys.argv:
    47     SUPPORT_LEGACY = True
    49     SUPPORT_LEGACY = True
    48     sys.argv.remove('--legacy')
    50     sys.argv.remove("--legacy")
    49 
    51 
    50 if '--system-zstd' in sys.argv:
    52 if "--system-zstd" in sys.argv:
    51     SYSTEM_ZSTD = True
    53     SYSTEM_ZSTD = True
    52     sys.argv.remove('--system-zstd')
    54     sys.argv.remove("--system-zstd")
    53 
    55 
    54 if '--warnings-as-errors' in sys.argv:
    56 if "--warnings-as-errors" in sys.argv:
    55     WARNINGS_AS_ERRORS = True
    57     WARNINGS_AS_ERRORS = True
    56     sys.argv.remove('--warning-as-errors')
    58     sys.argv.remove("--warning-as-errors")
    57 
    59 
    58 # Code for obtaining the Extension instance is in its own module to
    60 # Code for obtaining the Extension instance is in its own module to
    59 # facilitate reuse in other projects.
    61 # facilitate reuse in other projects.
    60 extensions = [
    62 extensions = [
    61     setup_zstd.get_c_extension(name='zstd',
    63     setup_zstd.get_c_extension(
    62                                support_legacy=SUPPORT_LEGACY,
    64         name="zstd",
    63                                system_zstd=SYSTEM_ZSTD,
    65         support_legacy=SUPPORT_LEGACY,
    64                                warnings_as_errors=WARNINGS_AS_ERRORS),
    66         system_zstd=SYSTEM_ZSTD,
       
    67         warnings_as_errors=WARNINGS_AS_ERRORS,
       
    68     ),
    65 ]
    69 ]
    66 
    70 
    67 install_requires = []
    71 install_requires = []
    68 
    72 
    69 if cffi:
    73 if cffi:
    70     import make_cffi
    74     import make_cffi
       
    75 
    71     extensions.append(make_cffi.ffi.distutils_extension())
    76     extensions.append(make_cffi.ffi.distutils_extension())
    72     install_requires.append('cffi>=%s' % MINIMUM_CFFI_VERSION)
    77     install_requires.append("cffi>=%s" % MINIMUM_CFFI_VERSION)
    73 
    78 
    74 version = None
    79 version = None
    75 
    80 
    76 with open('c-ext/python-zstandard.h', 'r') as fh:
    81 with open("c-ext/python-zstandard.h", "r") as fh:
    77     for line in fh:
    82     for line in fh:
    78         if not line.startswith('#define PYTHON_ZSTANDARD_VERSION'):
    83         if not line.startswith("#define PYTHON_ZSTANDARD_VERSION"):
    79             continue
    84             continue
    80 
    85 
    81         version = line.split()[2][1:-1]
    86         version = line.split()[2][1:-1]
    82         break
    87         break
    83 
    88 
    84 if not version:
    89 if not version:
    85     raise Exception('could not resolve package version; '
    90     raise Exception("could not resolve package version; " "this should never happen")
    86                     'this should never happen')
       
    87 
    91 
    88 setup(
    92 setup(
    89     name='zstandard',
    93     name="zstandard",
    90     version=version,
    94     version=version,
    91     description='Zstandard bindings for Python',
    95     description="Zstandard bindings for Python",
    92     long_description=open('README.rst', 'r').read(),
    96     long_description=open("README.rst", "r").read(),
    93     url='https://github.com/indygreg/python-zstandard',
    97     url="https://github.com/indygreg/python-zstandard",
    94     author='Gregory Szorc',
    98     author="Gregory Szorc",
    95     author_email='gregory.szorc@gmail.com',
    99     author_email="gregory.szorc@gmail.com",
    96     license='BSD',
   100     license="BSD",
    97     classifiers=[
   101     classifiers=[
    98         'Development Status :: 4 - Beta',
   102         "Development Status :: 4 - Beta",
    99         'Intended Audience :: Developers',
   103         "Intended Audience :: Developers",
   100         'License :: OSI Approved :: BSD License',
   104         "License :: OSI Approved :: BSD License",
   101         'Programming Language :: C',
   105         "Programming Language :: C",
   102         'Programming Language :: Python :: 2.7',
   106         "Programming Language :: Python :: 2.7",
   103         'Programming Language :: Python :: 3.5',
   107         "Programming Language :: Python :: 3.5",
   104         'Programming Language :: Python :: 3.6',
   108         "Programming Language :: Python :: 3.6",
   105         'Programming Language :: Python :: 3.7',
   109         "Programming Language :: Python :: 3.7",
       
   110         "Programming Language :: Python :: 3.8",
   106     ],
   111     ],
   107     keywords='zstandard zstd compression',
   112     keywords="zstandard zstd compression",
   108     packages=['zstandard'],
   113     packages=["zstandard"],
   109     ext_modules=extensions,
   114     ext_modules=extensions,
   110     test_suite='tests',
   115     test_suite="tests",
   111     install_requires=install_requires,
   116     install_requires=install_requires,
       
   117     tests_require=["hypothesis"],
   112 )
   118 )