setup.py
changeset 6522 c46b3b3291e8
parent 6509 b717a6cb337b
parent 6517 c991ad161d8f
child 6537 308037210dab
equal deleted inserted replaced
6515:6e998b1be7fd 6522:c46b3b3291e8
    59 scripts = getattr(__pkginfo__, 'scripts', ())
    59 scripts = getattr(__pkginfo__, 'scripts', ())
    60 include_dirs = getattr(__pkginfo__, 'include_dirs', ())
    60 include_dirs = getattr(__pkginfo__, 'include_dirs', ())
    61 data_files = getattr(__pkginfo__, 'data_files', None)
    61 data_files = getattr(__pkginfo__, 'data_files', None)
    62 subpackage_of = getattr(__pkginfo__, 'subpackage_of', None)
    62 subpackage_of = getattr(__pkginfo__, 'subpackage_of', None)
    63 ext_modules = getattr(__pkginfo__, 'ext_modules', None)
    63 ext_modules = getattr(__pkginfo__, 'ext_modules', None)
    64 
    64 package_data = getattr(__pkginfo__, 'package_data', {})
    65 
    65 
    66 BASE_BLACKLIST = ('CVS', 'debian', 'dist', 'build', '__buildlog')
    66 BASE_BLACKLIST = ('CVS', 'debian', 'dist', 'build', '__buildlog')
    67 IGNORED_EXTENSIONS = ('.pyc', '.pyo', '.elc')
    67 IGNORED_EXTENSIONS = ('.pyc', '.pyo', '.elc')
    68 
    68 
    69 
    69 
   162                 base = modname
   162                 base = modname
   163             for directory in include_dirs:
   163             for directory in include_dirs:
   164                 dest = join(self.install_dir, base, directory)
   164                 dest = join(self.install_dir, base, directory)
   165                 export(directory, dest, verbose=False)
   165                 export(directory, dest, verbose=False)
   166 
   166 
       
   167 # write required share/cubicweb/cubes/__init__.py
   167 class MyInstallData(install_data.install_data):
   168 class MyInstallData(install_data.install_data):
       
   169     """A class That manages data files installation"""
   168     def run(self):
   170     def run(self):
   169         """overridden from install_data class"""
   171         """overridden from install_data class"""
   170         install_data.install_data.run(self)
   172         install_data.install_data.run(self)
   171         path = join(self.install_dir, 'share', 'cubicweb', 'cubes', '__init__.py')
   173         path = join(self.install_dir, 'share', 'cubicweb', 'cubes', '__init__.py')
   172         ini = open(path, 'w')
   174         ini = open(path, 'w')
   173         ini.write('# Cubicweb cubes directory\n')
   175         ini.write('# Cubicweb cubes directory\n')
   174         ini.close()
   176         ini.close()
   175 
   177 
       
   178 # re-enable copying data files in sys.prefix
       
   179 if USE_SETUPTOOLS:
       
   180     # overwrite MyInstallData to use sys.prefix instead of the egg directory
       
   181     MyInstallMoreData = MyInstallData
       
   182     class MyInstallData(MyInstallMoreData):
       
   183         """A class that manages data files installation"""
       
   184         def run(self):
       
   185             _old_install_dir = self.install_dir
       
   186             if self.install_dir.endswith('egg'):
       
   187                 self.install_dir = sys.prefix
       
   188             MyInstallMoreData.run(self)
       
   189             self.install_dir = _old_install_dir
       
   190     try:
       
   191         import setuptools.command.easy_install # only if easy_install avaible
       
   192         # monkey patch: Crack SandboxViolation verification
       
   193         from setuptools.sandbox import DirectorySandbox as DS
       
   194         old_ok = DS._ok
       
   195         def _ok(self, path):
       
   196             """Return True if ``path`` can be written during installation."""
       
   197             out = old_ok(self, path)
       
   198             realpath = os.path.normcase(os.path.realpath(path))
       
   199             if realpath.startswith(sys.prefix):
       
   200                 out = True
       
   201             return out
       
   202         DS._ok = _ok
       
   203     except ImportError:
       
   204         pass
   176 
   205 
   177 def install(**kwargs):
   206 def install(**kwargs):
   178     """setup entry point"""
   207     """setup entry point"""
   179     if USE_SETUPTOOLS:
   208     if USE_SETUPTOOLS:
   180         if '--force-manifest' in sys.argv:
   209         if '--force-manifest' in sys.argv:
   192         kwargs['package_dir'] = {modname : '.'}
   221         kwargs['package_dir'] = {modname : '.'}
   193         packages = [modname] + get_packages(os.getcwd(), modname)
   222         packages = [modname] + get_packages(os.getcwd(), modname)
   194     if USE_SETUPTOOLS:
   223     if USE_SETUPTOOLS:
   195         kwargs['install_requires'] = install_requires
   224         kwargs['install_requires'] = install_requires
   196     kwargs['packages'] = packages
   225     kwargs['packages'] = packages
       
   226     kwargs['package_data'] = package_data
   197     return setup(name=distname, version=version, license=license, url=web,
   227     return setup(name=distname, version=version, license=license, url=web,
   198                  description=description, long_description=long_description,
   228                  description=description, long_description=long_description,
   199                  author=author, author_email=author_email,
   229                  author=author, author_email=author_email,
   200                  scripts=ensure_scripts(scripts), data_files=data_files,
   230                  scripts=ensure_scripts(scripts), data_files=data_files,
   201                  ext_modules=ext_modules,
   231                  ext_modules=ext_modules,
   202                  cmdclass={'install_lib': MyInstallLib, 'install_data': MyInstallData},
   232                  cmdclass={'install_lib': MyInstallLib,
       
   233                            'install_data': MyInstallData},
   203                  **kwargs
   234                  **kwargs
   204                  )
   235                  )
   205 
   236 
   206 if __name__ == '__main__' :
   237 if __name__ == '__main__' :
   207     install()
   238     install()