fixed some bugs
[django-tables2.git] / setup.py
1 # -*- coding: utf8 -*-
2 try:
3     from setuptools import setup
4 except ImportError:
5     from distutils.core import setup
6 from distutils.command.install_data import install_data
7 from distutils.command.install import INSTALL_SCHEMES
8 import os
9 import sys
10
11 class osx_install_data(install_data):
12     # On MacOS, the platform-specific lib dir is /System/Library/Framework/Python/.../
13     # which is wrong. Python 2.5 supplied with MacOS 10.5 has an Apple-specific fix
14     # for this in distutils.command.install_data#306. It fixes install_lib but not
15     # install_data, which is why we roll our own install_data class.
16
17     def finalize_options(self):
18         # By the time finalize_options is called, install.install_lib is set to the
19         # fixed directory, so we set the installdir to install_lib. The
20         # install_data class uses ('install_data', 'install_dir') instead.
21         self.set_undefined_options('install', ('install_lib', 'install_dir'))
22         install_data.finalize_options(self)
23
24 if sys.platform == "darwin":
25     cmdclasses = {'install_data': osx_install_data}
26 else:
27     cmdclasses = {'install_data': install_data}
28
29 def fullsplit(path, result=None):
30     """
31     Split a pathname into components (the opposite of os.path.join) in a
32     platform-neutral way.
33     """
34     if result is None:
35         result = []
36     head, tail = os.path.split(path)
37     if head == '':
38         return [tail] + result
39     if head == path:
40         return result
41     return fullsplit(head, [tail] + result)
42
43 # Tell distutils to put the data_files in platform-specific installation
44 # locations. See here for an explanation:
45 # http://groups.google.com/group/comp.lang.python/browse_thread/thread/35ec7b2fed36eaec/2105ee4d9e8042cb
46 for scheme in INSTALL_SCHEMES.values():
47     scheme['data'] = scheme['purelib']
48
49 # Compile the list of packages available, because distutils doesn't have
50 # an easy way to do this.
51 packages, data_files = [], []
52 root_dir = os.path.dirname(__file__)
53 if root_dir != '':
54     os.chdir(root_dir)
55 package_dir = 'django_tables'
56
57 for dirpath, dirnames, filenames in os.walk(package_dir):
58     # Ignore dirnames that start with '.'
59     for i, dirname in enumerate(dirnames):
60         if dirname.startswith('.'): del dirnames[i]
61     if '__init__.py' in filenames:
62         packages.append('.'.join(fullsplit(dirpath)))
63     elif filenames:
64         data_files.append([dirpath, [os.path.join(dirpath, f) for f in filenames]])
65
66 # Small hack for working with bdist_wininst.
67 # See http://mail.python.org/pipermail/distutils-sig/2004-August/004134.html
68 if len(sys.argv) > 1 and sys.argv[1] == 'bdist_wininst':
69     for file_info in data_files:
70         file_info[0] = '\\PURELIB\\%s' % file_info[0]
71
72 setup(
73     name = 'django-tables',
74     version = __import__(package_dir).get_version().replace(' ', '-'),
75     description = 'Table framework for Django',
76     author = 'Bradley Ayers',
77     author_email = 'bradley.ayers@gmail.com',
78     url = '',
79     classifiers = [
80         'Environment :: Web Environment',
81         'Framework :: Django',
82         'Intended Audience :: Developers',
83         'License :: OSI Approved :: BSD License',
84         'Operating System :: OS Independent',
85         'Programming Language :: Python',
86         'Topic :: Internet :: WWW/HTTP',
87         'Topic :: Software Development :: Libraries',
88     ],
89     packages = packages,
90     data_files = data_files,
91     cmdclass = cmdclasses,
92     requires = ['Django(>=1.1)'],
93     install_requires = ['Django>=1.1']
94 )