src/setup.py
changeset 686 385e3a12ee27
child 691 8454f9cda0ca
equal deleted inserted replaced
685:dc349ee44568 686:385e3a12ee27
       
     1 import os
       
     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 sys
       
     9 
       
    10 
       
    11 class osx_install_data(install_data):
       
    12     """
       
    13     On MacOS, the platform-specific lib dir is /System/Library/Framework/Python/.../
       
    14     which is wrong. Python 2.5 supplied with MacOS 10.5 has an Apple-specific fix
       
    15     for this in distutils.command.install_data#306. It fixes install_lib but not
       
    16     install_data, which is why we roll our own install_data class.
       
    17     """
       
    18 
       
    19     def finalize_options(self):
       
    20         """
       
    21         By the time finalize_options is called, install.install_lib is set to the
       
    22         fixed directory, so we set the installdir to install_lib. The
       
    23         install_data class uses ('install_data', 'install_dir') instead.
       
    24         """
       
    25         self.set_undefined_options('install', ('install_lib', 'install_dir'))
       
    26         install_data.finalize_options(self)
       
    27 
       
    28 def fullsplit(path, result=None):
       
    29     """
       
    30     Split a pathname into components (the opposite of os.path.join) in a
       
    31     platform-neutral way.
       
    32     """
       
    33     if result is None:
       
    34         result = []
       
    35     head, tail = os.path.split(path)
       
    36     if head == '':
       
    37         return [tail] + result
       
    38     if head == path:
       
    39         return result
       
    40     return fullsplit(head, [tail] + result)
       
    41 
       
    42 
       
    43 def launch_setup(setup_script_name, setup_script_args):
       
    44     """
       
    45     Start setup
       
    46     """
       
    47     if sys.platform == "darwin":
       
    48         cmdclasses = {'install_data': osx_install_data}
       
    49     else:
       
    50         cmdclasses = {'install_data': install_data}
       
    51 
       
    52 
       
    53     root_dir = os.path.dirname(__file__)
       
    54     if root_dir != '':
       
    55         os.chdir(root_dir)
       
    56     source_dirs = ['hdabo', 'hdalab']
       
    57 
       
    58     version_variables = {}
       
    59     try:
       
    60         with open(os.path.join(source_dirs[0], "__init__.py")) as f:
       
    61             code = compile(f.read(), "__init__.py", 'exec')
       
    62             exec(code, version_variables)
       
    63     except:
       
    64         pass
       
    65 
       
    66     version = version_variables['__version__']
       
    67 
       
    68     packages, data_files = [], []
       
    69 
       
    70     for source_dir in source_dirs:
       
    71         for dirpath, dirnames, filenames in os.walk(source_dir):
       
    72             # Ignore dirnames that start with '.'
       
    73             for i, dirname in enumerate(dirnames):
       
    74                 if dirname.startswith('.') or dirname.startswith('__pycache__'): del dirnames[i]
       
    75             if '__init__.py' in filenames:
       
    76                 packages.append('.'.join(fullsplit(dirpath)))
       
    77             elif filenames:
       
    78                 data_files.append([dirpath, [os.path.join(dirpath, f) for f in filenames]])
       
    79 
       
    80 
       
    81     # Tell distutils to put the data_files in platform-specific installation
       
    82     # locations. See here for an explanation:
       
    83     # http://groups.google.com/group/comp.lang.python/browse_thread/thread/35ec7b2fed36eaec/2105ee4d9e8042cb
       
    84     for scheme in INSTALL_SCHEMES.values():
       
    85         scheme['data'] = scheme['purelib']
       
    86 
       
    87     # Small hack for working with bdist_wininst.
       
    88     # See http://mail.python.org/pipermail/distutils-sig/2004-August/004134.html
       
    89     if len(sys.argv) > 1 and sys.argv[1] == 'bdist_wininst':
       
    90         for file_info in data_files:
       
    91             file_info[0] = '\\PURELIB\\%s' % file_info[0]
       
    92 
       
    93     #write MANIFEST.in
       
    94 
       
    95     with open("MANIFEST.in", "w") as m:
       
    96         m.write("exclude hdabo/config.py\n")
       
    97         m.write("exclude hdalab/config.py\n")
       
    98         m.write("include LICENSE\n")
       
    99         m.write("include README\n")
       
   100         m.write("include MANIFEST.in\n")
       
   101         for entry in data_files:
       
   102             file_list = entry[1]
       
   103             for filename in file_list:
       
   104                 m.write("include %s\n" % (filename))
       
   105 
       
   106     long_description = ''
       
   107     with open('README', 'r') as f:
       
   108         long_description = f.read()
       
   109 
       
   110     setup(
       
   111         script_name=setup_script_name,
       
   112         script_args=setup_script_args,
       
   113         name='hdalab',
       
   114         version=version,
       
   115         author='IRI',
       
   116         author_email='contact@iri.centrepompidou.fr',
       
   117         packages=packages,
       
   118         data_files=data_files,
       
   119         cmdclass=cmdclasses,
       
   120         scripts=[],
       
   121         url='http://www.iri.centrepompidou.fr/dev/hg/hdabo',
       
   122         license='CECILL-C',
       
   123         description='projet Irinotes',
       
   124         long_description=long_description,
       
   125         classifiers=[
       
   126             'Development Status :: 4 - Beta',
       
   127             'Environment :: Web Environment',
       
   128             'Framework :: Django',
       
   129             'Intended Audience :: Developers',
       
   130             'License :: Ceccil-B',
       
   131             'Operating System :: OS Independent',
       
   132             'Programming Language :: Python',
       
   133             'Topic :: Utilities'
       
   134         ],
       
   135     )
       
   136 
       
   137 
       
   138 if __name__ == "__main__":
       
   139 
       
   140     script_name = os.path.basename(sys.argv[0])
       
   141     script_args = sys.argv[1:]
       
   142 
       
   143     launch_setup(script_name, script_args)