forked from seb-m/pyinotify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·118 lines (100 loc) · 3.46 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
112
113
114
115
116
117
118
#!/usr/bin/env python
# Set True to force compile native C-coded extension providing direct access
# to inotify's syscalls. If set to False this extension will only be compiled
# if no inotify interface from ctypes is found.
compile_ext_mod = False
# import statements
import os
import sys
import distutils.extension
from distutils.util import get_platform
try:
# First try to load most advanced setuptools setup.
from setuptools import setup
except:
# Fall back if setuptools is not installed.
from distutils.core import setup
platform = get_platform()
# check Python's version
if sys.version_info < (2, 4):
sys.stderr.write('This module requires at least Python 2.4\n')
sys.exit(1)
# check linux platform
if not platform.startswith('linux') and not platform.startswith('freebsd'):
sys.stderr.write("inotify is not available on %s\n" % platform)
sys.exit(1)
classif = [
'Development Status :: 5 - Production/Stable',
'Environment :: Console',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Natural Language :: English',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python',
'Programming Language :: Python :: 2.4',
'Programming Language :: Python :: 2.5',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.0',
'Programming Language :: Python :: 3.1',
'Programming Language :: Python :: 3.2',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Topic :: Software Development :: Libraries :: Python Modules',
'Topic :: System :: Filesystems',
'Topic :: System :: Monitoring',
]
# Select branch
if sys.version_info >= (3, 0):
package_dir = {'': 'python3'}
else:
package_dir = {'': 'python2'}
def should_compile_ext_mod():
try:
import ctypes
import ctypes.util
except:
return True
try_libc_name = 'c'
if platform.startswith('freebsd'):
try_libc_name = 'inotify'
libc_name = None
try:
libc_name = ctypes.util.find_library(try_libc_name)
except:
pass # Will attemp to load it with None anyway.
libc = ctypes.CDLL(libc_name)
# Eventually check that libc has needed inotify bindings.
if (not hasattr(libc, 'inotify_init') or
not hasattr(libc, 'inotify_add_watch') or
not hasattr(libc, 'inotify_rm_watch')):
return True
return False
ext_mod = []
if compile_ext_mod or should_compile_ext_mod():
# add -fpic if x86_64 arch
if platform in ["linux-x86_64"]:
os.environ["CFLAGS"] = "-fpic"
# sources for ext module
ext_mod_src = ['common/inotify_syscalls.c']
# dst for ext module
ext_mod.append(distutils.extension.Extension('inotify_syscalls',
ext_mod_src))
setup(
name='pyinotify',
version='0.9.6',
description='Linux filesystem events monitoring',
author='Sebastien Martini',
author_email='[email protected]',
license='MIT License',
platforms='Linux',
classifiers=classif,
url='http://github.com/seb-m/pyinotify',
download_url='http://pypi.python.org/pypi/pyinotify',
ext_modules=ext_mod,
py_modules=['pyinotify'],
package_dir=package_dir,
)