Fix tests on older versions of Python 3.
[jelmer/dulwich.git] / setup.py
1 #!/usr/bin/python
2 # encoding: utf-8
3 # Setup file for dulwich
4 # Copyright (C) 2008-2016 Jelmer Vernooij <jelmer@jelmer.uk>
5
6 try:
7     from setuptools import setup, Extension
8 except ImportError:
9     from distutils.core import setup, Extension
10     has_setuptools = False
11 else:
12     has_setuptools = True
13 from distutils.core import Distribution
14 import os
15 import sys
16
17 dulwich_version_string = '0.19.7'
18
19 include_dirs = []
20 # Windows MSVC support
21 if sys.platform == 'win32' and sys.version_info[:2] < (3, 6):
22     # Include dulwich/ for fallback stdint.h
23     include_dirs.append('dulwich')
24
25
26 class DulwichDistribution(Distribution):
27
28     def is_pure(self):
29         if self.pure:
30             return True
31
32     def has_ext_modules(self):
33         return not self.pure
34
35     global_options = Distribution.global_options + [
36         ('pure', None, "use pure Python code instead of C "
37                        "extensions (slower on CPython)")]
38
39     pure = False
40
41
42 if sys.platform == 'darwin' and os.path.exists('/usr/bin/xcodebuild'):
43     # XCode 4.0 dropped support for ppc architecture, which is hardcoded in
44     # distutils.sysconfig
45     import subprocess
46     p = subprocess.Popen(
47         ['/usr/bin/xcodebuild', '-version'], stdout=subprocess.PIPE,
48         stderr=subprocess.PIPE, env={})
49     out, err = p.communicate()
50     for line in out.splitlines():
51         line = line.decode("utf8")
52         # Also parse only first digit, because 3.2.1 can't be parsed nicely
53         if (line.startswith('Xcode') and
54                 int(line.split()[1].split('.')[0]) >= 4):
55             os.environ['ARCHFLAGS'] = ''
56
57 tests_require = ['fastimport']
58
59
60 if '__pypy__' not in sys.modules and not sys.platform == 'win32':
61     tests_require.extend([
62         'gevent', 'geventhttpclient', 'mock', 'setuptools>=17.1'])
63
64
65 ext_modules = [
66     Extension('dulwich._objects', ['dulwich/_objects.c'],
67               include_dirs=include_dirs),
68     Extension('dulwich._pack', ['dulwich/_pack.c'],
69               include_dirs=include_dirs),
70     Extension('dulwich._diff_tree', ['dulwich/_diff_tree.c'],
71               include_dirs=include_dirs),
72 ]
73
74 setup_kwargs = {}
75
76 if has_setuptools:
77     setup_kwargs['extras_require'] = {
78         'fastimport': ['fastimport'],
79         'https': ['urllib3[secure]>=1.21'],
80         }
81     setup_kwargs['install_requires'] = ['urllib3>=1.21', 'certifi']
82     setup_kwargs['include_package_data'] = True
83     setup_kwargs['test_suite'] = 'dulwich.tests.test_suite'
84     setup_kwargs['tests_require'] = tests_require
85
86 with open('README.md', 'r') as f:
87     description = f.read()
88
89 setup(name='dulwich',
90       author="Jelmer Vernooij",
91       author_email="jelmer@jelmer.uk",
92       url="https://www.dulwich.io/",
93       long_description=description,
94       description="Python Git Library",
95       version=dulwich_version_string,
96       license='Apachev2 or later or GPLv2',
97       project_urls={
98           "Bug Tracker": "https://github.com/dulwich/dulwich/issues",
99           "Repository": "https://www.dulwich.io/code/",
100           "GitHub": "https://github.com/dulwich/dulwich",
101       },
102       keywords="git vcs",
103       packages=['dulwich', 'dulwich.tests', 'dulwich.tests.compat',
104                 'dulwich.contrib'],
105       package_data={'': ['../docs/tutorial/*.txt']},
106       scripts=['bin/dulwich', 'bin/dul-receive-pack', 'bin/dul-upload-pack'],
107       ext_modules=ext_modules,
108       distclass=DulwichDistribution,
109       classifiers=[
110           'Development Status :: 4 - Beta',
111           'License :: OSI Approved :: Apache Software License',
112           'Programming Language :: Python :: 2.7',
113           'Programming Language :: Python :: 3.3',
114           'Programming Language :: Python :: 3.4',
115           'Programming Language :: Python :: 3.5',
116           'Programming Language :: Python :: 3.6',
117           'Programming Language :: Python :: Implementation :: CPython',
118           'Programming Language :: Python :: Implementation :: PyPy',
119           'Operating System :: POSIX',
120           'Operating System :: Microsoft :: Windows',
121           'Topic :: Software Development :: Version Control',
122       ],
123       **setup_kwargs
124       )