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
|
'''
Created on 13 fevr. 2014
@author: coissac
'''
from distutils import log
import sys
from obidistutils.serenity import is_serenity
import os
from obidistutils.serenity.checkpackage import install_requirements
from obidistutils.serenity.rerun import rerun_with_anothe_python
try:
from Cython.Distutils import build_ext as ori_build_ext # @UnresolvedImport
except ImportError:
if not is_serenity() and install_requirements():
log.info("Restarting installation with all dependencies ok")
rerun_with_anothe_python(os.path.realpath(sys.executable))
from distutils.errors import DistutilsSetupError
class build_ext(ori_build_ext):
def modifyDocScripts(self):
print(self.build_lib, file=open("doc/sphinx/build_dir.txt","w"))
def initialize_options(self):
ori_build_ext.initialize_options(self) # @UndefinedVariable
self.littlebigman = None
self.built_files = None
def finalize_options(self):
ori_build_ext.finalize_options(self) # @UndefinedVariable
self.set_undefined_options('littlebigman',
('littlebigman', 'littlebigman'))
self.set_undefined_options('build_files',
('files', 'built_files'))
self.cython_c_in_temp = 1
if self.littlebigman =='-DLITTLE_END':
if self.define is None:
self.define=[('LITTLE_END',None)]
else:
self.define.append('LITTLE_END',None)
def substitute_sources(self,exe_name,sources):
"""
Substitutes source file name starting by an @ by the actual
name of the built file (see --> build_files)
"""
sources = list(sources)
for i in range(len(sources)):
print(exe_name,sources[i], end=' ')
if sources[i][0]=='@':
try:
filename = self.built_files[sources[i][1:]]
except KeyError:
tmpfilename = os.path.join(self.build_temp,sources[i][1:])
if os.path.isfile (tmpfilename):
filename = tmpfilename
else:
raise DistutilsSetupError(('The %s filename declared in the source '
'files of the program %s have not been '
'built by the installation process') % (sources[i],
exe_name))
sources[i]=filename
print("changed to ",filename)
else:
print(" ok")
return sources
def build_extensions(self):
# First, sanity-check the 'extensions' list
for ext in self.extensions:
ext.sources = self.substitute_sources(ext.name,ext.sources)
self.check_extensions_list(self.extensions)
for ext in self.extensions:
print("#####>",ext.sources)
ext.sources = self.cython_sources(ext.sources, ext)
self.build_extension(ext)
def run(self):
self.modifyDocScripts()
ori_build_ext.run(self) # @UndefinedVariable
# from obidistutils.serenity.getcython import get_a_cython_module
# import imp
# import os.path
#
# log.info("No cython installed, try to install a temporary cython")
# cython = get_a_cython_module()
# sys.path.insert(0,os.path.dirname(os.path.dirname(cython.__file__)))
# f, filename, description=imp.find_module('Distutils',[os.path.dirname(cython.__file__)])
# submodule = imp.load_module('Cython.Distutils', f, filename, description)
# ori_build_ext = submodule.build_ext
#
|