forked from python-pendulum/pendulum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
111 lines (87 loc) · 2.96 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# -*- coding: utf-8 -*-
import os
import sys
from setuptools import setup, find_packages, Extension
from distutils.errors import (CCompilerError, DistutilsExecError,
DistutilsPlatformError)
from distutils.command.build_ext import build_ext
try:
FileNotFoundError
except NameError:
FileNotFoundError = IOError # py2k
def get_version():
basedir = os.path.dirname(__file__)
with open(os.path.join(basedir, 'pendulum/version.py')) as f:
variables = {}
exec(f.read(), variables)
version = variables.get('VERSION')
if version:
return version
raise RuntimeError('No version info found.')
__version__ = get_version()
# C Extensions
with_extensions = os.getenv('PENDULUM_EXTENSIONS', None)
if with_extensions == '1' or with_extensions is None:
with_extensions = True
if with_extensions == '0' or hasattr(sys, 'pypy_version_info'):
with_extensions = False
extensions = []
if with_extensions:
extensions = [
Extension('pendulum._extensions._helpers',
['pendulum/_extensions/_helpers.c'],
extra_compile_args=['-Wno-unused-function']),
]
class BuildFailed(Exception):
pass
class ve_build_ext(build_ext):
# This class allows C extension building to fail.
def run(self):
try:
build_ext.run(self)
except (DistutilsPlatformError, FileNotFoundError):
raise BuildFailed()
def build_extension(self, ext):
try:
build_ext.build_extension(self, ext)
except (CCompilerError, DistutilsExecError,
DistutilsPlatformError, ValueError):
raise BuildFailed()
kwargs = dict(
name='pendulum',
license='MIT',
version=__version__,
description='Python datetimes made easy.',
long_description=open('README.rst').read(),
author='Sébastien Eustace',
author_email='sebastien@eustace.io',
url='https://github.com/sdispater/pendulum',
download_url='https://github.com/sdispater/pendulum/archive/%s.tar.gz' % __version__,
packages=find_packages(exclude=['tests']),
install_requires=[
'tzlocal',
'python-dateutil',
'pytzdata',
],
include_package_data=True,
tests_require=['pytest'],
test_suite='nose.collector',
classifiers=[
'Intended Audience :: Developers',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Topic :: Software Development :: Libraries :: Python Modules',
],
)
if extensions:
kwargs['ext_modules'] = extensions
kwargs['cmdclass'] = dict(build_ext=ve_build_ext)
try:
setup(**kwargs)
except BuildFailed:
print("************************************************************")
print("Cannot compile C accelerator module, use pure python version")
print("************************************************************")
del kwargs['ext_modules']
del kwargs['cmdclass']
setup(**kwargs)