-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
setup.py
96 lines (83 loc) · 2.98 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
#!/usr/bin/env python
import sys
import glob
import warnings
from distutils.command.build_ext import build_ext
from distutils.core import setup
from distutils.extension import Extension
from fallocate import __version__
def find_in_file(filename, s):
try:
for line in open(filename):
if s in line:
return True
except IOError:
return False
def find_in_glob(g, s):
for filename in glob.glob(g):
if find_in_file(filename, s):
return True
return False
def with_prefix(prefixen, func):
def newfunc(*args):
for prefix in prefixen:
if func(prefix + args[0], *args[1:]):
return True
return False
return newfunc
defs = []
if sys.platform == "darwin":
XCODE_PREFIX = "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk"
find_in_darwin_file = with_prefix(['', XCODE_PREFIX], find_in_file)
if find_in_darwin_file("/usr/include/sys/fcntl.h", "F_ALLOCATECONTIG"):
defs.append(("HAVE_APPLE_F_ALLOCATECONTIG", None))
else:
warnings.warn(
"We can't find F_ALLOCATECONTIG on a Mac! This is impossible!")
else:
if find_in_glob(
"/usr/include/*/bits/fcntl*.h", "fallocate") or find_in_glob(
"/usr/include/bits/fcntl*.h", "fallocate"):
defs.append(("HAVE_FALLOCATE", None))
if find_in_file("/usr/include/fcntl.h", "posix_fallocate"):
defs.append(("HAVE_POSIX_FALLOCATE", None))
if find_in_file("/usr/include/fcntl.h", "posix_fadvise"):
defs.append(("HAVE_POSIX_FADVISE", None))
if sum(1 for x in defs if 'ALLOCATE' in x) == 0:
warnings.warn(
"Setup.py cannot find a fallocate() or equivalent on your platform ({0}).".
format(sys.platform))
_fallocate = Extension(
'fallocate/_fallocate',
sources=['fallocate/_fallocatemodule.c'],
define_macros=defs)
setup(
name="fallocate",
version=__version__,
description="Module to expose posix_fallocate(3), posix_fadvise(3) and fallocate(2)",
long_description=open("README.rst", "r").read(),
author="I.S. van Oostveen",
author_email="[email protected]",
url="https://github.com/trbs/fallocate",
license="Python Software Foundation License",
keywords="posix_fallocate posix_fadvise fallocate",
classifiers=[
'Development Status :: 5 - Production/Stable',
'Programming Language :: Python',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Topic :: Software Development :: Libraries :: Python Modules',
'Intended Audience :: Developers',
'Operating System :: POSIX :: Linux',
'Operating System :: MacOS :: MacOS X',
'License :: OSI Approved :: Python Software Foundation License',
],
packages=[
'fallocate',
],
ext_modules=[_fallocate],
cmdclass={
'build_ext': build_ext,
},
)