-
Notifications
You must be signed in to change notification settings - Fork 7
/
setup.py
152 lines (140 loc) · 6.32 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# -*- coding: iso-8859-1 -*-
# -----------------------------------------------------------------------------
# setup.py - Setup script for kaa.base
# -----------------------------------------------------------------------------
# Copyright 2005-2012 Dirk Meyer, Jason Tackaberry
#
# This library is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License version
# 2.1 as published by the Free Software Foundation.
#
# This library is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301 USA
#
# -----------------------------------------------------------------------------
MODULE = 'base'
VERSION = '0.99.2'
# python imports
import sys
import os
import time
import platform
# We require python 2.6 or later, so complain if that isn't satisfied.
if sys.hexversion < 0x02060000:
print('Python 2.6 or later required.')
sys.exit(1)
# TODO: remove below at some suitable time in the future.
#
# Older version of kaa.base (0.6.0 or earlier) installed all package files
# directly under kaa/ whereas newer versions install under kaa/base/
#
# First chdir out of the src directory, which seems to confuse setuptools,
# and get a list of top-level kaa namespace paths.
cwd = os.getcwd()
os.chdir('/tmp')
paths = os.popen("%s -c 'import kaa; print \"\\x00\".join(kaa.__path__)' 2>/dev/null" % sys.executable).readline()
paths = paths.strip().split('\x00')
# We should not find a kaa.base module (e.g. rpc.py) in any of these paths.
# If we do, it means an old version is present.
conflicts = [p for p in paths if os.path.exists(os.path.join(p, 'rpc.py'))]
if conflicts:
print('ERROR: detected conflicting files from an old kaa.base version.\n\n'
"To fix, you'll need to run:\n"
' $ sudo rm -rf build %s\n\n'
"Once you delete #2, you'll need to reinstall all the kaa\n"
'sub-modules you use.' % ' '.join(conflicts))
sys.exit(1)
os.chdir(cwd)
# If kaa.base is already installed as an egg and we're now attempting to
# install without --egg, we error out now, because this won't work (the
# egg package will always get imported).
eggs = [p for p in paths if '.egg/' in p]
if eggs and 'install' in sys.argv and not '--egg' in sys.argv:
print('ERROR: attempting to install a non-egg version of kaa.base, but the following\n'
'kaa eggs were found:\n')
for egg in eggs:
print(' * ' + egg)
print('\nEither remove the current kaa egg(s) or install now with --egg')
sys.exit(1)
# Remove anything to do with kaa from the path. We want to use kaa.distribution
# from the source tree, not any previously installed kaa.base.
#
# Moreover, any installed kaa eggs will be a problem, because they install
# kaa/__init__.py stubs that declare the kaa namespace _and_ import kaa.base,
# which could get imported when kaa.distribution.core imports setuptools (because
# importing setuptools implicitly imports all declared namespace packages).
#
# So to avoid any problems, remove anything kaa from the path, since we don't
# need it.
[sys.path.remove(x) for x in sys.path[:] if '/kaa' in x and x != os.getcwd()]
# Now import the src directory and masquerade it as kaa and kaa.base modules so
# we can import distribution.core.
import src
sys.modules['kaa'] = sys.modules['kaa.base'] = src
# And now import it from the source tree.
from kaa.distribution.core import Extension, setup
extensions = []
objectrow_ext = Extension('kaa.base._objectrow', ['src/extensions/objectrow.c'])
if objectrow_ext.has_python_h():
extensions.append(objectrow_ext)
# Automagically construct version. If installing from a git clone, the
# version is based on the number of revisions since the last tag. Otherwise,
# if PKG-INFO exists, assume it's a dist tarball and pull the version from
# that.
version = VERSION
if os.path.isdir('.git'):
# Fetch all revisions since last tag. The first item is the current HEAD object name
# and the last is the tag object name.
revs = os.popen('git rev-list --all | grep -B9999 `git rev-list --tags --max-count=1`').read().splitlines()
if len(revs) > 1:
# We're at least one commit past the last tag, so this is considered a
# dev release.
version = '%sdev-%d-%s' % (VERSION, len(revs)-1, revs[0][:8])
elif os.path.isfile('PKG-INFO'):
ver = [l.split(':')[1].strip() for l in open('PKG-INFO') if l.startswith('Version')]
if ver:
version = ver[0]
else:
# Lack of PKG-INFO means installation was not from an official dist bundle,
# so treat it as a development version.
version += 'dev'
setup(
module = MODULE,
version = version,
license = 'LGPL',
url = 'http://freevo.github.io/kaa-base/',
summary = 'An application framework specializing in asynchronous programming.',
description = 'kaa.base is an LGPL-licensed generic application framework, providing the '
'foundation for other modules within Kaa, and can be used in any type of project, '
'from small event-driven tools, to larger, complex applications.',
rpminfo = {
'requires': 'glib2 >= 2.6.0, libxml2-python >= 2.6.0',
'build_requires': 'glib2-devel >= 2.6.0, python-devel >= 2.6.0'
},
ext_modules = extensions,
opts_2to3 = {
# Everything listed in 'exclude' is imported directly here (for distribution),
# so it must compile with both python 2.6 and 3.x.
'exclude': ['distribution/*', 'saxutils.py', 'strutils.py'],
'nofix': {
'*.py': ['import'],
'utils.py': ['filter'],
'io.py': ['throw'],
'rpc.py': ['throw'],
'async.py': ['throw']
}
},
auto_changelog = True,
# Don't declare kaa.base as part of the kaa namespace. Doing so will
# suppress installation of kaa/__init__.py when installing with pip. This
# needs to be installed with kaa.base in order to make our namespace hack
# work (where everything in kaa.base is under kaa).
# namespace_packages = ['kaa']
)