Commit 683691d9 by Eric Coissac

Patch fewbugs compare to the obitools3 version

parent aa3f94c4
def build_ext(*args,**kargs):
'''
Wrapper over the build_ext class to postpone the import of cython
'''
from build_ext import build_ext as _build_ext
return _build_ext(*args,**kargs)
......@@ -27,11 +27,16 @@ class build(ori_build):
def has_pidname(self):
return is_mac_system()
def has_doc(self):
return True
sub_commands = [('littlebigman', has_littlebigman),
('pidname',has_pidname),
('build_ctools', has_ctools),
('build_files', has_files),
('build_cexe', has_executables)] \
+ ori_build.sub_commands
+ ori_build.sub_commands + \
[('build_sphinx',has_doc)]
......@@ -4,9 +4,7 @@ Created on 20 oct. 2012
@author: coissac
'''
import os
from obidistutils.command.build_ctools import build_ctools
from distutils.sysconfig import customize_compiler
from distutils.errors import DistutilsSetupError
from distutils import log
......@@ -55,21 +53,21 @@ class build_cexe(build_ctools):
name of the built file (see --> build_files)
"""
sources = list(sources)
for i in xrange(len(sources)):
print exe_name,sources[i],
for i in range(len(sources)):
message = "%s :-> %s" % (exe_name,sources[i])
if sources[i][0]=='@':
try:
filename = self.built_files[sources[i][1:]]
except KeyError:
raise DistutilsSetupError, \
('The %s filename declared in the source '
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)
'built by the installation process' % (sources[i],
exe_name))
sources[i]=filename
print "changed to ",filename
log.info("%s changed to %s",message,filename)
else:
print " ok"
log.info("%s ok",message)
return sources
......@@ -4,12 +4,8 @@ Created on 20 oct. 2012
@author: coissac
'''
import os
from obidistutils.command.build_exe import build_exe
from distutils.sysconfig import customize_compiler
from distutils.errors import DistutilsSetupError
from distutils import log
class build_ctools(build_exe):
......@@ -42,18 +38,21 @@ class build_ctools(build_exe):
self.executables = self.distribution.ctools
self.check_executable_list(self.executables)
if self.littlebigman =='-DLITTLE_END':
if self.define is None:
self.define=[('LITTLE_END',None)]
else:
self.define.append('LITTLE_END',None)
log.info('Look for CPU architecture... %s',self.define)
self.ctools = set()
def run(self):
build_exe.run(self)
for e,p in self.executables:
for e,p in self.executables: # @UnusedVariable
self.ctools.add(e)
......
......@@ -12,8 +12,6 @@ from distutils.errors import DistutilsSetupError
from distutils import log
from distutils.ccompiler import show_compilers
import subprocess
class build_exe(Command):
description = "build an executable -- Abstract command "
......@@ -124,30 +122,28 @@ class build_exe(Command):
just returns otherwise.
"""
if not isinstance(executables, list):
raise DistutilsSetupError, \
"'executables' option must be a list of tuples"
raise DistutilsSetupError("'executables' option must be a list of tuples")
for exe in executables:
if not isinstance(exe, tuple) and len(exe) != 2:
raise DistutilsSetupError, \
"each element of 'executables' must a 2-tuple"
raise DistutilsSetupError("each element of 'executables' must a 2-tuple")
name, build_info = exe
if not isinstance(name, str):
raise DistutilsSetupError, \
"first element of each tuple in 'executables' " + \
"must be a string (the executables name)"
raise DistutilsSetupError(
"first element of each tuple in 'executables' "
"must be a string (the executables name)")
if '/' in name or (os.sep != '/' and os.sep in name):
raise DistutilsSetupError, \
("bad executable name '%s': " +
"may not contain directory separators") % \
exe[0]
raise DistutilsSetupError(
"bad executable name '%s': "
"may not contain directory separators" % exe[0])
if not isinstance(build_info, dict):
raise DistutilsSetupError, \
"second element of each tuple in 'executables' " + \
"must be a dictionary (build info)"
raise DistutilsSetupError(
"second element of each tuple in 'executables' "
"must be a dictionary (build info)")
def get_executable_names(self):
# Assume the executables list is valid -- 'check_executable_list()' is
......@@ -156,7 +152,7 @@ class build_exe(Command):
return None
exe_names = []
for (exe_name, build_info) in self.executables:
for (exe_name, build_info) in self.executables: # @UnusedVariable
exe_names.append(exe_name)
return exe_names
......@@ -164,13 +160,13 @@ class build_exe(Command):
def get_source_files(self):
self.check_executable_list(self.executables)
filenames = []
for (exe_name, build_info) in self.executables:
for (exe_name, build_info) in self.executables: # @UnusedVariable
sources = build_info.get('sources')
if sources is None or not isinstance(sources, (list, tuple)):
raise DistutilsSetupError, \
("in 'executables' option (library '%s'), "
raise DistutilsSetupError(
"in 'executables' option (library '%s'), "
"'sources' must be present and must be "
"a list of source filenames") % exe_name
"a list of source filenames" % exe_name)
filenames.extend(sources)
return filenames
......@@ -182,10 +178,11 @@ class build_exe(Command):
for (exe_name, build_info) in executables:
sources = build_info.get('sources')
if sources is None or not isinstance(sources, (list, tuple)):
raise DistutilsSetupError, \
("in 'executables' option (library '%s'), " +
"'sources' must be present and must be " +
"a list of source filenames") % exe_name
raise DistutilsSetupError(
"in 'executables' option (library '%s'), "
"'sources' must be present and must be "
"a list of source filenames" % exe_name)
sources = self.substitute_sources(exe_name,sources)
log.info("building '%s' program", exe_name)
......
......@@ -4,26 +4,27 @@ Created on 13 fevr. 2014
@author: coissac
'''
try:
from Cython.Distutils import build_ext as ori_build_ext # @UnresolvedImport
except ImportError:
from distutils.command.build_ext import build_ext as ori_build_ext
from distutils.errors import DistutilsSetupError
from distutils import log
import os
from Cython.Distutils import build_ext as ori_build_ext # @UnresolvedImport
from distutils.errors import DistutilsSetupError
class build_ext(ori_build_ext):
def modifyDocScripts(self):
print >>open("doc/sphinx/build_dir.txt","w"),self.build_lib
build_dir_file=open("doc/sphinx/build_dir.txt","w")
print(self.build_lib,file=build_dir_file)
build_dir_file.close()
def initialize_options(self):
ori_build_ext.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)
ori_build_ext.finalize_options(self) # @UndefinedVariable
self.set_undefined_options('littlebigman',
('littlebigman', 'littlebigman'))
......@@ -45,8 +46,8 @@ class build_ext(ori_build_ext):
name of the built file (see --> build_files)
"""
sources = list(sources)
for i in xrange(len(sources)):
print exe_name,sources[i],
for i in range(len(sources)):
message = "%s :-> %s" % (exe_name,sources[i])
if sources[i][0]=='@':
try:
filename = self.built_files[sources[i][1:]]
......@@ -55,15 +56,15 @@ class build_ext(ori_build_ext):
if os.path.isfile (tmpfilename):
filename = tmpfilename
else:
raise DistutilsSetupError, \
('The %s filename declared in the source '
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)
'built by the installation process' % (sources[i],
exe_name))
sources[i]=filename
print "changed to ",filename
log.info("%s changed to %s",message,filename)
else:
print " ok"
log.info("%s ok",message)
return sources
......@@ -76,16 +77,16 @@ class build_ext(ori_build_ext):
self.check_extensions_list(self.extensions)
for ext in self.extensions:
print "#####>",ext.sources
log.info("%s :-> %s",ext.name,ext.sources)
ext.sources = self.cython_sources(ext.sources, ext)
self.build_extension(ext)
def run(self):
self.modifyDocScripts()
ori_build_ext.run(self)
ori_build_ext.run(self) # @UndefinedVariable
......@@ -7,13 +7,8 @@ Created on 20 oct. 2012
import os.path
from distutils.core import Command
from distutils.util import convert_path
from distutils import log, sysconfig
from distutils.dep_util import newer
from distutils import log
class build_files(Command):
def initialize_options(self):
......
'''
Created on 20 oct. 2012
@author: coissac
'''
from obidistutils.command.build_scripts import build_scripts
class build_filters(build_scripts):
pass
......@@ -6,14 +6,14 @@ Created on 20 oct. 2012
import os.path
from distutils.command.build_scripts import build_scripts as ori_build_scripts,\
first_line_re
from distutils.command.build_scripts import build_scripts as ori_build_scripts
from distutils.util import convert_path
from distutils import log, sysconfig
from distutils.dep_util import newer
from stat import ST_MODE
import re
first_line_re = re.compile('^#!.*python[0-9.]*([ \t].*)?$')
class build_scripts(ori_build_scripts):
......@@ -93,8 +93,10 @@ class build_scripts(ori_build_scripts):
if self.dry_run:
log.info("changing mode of %s", F)
else:
oldmode = os.stat(F)[ST_MODE] & 07777
newmode = (oldmode | 0555) & 07777
oldmode = os.stat(F)[ST_MODE]
oldmode = oldmode & 0o7777
newmode = (oldmode | 0o555) & 0o7777
if newmode != oldmode:
log.info("changing mode of %s from %o to %o",
F, oldmode, newmode)
......
'''
Created on 10 mars 2015
@author: coissac
'''
from sphinx.setup_command import BuildDoc as ori_build_sphinx # @UnresolvedImport
class build_sphinx(ori_build_sphinx):
'''
Build Sphinx documentation in html, epub and man formats
'''
description = __doc__
def run(self):
self.builder='html'
self.finalize_options()
ori_build_sphinx.run(self)
self.builder='epub'
self.finalize_options()
ori_build_sphinx.run(self)
self.builder='man'
self.finalize_options()
ori_build_sphinx.run(self)
\ No newline at end of file
......@@ -11,4 +11,4 @@ class install(install_ori):
def __init__(self,dist):
install_ori.__init__(self, dist)
self.sub_commands.insert(0, ('build',lambda self: True))
self.sub_commands.append(('install_sphinx',lambda self: self.distribution.serenity))
......@@ -3,8 +3,8 @@ Created on 20 oct. 2012
@author: coissac
'''
from distutils.command.install_scripts import install_scripts as ori_install_scripts
import os.path
from distutils import log
......@@ -12,42 +12,32 @@ class install_scripts(ori_install_scripts):
def initialize_options(self):
ori_install_scripts.initialize_options(self)
self.deprecated_scripts = None
def revove_dot_py(self):
for filename in self.get_outputs():
pyfile = "%s.py" % filename
if os.path.exists(pyfile):
command = os.path.split(pyfile)[-1]
log.info('Removing deprecated .py form of the unix command : %s (file %s)' % (command,pyfile))
if not self.dry_run:
os.unlink(pyfile)
try:
if not self.dry_run:
os.unlink(os.path.join(self.build_dir,command))
except:
log.info('Unix command %s is not present in build dir' % command)
self.public_dir = None
def install_public_link(self):
self.mkpath(self.public_dir)
for file in self.get_outputs():
if self.dry_run:
log.info("changing mode of %s", file)
else:
log.info("exporting file %s -> %s", file,os.path.join(self.public_dir,
os.path.split(file)[1]
))
dest = os.path.join(self.public_dir,
os.path.split(file)[1]
)
if os.path.exists(dest):
os.unlink(dest)
os.symlink(file,dest)
def remove_deprecated_script(self):
if self.deprecated_scripts is not None:
for f in self.deprecated_scripts:
try:
ff = os.path.join(self.install_dir,f)
if not self.dry_run:
os.unlink(ff)
log.info('Removing deprecated unix command : %s (file : %s)' % (f,ff))
ff = os.path.join(self.build_dir,f)
if not self.dry_run:
os.unlink(ff)
except:
log.info('Unix command %s is not present' % f)
def run(self):
self.remove_deprecated_script()
ori_install_scripts.run(self)
self.revove_dot_py()
if self.distribution.serenity:
self.public_dir=os.path.join(self.install_dir,"../export/bin")
self.public_dir=os.path.abspath(self.public_dir)
self.install_public_link()
'''
Created on 10 mars 2015
@author: coissac
'''
from distutils.core import Command
import os.path
import glob
class install_sphinx(Command):
'''
Install the sphinx documentation
'''
description = "Install the sphinx documentation in serenity mode"
boolean_options = ['force', 'skip-build']
def initialize_options (self):
self.install_doc = None
self.build_dir = None
def finalize_options (self):
self.set_undefined_options('build_sphinx', ('build_dir', 'build_dir'))
self.set_undefined_options('install',
('install_scripts', 'install_doc'))
def run (self):
if self.distribution.serenity:
self.install_doc = os.path.join(self.install_doc,"../export/share")
self.install_doc=os.path.abspath(self.install_doc)
self.mkpath(self.install_doc)
self.mkpath(os.path.join(self.install_doc,'html'))
outfiles = self.copy_tree(os.path.join(self.build_dir,'html'), # @UnusedVariable
os.path.join(self.install_doc,'html'))
self.mkpath(os.path.join(self.install_doc,'man','man1'))
outfiles = self.copy_tree(os.path.join(self.build_dir,'man'), # @UnusedVariable
os.path.join(self.install_doc,'man','man1'))
for epub in glob.glob(os.path.join(self.build_dir,'epub/*.epub')):
self.copy_file(os.path.join(epub),
os.path.join(self.install_doc,os.path.split(epub)[1]))
\ No newline at end of file
......@@ -6,10 +6,7 @@ Created on 20 oct. 2012
import os
from distutils.core import Command
from obidistutils.command.build_exe import build_exe
from distutils.sysconfig import customize_compiler
from distutils.errors import DistutilsSetupError
from distutils import log
import subprocess
......@@ -52,7 +49,7 @@ class littlebigman(build_exe):
shell=True,
stdout=subprocess.PIPE)
little = p.communicate()[0]
return little
return little.decode('latin1')
def run(self):
build_exe.run(self)
......
......@@ -10,30 +10,20 @@ import glob
import sys
try:
from setuptools import setup as ori_setup
has_setuptools = True
except ImportError:
from distutils.core import setup as ori_setup
has_setuptools = False
from distutils.core import setup as ori_setup
from distutils.extension import Extension
from obidistutils.command.build import build
from obidistutils.command.littlebigman import littlebigman
from obidistutils.command.build_cexe import build_cexe
from obidistutils.command import build_ext
from obidistutils.command.build_ctools import build_ctools
from obidistutils.command.build_files import build_files
from obidistutils.command.build_scripts import build_scripts
from obidistutils.command.install_scripts import install_scripts
from obidistutils.command.install import install
from obidistutils.command.pidname import pidname
from obidistutils.serenity.checkpackage import install_requirements,\
check_requirements, \
RequirementError
from obidistutils.serenity.rerun import enforce_good_python
from obidistutils.serenity.rerun import rerun_with_anothe_python
from distutils import log
from obidistutils.dist import Distribution
def findPackage(root,base=None):
modules=[]
if base is None:
......@@ -55,7 +45,10 @@ def findCython(root,base=None,pyrexs=None):
for pyrex in glob.glob(path.join(root,module,'*.pyx')):
pyrexs.append(Extension('.'.join(base+[module,path.splitext(path.basename(pyrex))[0]]),[pyrex]))
pyrexs.append(Extension('.'.join(base+[module,path.splitext(path.basename(pyrex))[0]]),
[pyrex]
)
)
try:
cfiles = os.path.splitext(pyrex)[0]+".cfiles"
cfilesdir = os.path.dirname(cfiles)
......@@ -64,66 +57,55 @@ def findCython(root,base=None,pyrexs=None):
if y[0] !='@' else y.strip()
for y in cfiles]
print "@@@@>",cfiles
log.info("Cython module : %s",cfiles)
incdir = set(os.path.dirname(x) for x in cfiles if x[-2:]==".h")
cfiles = [x for x in cfiles if x[-2:]==".c"]
pyrexs[-1].sources.extend(cfiles)
pyrexs[-1].include_dirs.extend(incdir)
pyrexs[-1].extra_compile_args.extend(['-msse2'])
pyrexs[-1].extra_compile_args.extend(['-msse2','-Wno-unused-function','-Wmissing-braces'])
except IOError:
pass
pyrexs[-1].sources.extend(glob.glob(os.path.splitext(pyrex)[0]+'.ext.*.c'))
print pyrexs[-1].sources
# Main.compile([pyrex],timestamps=True)
pyrexs.extend(findCython(path.join(root,module),base+[module]))
return pyrexs
def findC(root,base=None,pyrexs=None):
setupdir = os.path.dirname(sys.argv[0])
pyrexs=[]
if base is None:
base=[]
for module in (path.basename(path.dirname(x))
for x in glob.glob(path.join(root,'*','__init__.py'))):