src/ldt/setup.py
changeset 189 08e6b5dbfc93
parent 167 fe00e7302efe
child 627 f5c55582565d
equal deleted inserted replaced
188:74bad93d3cb7 189:08e6b5dbfc93
     1 import os
     1 import os
       
     2 from distutils.core import setup
       
     3 from distutils.command.install_data import install_data
       
     4 from distutils.command.install import INSTALL_SCHEMES
       
     5 import sys
     2 
     6 
     3 from distribute_setup import use_setuptools
     7 class osx_install_data(install_data):
     4 use_setuptools()
     8     # On MacOS, the platform-specific lib dir is /System/Library/Framework/Python/.../
       
     9     # which is wrong. Python 2.5 supplied with MacOS 10.5 has an Apple-specific fix
       
    10     # for this in distutils.command.install_data#306. It fixes install_lib but not
       
    11     # install_data, which is why we roll our own install_data class.
       
    12     
       
    13     def finalize_options(self):
       
    14         # By the time finalize_options is called, install.install_lib is set to the
       
    15         # fixed directory, so we set the installdir to install_lib. The
       
    16         # install_data class uses ('install_data', 'install_dir') instead.
       
    17         self.set_undefined_options('install', ('install_lib', 'install_dir'))
       
    18         install_data.finalize_options(self)
     5 
    19 
     6 from setuptools import setup
    20 if sys.platform == "darwin": 
       
    21     cmdclasses = {'install_data': osx_install_data} 
       
    22 else: 
       
    23     cmdclasses = {'install_data': install_data} 
     7 
    24 
     8 ROOT_DIR = os.path.dirname(__file__)
    25 
     9 SOURCE_DIR = os.path.join(ROOT_DIR, 'ldt')
    26 root_dir = os.path.dirname(__file__)
       
    27 if root_dir != '':
       
    28     os.chdir(root_dir)
       
    29 source_dir = 'ldt'
    10 
    30 
    11 version_variables = {}
    31 version_variables = {}
    12 try:
    32 try:
    13     execfile(os.path.join(SOURCE_DIR, "__init__.py"), version_variables)
    33     execfile(os.path.join(source_dir, "__init__.py"), version_variables)
    14 except:
    34 except:
    15     pass
    35     pass
    16 
    36 
    17 version = version_variables['__version__']
    37 version = version_variables['__version__']
    18 
    38 
    19 def full_split(path, result=None):
    39 def fullsplit(path, result=None):
    20     """
    40     """
    21     Split a pathname into components (the opposite of os.path.join) in a
    41     Split a pathname into components (the opposite of os.path.join) in a
    22     platform-neutral way.
    42     platform-neutral way.
    23     """
    43     """
    24     if result is None:
    44     if result is None:
    26     head, tail = os.path.split(path)
    46     head, tail = os.path.split(path)
    27     if head == '':
    47     if head == '':
    28         return [tail] + result
    48         return [tail] + result
    29     if head == path:
    49     if head == path:
    30         return result
    50         return result
    31     return full_split(head, [tail] + result)
    51     return fullsplit(head, [tail] + result)
    32 
    52 
    33 packages, data_files, path_processed = [], {}, []
    53 packages, data_files = [], []
    34 
    54 
    35 #TODO : uses find_packages form setuptools and teh mercurial extension
       
    36 
    55 
    37 for dirpath, dirnames, filenames in os.walk(SOURCE_DIR, True):
    56 for dirpath, dirnames, filenames in os.walk(source_dir):
    38     # Ignore dirnames that start with '.'
    57     # Ignore dirnames that start with '.'
    39     if dirpath in path_processed:
       
    40         continue
       
    41     path_processed.append(dirpath)
       
    42     for i, dirname in enumerate(dirnames):
    58     for i, dirname in enumerate(dirnames):
    43         if dirname.startswith('.'): del dirnames[i]
    59         if dirname.startswith('.'): del dirnames[i]
    44     if '__init__.py' in filenames:
    60     if '__init__.py' in filenames:
    45         packages.append('.'.join(full_split(dirpath)))
    61         packages.append('.'.join(fullsplit(dirpath)))
    46     else:
    62     elif filenames:
    47         new_data_files = []
    63         data_files.append([dirpath, [os.path.join(dirpath, f) for f in filenames]])
    48         base_path_list = full_split(dirpath)[:-1]
    64 
    49         base_path = "/".join(base_path_list) + "/"
    65 
    50         key = '.'.join(base_path_list)
    66 # Tell distutils to put the data_files in platform-specific installation
    51         for ldirpath, ldirnames, lfilenames in os.walk(dirpath):
    67 # locations. See here for an explanation:
    52             path_processed.append(ldirpath)
    68 # http://groups.google.com/group/comp.lang.python/browse_thread/thread/35ec7b2fed36eaec/2105ee4d9e8042cb
    53             new_data_files.extend([os.path.join(ldirpath[len(base_path):], f) for f in lfilenames])
    69 for scheme in INSTALL_SCHEMES.values():
    54         data_files.setdefault(key, []).extend(new_data_files)
    70     scheme['data'] = scheme['purelib']
       
    71 
       
    72 # Small hack for working with bdist_wininst.
       
    73 # See http://mail.python.org/pipermail/distutils-sig/2004-August/004134.html
       
    74 if len(sys.argv) > 1 and sys.argv[1] == 'bdist_wininst':
       
    75     for file_info in data_files:
       
    76         file_info[0] = '\\PURELIB\\%s' % file_info[0]
    55 
    77 
    56 #write MANIFEST.in
    78 #write MANIFEST.in
    57 
    79 
    58 m = open("MANIFEST.in", "w")
    80 with open("MANIFEST.in", "w") as m:    
       
    81     m.write("include CHANGES\n")
       
    82     m.write("include LICENSE\n")
       
    83     m.write("include README\n")
       
    84     m.write("include MANIFEST.in\n")
       
    85     for entry in data_files:
       
    86         file_list = entry[1]
       
    87         for filename in file_list:
       
    88             m.write("include %s\n" % (filename))
    59 
    89 
    60 m.write("exclude MANIFEST.in\n")
       
    61 for key, file_list in data_files.iteritems():
       
    62     for filename in file_list:
       
    63         m.write("include %s/%s\n" % (key.replace(".", "/"), filename))
       
    64 m.close()
       
    65 
    90 
    66 setup(
    91 setup(
    67     name='ldt',
    92     name='ldt',
    68     version=version,
    93     version=version,
    69     author='Yves-Marie Haussonne (IRI)',
    94     author='IRI',
    70     author_email='contact@iri.centrepompidou.fr',
    95     author_email='contact@iri.centrepompidou.fr',
    71     packages=packages,
    96     packages=packages,
    72     package_data=data_files,
    97     data_files=data_files,
       
    98     cmdclass = cmdclasses,
    73     scripts=[],
    99     scripts=[],
    74     url='https://www.iri.centrepompidou.fr/dev/hg/platform',
   100     url='http://www.iri.centrepompidou.fr/dev/hg/platform',
    75     license='LICENSE.txt',
   101     license='LICENSE.txt',
    76     description='Platform ldt',
   102     description='Platform ldt',
    77     long_description=open('README.txt').read(),
   103     long_description=open('README').read(),
    78     zip_safe=False,
       
    79     classifiers=['Development Status :: 5 - Production/Stable',
   104     classifiers=['Development Status :: 5 - Production/Stable',
    80                    'Environment :: Web Environment',
   105                    'Environment :: Web Environment',
    81                    'Framework :: Django',
   106                    'Framework :: Django',
    82                    'Intended Audience :: Developers',
   107                    'Intended Audience :: Developers',
    83                    'License :: Ceccil-C',
   108                    'License :: Ceccil-C',
    84                    'Operating System :: OS Independent',
   109                    'Operating System :: OS Independent',
    85                    'Programming Language :: Python',
   110                    'Programming Language :: Python',
    86                    'Topic :: Utilities'],
   111                    'Topic :: Utilities',
       
   112     ],
    87 )
   113 )