Merge branch 'pip-standard-orig-python' into 'master'

The new install version based on classical setup.py

See merge request obitools/obitools3!1
This commit is contained in:
2019-03-29 16:25:01 +01:00
40 changed files with 227 additions and 2163 deletions

13
.gitignore vendored Normal file
View File

@ -0,0 +1,13 @@
.DS_Store
/obitools.test/
/OBITools3- 1.01.16/
/OBITools3-0.00.0/
/build/
/testpip/
/toto.obidms/
/unittests/
/setup.py.old
/3_Hornung_testseq.fastq
/sample/
/save.temp/
/obitmp/

17
.project Normal file
View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>obitools3</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.python.pydev.PyDevBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.python.pydev.pythonNature</nature>
</natures>
</projectDescription>

20
.pydevproject Normal file
View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?eclipse-pydev version="1.0"?><pydev_project>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">python3.6-obitool3</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python interpreter</pydev_property>
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
<path>/${PROJECT_DIR_NAME}/python</path>
</pydev_pathproperty>
</pydev_project>

View File

@ -1,33 +0,0 @@
ifeq ($(CC),gcc)
LFLAGS = -fopenmp
else
LFLAGS =
endif
SOURCE_DIR := src
ENV_DIR := $(abspath .)
OBJ_DIR := $(ENV_DIR)/obi_objdir
LIB_DIR := $(ENV_DIR)/obi_libdir
SOURCE_FILES = $(SOURCE_DIR)/libecoPCR/libapat/*.c $(SOURCE_DIR)/libecoPCR/libthermo/*.c $(SOURCE_DIR)/libecoPCR/*.c $(SOURCE_DIR)/libjson/*.c $(SOURCE_DIR)/*.c
OBJ_FILES = $(OBJ_DIR)/*.o
DYN_LIB_FILES = $(LIB_DIR)/libobi3.so
all: $(DYN_LIB_FILES)
$(LIB_DIR):
mkdir -p $(LIB_DIR)
$(OBJ_DIR):
mkdir -p $(OBJ_DIR)
$(DYN_LIB_FILES): $(OBJ_FILES) | $(LIB_DIR)
$(CC) -shared -o $@ $^
$(OBJ_FILES): | $(OBJ_DIR)
$(CC) $(LFLAGS) -fpic -c $(SOURCE_FILES)
mv *.o $(OBJ_DIR)
clean:
rm -rf $(LIB_DIR)
rm -rf $(OBJ_DIR)

View File

@ -1,38 +0,0 @@
'''
Created on 20 oct. 2012
@author: coissac
'''
from distutils.command.build import build as ori_build
from obidistutils.serenity.checksystem import is_mac_system
class build(ori_build):
def has_ext_modules(self):
return self.distribution.has_ext_modules()
def has_pidname(self):
return is_mac_system()
def has_doc(self):
return True
def has_littlebigman(self):
return True
try:
from obidistutils.command.build_sphinx import build_sphinx # @UnusedImport
sub_commands = [("littlebigman",has_littlebigman),
('pidname',has_pidname)
] \
+ ori_build.sub_commands + \
[('build_sphinx',has_doc)]
except ImportError:
sub_commands = [("littlebigman",has_littlebigman),
('pidname',has_pidname)
] \
+ ori_build.sub_commands

View File

@ -1,85 +0,0 @@
'''
Created on 20 oct. 2012
@author: coissac
'''
from .build_ctools import build_ctools
from .build_exe import build_exe
from distutils.errors import DistutilsSetupError
from distutils import log
import os
class build_cexe(build_ctools):
description = "build C/C++ executable distributed with Python extensions"
def initialize_options(self):
build_ctools.initialize_options(self)
self.built_files = None
def finalize_options(self):
# This might be confusing: both build-cexe and build-temp default
# to build-temp as defined by the "build" command. This is because
# I think that C libraries are really just temporary build
# by-products, at least from the point of view of building Python
# extensions -- but I want to keep my options open.
build_cexe_dir = self.build_cexe
build_ctools.finalize_options(self)
if build_cexe_dir is None:
self.build_cexe=None
self.set_undefined_options('build',
('build_scripts', 'build_cexe'))
self.set_undefined_options('build_files',
('files', 'built_files'))
self.executables = self.distribution.executables
# self.build_cexe = os.path.join(os.path.dirname(self.build_cexe),'cbinaries')
# self.mkpath(self.build_cexe)
if self.executables:
self.check_executable_list(self.executables)
# XXX same as for build_ext -- what about 'self.define' and
# 'self.undef' ?
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)):
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 '
'files of the program %s have not been '
'built by the installation process' % (sources[i],
exe_name))
sources[i]=filename
log.info("%s changed to %s",message,filename)
else:
log.info("%s ok",message)
return sources
def run(self):
for cmd_name in self.get_sub_commands():
self.run_command(cmd_name)
build_exe.run(self)

View File

@ -1,63 +0,0 @@
'''
Created on 20 oct. 2012
@author: coissac
'''
from .build_exe import build_exe
from distutils import log
class build_ctools(build_exe):
description = "build C/C++ executable not distributed with Python extensions"
def initialize_options(self):
build_exe.initialize_options(self)
# List of built tools
self.ctools = None
self.littlebigman = None
def finalize_options(self):
# This might be confusing: both build-cexe and build-temp default
# to build-temp as defined by the "build" command. This is because
# I think that C libraries are really just temporary build
# by-products, at least from the point of view of building Python
# extensions -- but I want to keep my options open.
build_exe.finalize_options(self)
self.set_undefined_options('build',
('build_temp', 'build_cexe'))
self.set_undefined_options('littlebigman',
('littlebigman', 'littlebigman'))
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):
for cmd_name in self.get_sub_commands():
self.run_command(cmd_name)
build_exe.run(self)
for e,p in self.executables: # @UnusedVariable
self.ctools.add(e)

View File

@ -1,228 +0,0 @@
'''
Created on 20 oct. 2012
@author: coissac
'''
import os
from distutils import sysconfig
from distutils.core import Command
from distutils.sysconfig import customize_compiler as customize_compiler_ori
from distutils.errors import DistutilsSetupError
from distutils import log
from distutils.ccompiler import show_compilers
def customize_compiler(compiler):
customize_compiler_ori(compiler)
compilername = compiler.compiler[0]
if ("gcc" in compilername or "g++" in compilername):
cc_cmd = ' '.join(compiler.compiler + ['-fopenmp'])
ccshared= ' '.join(x for x in sysconfig.get_config_vars("ccshared") if x is not None)
compiler.set_executables(
compiler=cc_cmd,
compiler_so=cc_cmd + ' ' + ccshared
)
class build_exe(Command):
description = "build an executable -- Abstract command "
user_options = [
('build-cexe', 'x',
"directory to build C/C++ libraries to"),
('build-temp', 't',
"directory to put temporary build by-products"),
('debug', 'g',
"compile with debugging information"),
('force', 'f',
"forcibly build everything (ignore file timestamps)"),
('compiler=', 'c',
"specify the compiler type"),
]
boolean_options = ['debug', 'force']
help_options = [
('help-compiler', None,
"list available compilers", show_compilers),
]
def initialize_options(self):
self.build_cexe = None
self.build_temp = None
# List of executables to build
self.executables = None
# Compilation options for all libraries
self.include_dirs = None
self.define = None
self.undef = None
self.extra_compile_args = None
self.debug = None
self.force = 0
self.compiler = None
self.sse = None
self.built_files=None
def finalize_options(self):
# This might be confusing: both build-cexe and build-temp default
# to build-temp as defined by the "build" command. This is because
# I think that C libraries are really just temporary build
# by-products, at least from the point of view of building Python
# extensions -- but I want to keep my options open.
self.set_undefined_options('build',
('build_temp', 'build_temp'),
('compiler', 'compiler'),
('debug', 'debug'),
('force', 'force'))
if self.include_dirs is None:
self.include_dirs = self.distribution.include_dirs or []
if isinstance(self.include_dirs, str):
self.include_dirs = self.include_dirs.split(os.pathsep)
self.sse = self.distribution.sse
if self.sse is not None:
if self.extra_compile_args is None:
self.extra_compile_args=['-m%s' % self.sse]
else:
self.extra_compile_args.append('-m%s' % self.sse)
# XXX same as for build_ext -- what about 'self.define' and
# 'self.undef' ?
def run(self):
if not self.executables:
return
self.mkpath(self.build_cexe)
# Yech -- this is cut 'n pasted from build_ext.py!
from distutils.ccompiler import new_compiler
self.compiler = new_compiler(compiler=self.compiler,
dry_run=self.dry_run,
force=self.force)
customize_compiler(self.compiler)
if self.include_dirs is not None:
self.compiler.set_include_dirs(self.include_dirs)
if self.define is not None:
# 'define' option is a list of (name,value) tuples
for (name,value) in self.define:
self.compiler.define_macro(name, value)
if self.undef is not None:
for macro in self.undef:
self.compiler.undefine_macro(macro)
self.build_executables(self.executables)
def check_executable_list(self, executables):
"""Ensure that the list of executables is valid.
`executable` is presumably provided as a command option 'executables'.
This method checks that it is a list of 2-tuples, where the tuples
are (executable_name, build_info_dict).
Raise DistutilsSetupError if the structure is invalid anywhere;
just returns otherwise.
"""
if not isinstance(executables, list):
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")
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)")
if '/' in name or (os.sep != '/' and os.sep in name):
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)")
def get_executable_names(self):
# Assume the executables list is valid -- 'check_executable_list()' is
# called from 'finalize_options()', so it should be!
if not self.executables:
return None
exe_names = []
for (exe_name, build_info) in self.executables: # @UnusedVariable
exe_names.append(exe_name)
return exe_names
def get_source_files(self):
self.check_executable_list(self.executables)
filenames = []
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'), "
"'sources' must be present and must be "
"a list of source filenames" % exe_name)
filenames.extend(sources)
return filenames
def substitute_sources(self,exe_name,sources):
return list(sources)
def build_executables(self, executables):
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)
sources = self.substitute_sources(exe_name,sources)
log.info("building '%s' program", exe_name)
# First, compile the source code to object files in the library
# directory. (This should probably change to putting object
# files in a temporary build directory.)
macros = build_info.get('macros')
include_dirs = build_info.get('include_dirs')
extra_args = self.extra_compile_args or []
objects = self.compiler.compile(sources,
output_dir=self.build_temp,
macros=macros,
include_dirs=include_dirs,
extra_postargs=extra_args,
debug=self.debug)
# Now "link" the object files together into a static library.
# (On Unix at least, this isn't really linking -- it just
# builds an archive. Whatever.)
self.compiler.link_executable(objects, exe_name,
output_dir=self.build_cexe,
debug=self.debug)

View File

@ -1,143 +0,0 @@
'''
Created on 13 fevr. 2014
@author: coissac
'''
from distutils import log
import os
from distutils import sysconfig
from distutils.errors import DistutilsSetupError
def _customize_compiler(compiler):
compilername = compiler.compiler[0]
if ("gcc" in compilername or "g++" in compilername):
cc_cmd = ' '.join(compiler.compiler + ['-fopenmp'])
ccshared= ' '.join(x for x in sysconfig.get_config_vars("ccshared") if x is not None)
compiler.set_executables(
compiler=cc_cmd,
compiler_so=cc_cmd + ' ' + ccshared
)
try:
from Cython.Distutils import build_ext as ori_build_ext # @UnresolvedImport
from Cython.Compiler import Options as cython_options # @UnresolvedImport
class build_ext(ori_build_ext):
def modifyDocScripts(self):
try:
os.mkdir("doc/sphinx")
except:
pass
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) # @UndefinedVariable
self.littlebigman = None
self.built_files = None
def finalize_options(self):
super(build_ext, self).finalize_options()
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)):
message = "%s :-> %s" % (exe_name,sources[i])
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
log.info("%s changed to %s",message,filename)
else:
log.info("%s ok",message)
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)
print("pouic")
print(ext.sources)
print("pouac")
for ext in self.extensions:
log.info("%s :-> %s",ext.name,ext.sources)
ext.sources = self.cython_sources(ext.sources, ext)
self.build_extension(ext)
def build_extensions(self): # TODO what?? double? is it supposed to be build_extension?
if hasattr(self, 'compiler'):
_customize_compiler(self.compiler)
if hasattr(self, 'shlib_compiler'):
_customize_compiler(self.shlib_compiler)
ori_build_ext.build_extensions(self)
def run(self):
self.modifyDocScripts()
for cmd_name in self.get_sub_commands():
self.run_command(cmd_name)
cython_options.annotate = True
ori_build_ext.run(self) # @UndefinedVariable
def has_files(self):
return self.distribution.has_files()
def has_executables(self):
return self.distribution.has_executables()
sub_commands = [('build_files',has_files),
('build_cexe', has_executables)
] + ori_build_ext.sub_commands
except ImportError:
from distutils.command import build_ext # @UnusedImport

View File

@ -1,63 +0,0 @@
'''
Created on 20 oct. 2012
@author: coissac
'''
import os.path
from distutils.core import Command
from distutils import log
class build_files(Command):
def initialize_options(self):
self.files=None
self.ctools=None
self.build_temp=None
self.build_cexe=None
def finalize_options(self):
self.set_undefined_options('build_ctools',
('ctools', 'ctools'),
('build_temp','build_temp'),
('build_cexe','build_cexe'),
)
self.files = {}
def run(self):
for cmd_name in self.get_sub_commands():
self.run_command(cmd_name)
for dest,prog,command in self.distribution.files:
destfile = os.path.join(self.build_temp,dest)
if prog in self.ctools:
progfile = os.path.join(self.build_cexe,prog)
else:
progfile = prog
log.info("Building file : %s" % dest)
commandline = command % {'prog' : progfile,
'dest' : destfile}
log.info(" --> %s" % commandline)
os.system(commandline)
self.files[dest]=destfile
log.info("Done.\n")
def has_ctools(self):
return self.distribution.has_ctools()
sub_commands = [('build_ctools', has_ctools)] + \
Command.sub_commands

View File

@ -1,104 +0,0 @@
'''
Created on 20 oct. 2012
@author: coissac
'''
import os.path
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):
def copy_scripts (self):
"""Copy each script listed in 'self.scripts'; if it's marked as a
Python script in the Unix way (first line matches 'first_line_re',
ie. starts with "\#!" and contains "python"), then adjust the first
line to refer to the current Python interpreter as we copy.
"""
self.mkpath(self.build_dir)
rawbuild_dir = os.path.join(os.path.dirname(self.build_dir),'raw_scripts')
self.mkpath(rawbuild_dir)
outfiles = []
for script in self.scripts:
adjust = 0
script = convert_path(script)
outfile = os.path.join(self.build_dir, os.path.splitext(os.path.basename(script))[0])
rawoutfile = os.path.join(rawbuild_dir, os.path.basename(script))
outfiles.append(outfile)
if not self.force and not newer(script, outfile):
log.debug("not copying %s (up-to-date)", script)
continue
# Always open the file but ignore failures in dry-run mode --
# that way, we'll get accurate feedback if we can read the
# script.
try:
f = open(script, "r")
except IOError:
if not self.dry_run:
raise
f = None
else:
first_line = f.readline()
if not first_line:
self.warn("%s is an empty file (skipping)" % script)
continue
match = first_line_re.match(first_line)
if match:
adjust = 1
post_interp = match.group(1) or ''
log.info("Store the raw script %s -> %s", script,rawoutfile)
self.copy_file(script, rawoutfile)
if adjust:
log.info("copying and adjusting %s -> %s", script,
self.build_dir)
if not self.dry_run:
outf = open(outfile, "w")
if not sysconfig.python_build:
outf.write("#!%s%s\n" %
(self.executable,
post_interp))
else:
outf.write("#!%s%s\n" %
(os.path.join(
sysconfig.get_config_var("BINDIR"),
"python%s%s" % (sysconfig.get_config_var("VERSION"),
sysconfig.get_config_var("EXE"))),
post_interp))
outf.writelines(f.readlines())
outf.close()
if f:
f.close()
else:
if f:
f.close()
self.copy_file(script, outfile)
if os.name == 'posix':
for F in outfiles:
if self.dry_run:
log.info("changing mode of %s", F)
else:
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)
os.chmod(F, newmode)

View File

@ -1,27 +0,0 @@
'''
Created on 10 mars 2015
@author: coissac
'''
try:
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)
except ImportError:
pass

View File

@ -1,19 +0,0 @@
'''
Created on 6 oct. 2014
@author: coissac
'''
# try:
# from setuptools.command.install import install as install_ori
# except ImportError:
# from distutils.command.install import install as install_ori
from distutils.command.install import install as install_ori
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))

View File

@ -1,47 +0,0 @@
'''
Created on 20 oct. 2012
@author: coissac
'''
# try:
# from setuptools.command.install_scripts import install_scripts as ori_install_scripts
# except ImportError:
# from distutils.command.install_scripts import install_scripts as ori_install_scripts
from distutils.command.install_scripts import install_scripts as ori_install_scripts
import os.path
from distutils import log
class install_scripts(ori_install_scripts):
def initialize_options(self):
ori_install_scripts.initialize_options(self)
self.public_dir = None
def install_public_link(self):
self.mkpath(self.public_dir)
for file in self.get_outputs():
log.info("exporting file %s -> %s", file,os.path.join(self.public_dir,
os.path.split(file)[1]
))
if not self.dry_run:
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 run(self):
ori_install_scripts.run(self)
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()

View File

@ -1,61 +0,0 @@
'''
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]))
def get_outputs(self):
directory=os.path.join(self.install_doc,'html')
files = [os.path.join(self.install_doc,'html', f)
for dp, dn, filenames in os.walk(directory) for f in filenames] # @UnusedVariable
directory=os.path.join(self.build_dir,'man')
files.append(os.path.join(self.install_doc,'man','man1', f)
for dp, dn, filenames in os.walk(directory) for f in filenames) # @UnusedVariable
directory=os.path.join(self.build_dir,'epub')
files.append(os.path.join(self.install_doc, f)
for dp, dn, filenames in os.walk(directory) # @UnusedVariable
for f in glob.glob(os.path.join(dp, '*.epub')) )
return files

View File

@ -1,59 +0,0 @@
'''
Created on 20 oct. 2012
@author: coissac
'''
import os
from obidistutils.command.build_exe import build_exe
from distutils import log
import subprocess
class littlebigman(build_exe):
description = "build the littlebigman executable testing endianness of the CPU"
def initialize_options(self):
build_exe.initialize_options(self)
self.littlebigman = None
def finalize_options(self):
# This might be confusing: both build-cexe and build-temp default
# to build-temp as defined by the "build" command. This is because
# I think that C libraries are really just temporary build
# by-products, at least from the point of view of building Python
# extensions -- but I want to keep my options open.
build_exe.finalize_options(self)
self.set_undefined_options('build',
('build_temp', 'build_cexe'))
# self.ctools = self.distribution.ctools
if os.path.isfile("distutils.ext/src/littlebigman.c"):
self.executables = [('littlebigman',{"sources":["distutils.ext/src/littlebigman.c"]})]
self.check_executable_list(self.executables)
else:
self.executables = []
def run_littlebigman(self):
p = subprocess.Popen("'%s'" % os.path.join(self.build_temp,
'littlebigman'),
shell=True,
stdout=subprocess.PIPE)
little = p.communicate()[0]
return little.decode('latin1')
def run(self):
build_exe.run(self)
self.littlebigman=self.run_littlebigman()
log.info("Your CPU is in mode : %s" % self.littlebigman)

View File

@ -1,55 +0,0 @@
'''
Created on 20 oct. 2012
@author: coissac
'''
import os
from obidistutils.command.build_exe import build_exe
from obidistutils.serenity.checksystem import is_mac_system
class pidname(build_exe):
description = "build the pidname executable returning the executable path from a PID on a mac"
def initialize_options(self):
build_exe.initialize_options(self)
self.pidname = False
def finalize_options(self):
# This might be confusing: both build-cexe and build-temp default
# to build-temp as defined by the "build" command. This is because
# I think that C libraries are really just temporary build
# by-products, at least from the point of view of building Python
# extensions -- but I want to keep my options open.
build_exe.finalize_options(self)
self.set_undefined_options('build',
('build_scripts', 'build_cexe'))
# self.ctools = self.distribution.ctools
if os.path.isfile("distutils.ext/src/pidname.c"):
self.executables = [('pidname',{"sources":["distutils.ext/src/pidname.c"]})]
self.check_executable_list(self.executables)
else:
self.executables = []
# self.build_cexe = os.path.join(os.path.dirname(self.build_cexe),'cbinaries')
# self.mkpath(self.build_cexe)
def run(self):
if is_mac_system():
build_exe.run(self)
self.pidname=True
else:
self.pidname=False

View File

@ -1,42 +0,0 @@
'''
Created on 10 mars 2015
@author: coissac
'''
import os.path
from distutils.command.sdist import sdist as orig_sdist
from distutils import dir_util
class sdist(orig_sdist):
def make_distribution(self):
"""Create the source distribution(s). First, we create the release
tree with 'make_release_tree()'; then, we create all required
archive files (according to 'self.formats') from the release tree.
Finally, we clean up by blowing away the release tree (unless
'self.keep_temp' is true). The list of archive files created is
stored so it can be retrieved later by 'get_archive_files()'.
"""
# Don't warn about missing meta-data here -- should be (and is!)
# done elsewhere.
base_dir = self.distribution.get_fullname()
base_name = os.path.join(self.dist_dir,base_dir)
self.make_release_tree(os.path.join('tmp',base_dir), self.filelist.files)
archive_files = [] # remember names of files we create
# tar archive must be created last to avoid overwrite and remove
if 'tar' in self.formats:
self.formats.append(self.formats.pop(self.formats.index('tar')))
for fmt in self.formats:
file = self.make_archive(base_name, fmt, root_dir='tmp',base_dir=base_dir,
owner=self.owner, group=self.group)
archive_files.append(file)
self.distribution.dist_files.append(('sdist', '', file))
self.archive_files = archive_files
if not self.keep_temp:
dir_util.remove_tree(os.path.join('tmp',base_dir), dry_run=self.dry_run)

View File

@ -1,234 +0,0 @@
'''
Created on 20 oct. 2012
@author: coissac
'''
from os import path
import os.path
import glob
import sys
try:
from setuptools.extension import Extension
except ImportError:
from distutils.extension import Extension
# from distutils.extension import Extension
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
from obidistutils.serenity import is_serenity
def findPackage(root,base=None):
modules=[]
if base is None:
base=[]
for module in (path.basename(path.dirname(x))
for x in glob.glob(path.join(root,'*','__init__.py'))):
modules.append('.'.join(base+[module]))
modules.extend(findPackage(path.join(root,module),base+[module]))
return modules
def findCython(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'))):
for pyrex in glob.glob(path.join(root,module,'*.pyx')):
libabspath = os.path.abspath('obi_libdir')
obiabspath = os.path.abspath('.')
pyrexs.append(Extension('.'.join(base+[module,path.splitext(path.basename(pyrex))[0]]),
[pyrex],
library_dirs=[libabspath],
include_dirs=[libabspath],
libraries=["obi3"],
runtime_library_dirs=[libabspath],
extra_link_args=["-Wl,-rpath,"+libabspath, "-L"+libabspath]
)
)
try:
cfiles = os.path.splitext(pyrex)[0]+".cfiles"
cfilesdir = os.path.dirname(cfiles)
cfiles = open(cfiles)
cfiles = [os.path.relpath(os.path.join(cfilesdir,y),setupdir).strip()
if y[0] !='@' else y.strip()
for y in 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',
'-Wno-unused-function',
'-Wmissing-braces',
'-Wchar-subscripts',
'-fPIC'
])
except IOError:
pass
pyrexs.extend(findCython(path.join(root,module),base+[module]))
return pyrexs
def rootname(x):
return os.path.splitext(x.sources[0])[0]
def prepare_commands():
from obidistutils.command.build import build
from obidistutils.command.littlebigman import littlebigman
# from obidistutils.command.serenity import serenity
from obidistutils.command.build_cexe import build_cexe
from obidistutils.command.build_ext 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_sphinx import install_sphinx
from obidistutils.command.install import install
from obidistutils.command.pidname import pidname
from obidistutils.command.sdist import sdist
COMMANDS = {'build':build,
# 'serenity':serenity,
'littlebigman':littlebigman,
'pidname':pidname,
'build_ctools':build_ctools,
'build_files':build_files,
'build_cexe':build_cexe,
'build_ext': build_ext,
'build_scripts':build_scripts,
'install_scripts':install_scripts,
'install_sphinx':install_sphinx,
'install':install,
'sdist':sdist}
# try:
# from setuptools.commands import egg_info
# COMMANDS['egg_info']=egg_info
# except ImportError:
# pass
try:
from obidistutils.command.build_sphinx import build_sphinx
COMMANDS['build_sphinx']=build_sphinx
except ImportError:
pass
return COMMANDS
CTOOLS =[]
CEXES =[]
FILES =[]
def setup(**attrs):
log.set_threshold(log.INFO)
minversion = attrs.get("pythonmin",'3.7')
maxversion = attrs.get('pythonmax',None)
fork = attrs.get('fork',False)
requirementfile = attrs.get('requirements','requirements.txt')
try:
del attrs['pythonmin']
except KeyError:
pass
try:
del attrs['pythonmax']
except KeyError:
pass
try:
del attrs['fork']
except KeyError:
pass
try:
del attrs['requirements']
except KeyError:
pass
if is_serenity():
enforce_good_python(minversion, maxversion, fork)
if (install_requirements(requirementfile)):
rerun_with_anothe_python(sys.executable,minversion,maxversion,fork)
try:
check_requirements(requirementfile)
except RequirementError as e :
log.error(e)
sys.exit(1)
if 'distclass' not in attrs:
attrs['distclass']=Distribution
if 'python_src' not in attrs:
SRC = 'python'
else:
SRC = attrs['python_src']
del(attrs['python_src'])
if 'scripts' not in attrs:
attrs['scripts'] = glob.glob('%s/*.py' % SRC)
if 'package_dir' not in attrs:
attrs['package_dir'] = {'': SRC}
if 'packages' not in attrs:
attrs['packages'] = findPackage(SRC)
if 'cmdclass' not in attrs:
attrs['cmdclass'] = prepare_commands()
if 'ctools' not in attrs:
attrs['ctools'] = CTOOLS
if 'executables' not in attrs:
attrs['executables'] = CEXES
if 'files' not in attrs:
attrs['files'] = FILES
if 'sse' not in attrs:
attrs['sse']=None
if 'serenity' not in attrs:
attrs['serenity']=False
EXTENTION=findCython(SRC)
if 'ext_modules' not in attrs:
attrs['ext_modules'] = EXTENTION
# try:
# from setuptools.core import setup as ori_setup
# except ImportError:
# from distutils.core import setup as ori_setup
from distutils.core import setup as ori_setup
return ori_setup(**attrs)

View File

@ -1,58 +0,0 @@
'''
Created on 20 oct. 2012
@author: coissac
'''
try:
from setuptools.dist import Distribution as ori_Distribution
except ImportError:
from distutils.dist import Distribution as ori_Distribution
# from distutils.dist import Distribution as ori_Distribution
class Distribution(ori_Distribution):
def __init__(self,attrs=None):
self.executables = None
self.ctools = None
self.files = None
self.build_cexe = None
self.deprecated_scripts = None
self.zip_safe=False
self.sse = None
self.serenity=attrs['serenity']
ori_Distribution.__init__(self, attrs)
self.global_options.insert(0,('serenity', None, "install or build the package in a python virtualenv "
"without polluting the installed python and with many "
"checks during the installation process"
))
self.global_options.insert(0,('virtualenv', None, "if the installation is done using the serenity mode "
"this option allows for specifying the virtualenv name. "
"By default the name is PACKAGE-VERSION"
))
def run_commands(self):
"""Run each command that was seen on the setup script command line.
Uses the list of commands found and cache of command objects
created by 'get_command_obj()'.
"""
# self.run_command('littlebigman')
ori_Distribution.run_commands(self)
def has_executables(self):
return self.executables is not None and self.executables
def has_ctools(self):
return self.ctools is not None and self.ctools
def has_files(self):
return self.files is not None and self.files
def has_deprecated_scripts(self):
return self.deprecated_scripts is not None and self.deprecated_scripts

View File

@ -1,118 +0,0 @@
import sys
from distutils import util
from distutils import sysconfig
from distutils import log
from distutils.version import LooseVersion, StrictVersion
import glob
import os
import subprocess
import re
from distutils.errors import DistutilsError
import tempfile
from importlib.util import spec_from_file_location # @UnresolvedImport
import zipimport
import argparse
import base64
from .checkpython import is_python_version
from obidistutils.serenity.rerun import enforce_good_python
from obidistutils.serenity.rerun import rerun_with_anothe_python
from obidistutils.serenity.virtual import serenity_virtualenv
from obidistutils.serenity.checksystem import is_mac_system, \
is_windows_system
from obidistutils.serenity.checkpackage import install_requirements
from obidistutils.serenity.checkpackage import check_requirements
from obidistutils.serenity.util import save_argv
from obidistutils.serenity.snake import snake
def serenity_snake(envname,package,version):
old = log.set_threshold(log.INFO)
log.info("Installing %s (%s) in serenity mode" % (package,version))
enforce_good_python()
virtualpython=serenity_virtualenv(envname,package,version)
if virtualpython!=os.path.realpath(sys.executable):
log.info("Restarting installation within the %s virtualenv" % (envname))
rerun_with_anothe_python(virtualpython)
log.info("%s will be installed with python : %s" % (package,virtualpython))
if install_requirements():
log.info("Restarting installation with all dependencies ok")
rerun_with_anothe_python(virtualpython)
log.set_threshold(old)
def serenity_assert(version):
check_requirements()
def is_serenity():
from obidistutils.serenity.globals import local_serenity
return local_serenity and local_serenity[0]
def serenity_mode(package,version):
save_argv()
from obidistutils.serenity.globals import saved_args
from obidistutils.serenity.globals import local_serenity
old = log.set_threshold(log.INFO)
argparser = argparse.ArgumentParser(add_help=False)
argparser.add_argument('--serenity',
dest='serenity',
action='store_true',
default=True,
help='Switch the installer in serenity mode. Everythings are installed in a virtualenv')
argparser.add_argument('--no-serenity',
dest='serenity',
action='store_false',
default=True,
help='Switch the installer in the no serenity mode.')
argparser.add_argument('--virtualenv',
dest='virtual',
type=str,
action='store',
default="%s-%s" % (package,version),
help='Specify the name of the virtualenv used by the serenity mode [default: %s-%s]' % (package,version))
args, unknown = argparser.parse_known_args()
sys.argv = [sys.argv[0]] + unknown
if args.serenity:
local_serenity.append(True)
serenity_snake(args.virtual,package,version)
else:
local_serenity.append(False)
log.set_threshold(old)
return args.serenity
def getVersion(source,main,version):
path = os.path.join(source,main,'%s.py' % version)
spec = spec_from_file_location('version',path)
return spec.loader.load_module().version.strip()

View File

@ -1,36 +0,0 @@
'''
Created on 22 janv. 2016
@author: coissac
'''
import sys
from urllib import request
import os.path
from obidistutils.serenity.util import get_serenity_dir
from obidistutils.serenity.rerun import rerun_with_anothe_python
from obidistutils.serenity.checkpython import is_a_virtualenv_python
getpipurl="https://bootstrap.pypa.io/get-pip.py"
def bootstrap():
getpipfile=os.path.join(get_serenity_dir(),"get-pip.py")
with request.urlopen(getpipurl) as getpip:
with open(getpipfile,"wb") as out:
for l in getpip:
out.write(l)
python = sys.executable
if is_a_virtualenv_python():
command= "%s %s" % (python,getpipfile)
else:
command= "%s %s --user" % (python,getpipfile)
os.system(command)
rerun_with_anothe_python(python)

View File

@ -1,175 +0,0 @@
'''
Created on 2 oct. 2014
@author: coissac
'''
import re
from distutils.version import StrictVersion # @UnusedImport
from distutils.errors import DistutilsError
from distutils import log
import os.path
import sys
import subprocess
class RequirementError(Exception):
pass
def is_installed(requirement):
pipcommand = os.path.join(os.path.dirname(sys.executable),'pip')
pipjson = subprocess.run([pipcommand,"list","--format=json"],
capture_output=True).stdout
packages = eval(pipjson)
requirement_project,requirement_relation,requirement_version = parse_package_requirement(requirement)
package = [x for x in packages if x["name"]==requirement_project]
if len(package)==1:
if ( requirement_version is not None
and requirement_relation is not None):
rep = (len(package)==1) and eval("StrictVersion('%s') %s StrictVersion('%s')" % (package[0]["version"],
requirement_relation,
requirement_version)
)
else:
rep=True
else:
rep=False
if rep:
if requirement_version is not None and requirement_relation is not None:
log.info("Look for package %s (%s%s) : ok version %s installed" % (requirement_project,
requirement_relation,
requirement_version,
package[0]["version"]))
else:
log.info("Look for package %s : ok version %s installed" % (requirement_project,
package[0]["version"]))
else:
if len(package)!=1:
if requirement_version is not None and requirement_relation is not None:
log.info("Look for package %s (%s%s) : not installed" % (requirement_project,
requirement_relation,
requirement_version))
else:
log.info("Look for package %s : not installed" % requirement_project)
else:
log.info("Look for package %s (%s%s) : failed only version %s installed" % (requirement_project,
requirement_relation,
requirement_version,
package[0]["version"]))
return rep
def get_requirements(requirementfile='requirements.txt'):
try:
requirements = open(requirementfile).readlines()
requirements = [x.strip() for x in requirements]
requirements = [x for x in requirements if x[0]!='-']
except IOError:
requirements = []
return requirements
def install_requirements(requirementfile='requirements.txt'):
install_something=False
requirements = get_requirements(requirementfile)
log.info("Required packages for the installation :")
for x in requirements:
ok = is_installed(x)
if not ok:
log.info(" Installing requirement : %s" % x)
pip_install_package(x,requirement=requirementfile)
install_something=True
if x[0:3]=='pip':
return True
return install_something
def check_requirements(requirementfile='requirements.txt'):
requirements = get_requirements(requirementfile)
log.info("Required packages for the installation :")
for x in requirements:
ok = is_installed(x)
if not ok:
raise RequirementError(" Missing requirement : %s -- Package installation stopped" % x)
def parse_package_requirement(requirement):
version_pattern = re.compile('[=><]+(.*)$')
project_pattern = re.compile('[^=><]+')
relationship_pattern = re.compile('[=><]+')
try:
requirement_project = project_pattern.search(requirement).group(0)
requirement_version = version_pattern.search(requirement)
if requirement_version is not None:
requirement_version=requirement_version.group(1)
requirement_relation= relationship_pattern.search(requirement)
if requirement_relation is not None:
requirement_relation=requirement_relation.group(0)
except:
raise DistutilsError("Requirement : %s not correctly formated" % requirement)
return requirement_project,requirement_relation,requirement_version
def get_package_requirement(package,requirementfile='requirements.txt'):
requirements = get_requirements(requirementfile)
req = [x for x in requirements
if x[0:len(package)]==package
]
if len(req)==1:
return req[0]
else:
return None
def pip_install_package(package,directory=None,requirement=None):
pipcommand = os.path.join(os.path.dirname(sys.executable),'pip')
if directory is not None:
log.info(' installing %s in directory %s' % (package,str(directory)))
if 'http_proxy' in os.environ and 'https_proxy' not in os.environ:
os.environ['https_proxy']=os.environ['http_proxy']
args = ['install']
if requirement:
args.append('--requirement')
args.append(requirement)
if 'https_proxy' in os.environ:
args.append('--proxy=%s' % os.environ['https_proxy'])
if directory is not None:
args.append('--target=%s' % directory)
args.append(package)
pip = subprocess.run([pipcommand] + args)
return pip

View File

@ -1,138 +0,0 @@
'''
Created on 24 mai 2015
@author: coissac
'''
from distutils.version import StrictVersion
from distutils import sysconfig
import subprocess
import os
import glob
import re
from obidistutils.serenity.checksystem import is_windows_system
import sys
def is_python_version(path=None,minversion='3.4',maxversion=None):
'''
Checks that the python version is in the range {minversion,maxversion[
@param path: if None consider the running python
otherwise the python pointed by the path
@param minversion: the minimum version to consider
@param maxversion: the maximum version to consider (strictly inferior to)
@return: True if the python version match
@rtype: bool
'''
if path is None:
pythonversion = StrictVersion(sysconfig.get_python_version())
else:
command = """'%s' -c 'from distutils import sysconfig; """ \
"""print(sysconfig.get_python_version())'""" % path
p = subprocess.Popen(command,
shell=True,
stdout=subprocess.PIPE)
pythonversion=str(p.communicate()[0],'utf8').strip()
pythonversion = StrictVersion(pythonversion)
return ( pythonversion >=StrictVersion(minversion)
and ( maxversion is None
or pythonversion < StrictVersion(maxversion))
)
def lookfor_good_python(minversion='3.4',maxversion=None,followLink=False):
'''
Look for all python interpreters present in the system path that
match the version constraints.
@param minversion: the minimum version to consider
@param maxversion: the maximum version to consider (strictly inferior to)
@param followLink: a boolean value indicating if link must be substituted
by their real path.
@return: a list of path to interpreters
'''
exe = []
if not is_windows_system():
paths = os.environ['PATH'].split(os.pathsep)
for p in paths:
candidates = glob.glob(os.path.join(p,'python*'))
pexe = []
pythonpat=re.compile('python([0-9]|[0-9]\.[0-9])?$')
for e in candidates:
print(e)
if pythonpat.search(e) is not None:
if followLink and os.path.islink(e):
e = os.path.realpath(e)
if (os.path.isfile(e) and
os.access(e, os.X_OK) and
is_python_version(e,minversion,maxversion)):
pexe.append(e)
exe.extend(set(pexe))
return exe
def is_a_virtualenv_python(path=None):
'''
Check if the python is belonging a virtualenv
@param path: the path pointing to the python executable.
if path is None then the running python is
considered.
@param path: str or None
@return: True if the python belongs a virtualenv
False otherwise
@rtype: bool
'''
if path is None:
rep = sys.base_exec_prefix != sys.exec_prefix
else:
command = """'%s' -c 'import sys; print(sys.base_exec_prefix != sys.exec_prefix)'""" % path
p = subprocess.Popen(command,
shell=True,
stdout=subprocess.PIPE)
rep = eval(str(p.communicate()[0],'utf8'))
return rep
def which_virtualenv(path=None,full=False):
'''
Returns the name of the virtualenv.
@param path: the path to a python binary or None
if you want to consider the running python
@type path: str or None
@param full: if set to True, returns the absolute path,
otherwise only return a simple directory name
@type full: bool
@return: the virtual environment name or None if the
path does not belong a virtualenv
@rtype: str or None
'''
if path is None:
path = sys.executable
if is_a_virtualenv_python(path):
parts = path.split(os.sep)
try:
if full:
rep = os.sep.join(parts[0:parts.index('bin')])
rep = os.path.realpath(rep)
else:
rep = parts[parts.index('bin')-1]
except ValueError:
rep = None
else:
rep=None
return rep

View File

@ -1,18 +0,0 @@
'''
Created on 24 mai 2015
@author: coissac
'''
from distutils import util
def is_mac_system():
platform = util.get_platform().split('-')[0]
return platform=='macosx'
def is_windows_system():
platform = util.get_platform().split('-')[0]
return platform=='Windows'

View File

@ -1,14 +0,0 @@
'''
Created on 24 mai 2015
@author: coissac
'''
saved_args=[]
tmpdir=[]
local_pip=[]
local_virtualenv=[]
local_cython=[]
local_serenity=[]

View File

@ -1,61 +0,0 @@
'''
Created on 24 mai 2015
@author: coissac
'''
import sys
import os
from distutils import log
from distutils.errors import DistutilsError
from obidistutils.serenity.globals import saved_args
from obidistutils.serenity.checkpython import is_python_version,\
lookfor_good_python
def rerun_with_anothe_python(path, minversion='3.4',maxversion=None, fork=False):
if saved_args:
args = saved_args
else:
args = list(sys.argv)
assert is_python_version(path,minversion,maxversion), \
'the selected python is not adapted to the installation of this package'
args.insert(0, path)
sys.stderr.flush()
sys.stdout.flush()
if fork:
log.info('Forking a new install process')
os.system(' '.join(list(args)))
log.info('External process ended')
sys.exit(0)
else:
log.info('Install script restarting...')
os.execv(path,list(args))
def enforce_good_python(minversion='3.4',maxversion=None, fork=False):
if is_python_version(minversion=minversion,maxversion=maxversion):
log.info('You are running the good python')
return True
goodpython = lookfor_good_python(minversion,maxversion)
if not goodpython:
raise DistutilsError('No good python identified on your system')
goodpython=goodpython[0]
log.warn("========================================")
log.warn("")
log.warn(" Switching to python : %s" % goodpython)
log.warn("")
log.warn("========================================")
rerun_with_anothe_python(goodpython)

View File

@ -1,35 +0,0 @@
'''
Created on 2 oct. 2014
@author: coissac
'''
snake ="""
___
,'._,`.
(-.___.-)
(-.___.-)
`-.___.-'
(( @ @| . __
\ ` | ,\ |`. @| | | _.-._
__`.`=-=mm===mm:: | | |`. | | | ,'=` '=`.
( `-'|:/ /:/ `/ @| | | |, @| @| /---)W(---\
\ \ / / / / @| | ' (----| |----) ,~
|\ \ / /| / / @| \---| |---/ |
| \ V /||/ / `.-| |-,' |
| `-' |V / \| |/ @'
| , |-' __| |__
| .;: _,-. ,--""..| |..""--.
;;:::' " ) (`--::__|_|__::--')
,-" _, / \`--...___...--'/
( -:--'/ / /`--...___...--'\
"-._ `"'._/ /`---...___...---'\
"-._ "---. (`---....___....---')
.' ",._ ,' ) |`---....___....---'|
/`._| `| | (`---....___....---')
( \ | / \`---...___...---'/
`. `, ^"" `:--...___...--;'
`.,' hh `-._______.-'
"""

View File

@ -1,27 +0,0 @@
'''
Created on 2 oct. 2014
@author: coissac
'''
import sys
import tempfile
from obidistutils.serenity.globals import tmpdir # @UnusedImport
from obidistutils.serenity.globals import saved_args # @UnusedImport
def get_serenity_dir():
global tmpdir
if not tmpdir:
tmpdir.append(tempfile.mkdtemp())
return tmpdir[0]
def save_argv():
global saved_args
del saved_args[:]
saved_args.extend(list(sys.argv))

View File

@ -1,69 +0,0 @@
'''
Created on 2 oct. 2014
@author: coissac
'''
import os
import sys
import venv
from distutils.errors import DistutilsError
from .globals import local_virtualenv # @UnusedImport
from .checkpython import which_virtualenv,\
is_python_version, \
is_a_virtualenv_python
def serenity_virtualenv(envname,package,version,minversion='3.4',maxversion=None):
#
# Checks if we are already running under the good virtualenv
#
ve = which_virtualenv(full=True)
if ve == os.path.realpath(envname) and is_python_version(minversion=minversion,maxversion=maxversion):
return sys.executable
#
# Check if the virtualenv exist
#
python = None
if os.path.isdir(envname):
python = os.path.join(envname,'bin','python')
ok = (is_python_version(python,
minversion=minversion,
maxversion=maxversion) and
is_a_virtualenv_python(python))
#
# The virtualenv already exist but it is not ok
#
if not ok:
raise DistutilsError("A virtualenv %s already exists but not with the required python")
else:
ok = False
#
# Creates a new virtualenv
#
if not ok:
venv.create(envname,
system_site_packages=False,
clear=True,
symlinks=False,
with_pip=True)
# check the newly created virtualenv
return serenity_virtualenv(envname,package,version)
return os.path.realpath(python)

View File

@ -1,24 +0,0 @@
/*
* littlebigman.c
*
* Created on: 11 juil. 2012
* Author: coissac
*/
#include <stdio.h>
int main(int argc, char *argv[])
{
union { int entier;
char caractere[4] ;
} test;
test.entier=0x01020304;
if (test.caractere[3] == 1)
printf("-DLITTLE_END");
else
printf("-DBIG_END");
return 0;
}

View File

@ -1,24 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <libproc.h>
int main (int argc, char* argv[])
{
pid_t pid; int ret;
char pathbuf[PROC_PIDPATHINFO_MAXSIZE];
if ( argc > 1 ) {
pid = (pid_t) atoi(argv[1]);
ret = proc_pidpath (pid, pathbuf, sizeof(pathbuf));
if ( ret <= 0 ) {
fprintf(stderr, "PID %d: proc_pidpath ();\n", pid);
fprintf(stderr, " %s\n", strerror(errno));
} else {
printf("proc %d: %s\n", pid, pathbuf);
}
}
return 0;
}

2
doc/sphinx/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
.DS_Store
/build_dir.txt

1
python/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/OBITools3.egg-info/

168
setup.py
View File

@ -1,87 +1,125 @@
#!/usr/bin/env python
import glob
import os
import sys
import re
import subprocess
from distutils.core import setup,Extension
from distutils.sysconfig import get_python_lib
from Cython.Build import cythonize
import os.path
from distutils import log
from distutils.extension import Extension
sys.path.append(os.path.abspath("python"))
dependencies = ['sphinx',"Cython"]
def findPackage(root,base=None):
modules=[]
if base is None:
base=[]
for module in (os.path.basename(os.path.dirname(x))
for x in glob.glob(os.path.join(root,'*','__init__.py'))):
modules.append('.'.join(base+[module]))
modules.extend(findPackage(os.path.join(root,module),base+[module]))
return modules
PACKAGE = "OBITools3"
VERSION = "0.0.0"
AUTHOR = 'Eric Coissac'
EMAIL = 'eric@coissac.eu'
URL = 'metabarcoding.org/obitools3'
LICENSE = 'CeCILL-V2'
DESCRIPTION ="Scripts and library for DNA metabarcoding",
EMAIL = 'eric@metabarcoding.org'
URL = "metabarcoding.org/obitools3"
LICENSE = "CeCILL-V2"
DESCRIPTION = "Tools and library for DNA metabarcoding",
PYTHONMIN = '3.6'
SRC = 'python'
CSRC = 'src'
REQUIRES = ['Cython>=0.24',
'Sphinx>=1.2.0',
'ipython>=3.0.0',
'breathe>=4.0.0'
]
os.environ['CFLAGS'] = '-O3 -Wall -I "src" -I "src/libecoPCR" -I "src/libjson"'
#sys.path.append("/Users/coissac/git/obitools3/python")
cython_src = [x for x in glob.iglob('python/obitools3/**/*.pyx',
recursive=True
)
]
#with open(os.path.join(os.path.dirname(__file__), 'README.rst')) as f:
# readme = f.read()
install_clibdir_option="-DPYTHONLIB:STRING='%s'" % get_python_lib()
subprocess.call(['cmake', install_clibdir_option, 'src'])
subprocess.call(['make', '-C', 'src','install'])
cython_ext = [Extension('.'.join([os.path.dirname(x).replace("python/",""),
os.path.splitext(os.path.basename(x))[0]]).replace('/','.'),
[x],
library_dirs=[get_python_lib()],
include_dirs=["src","src/libecoPCR","src/libjson"],
libraries=["cobitools3"],
runtime_library_dirs=[get_python_lib()],
extra_compile_args=['-msse2',
'-Wno-unused-function',
'-Wmissing-braces',
'-Wchar-subscripts',
'-fPIC'
],
extra_link_args=["-Wl,-rpath,"+get_python_lib(),
"-L"+get_python_lib()
]
)
for x in cython_src
]
xx = cythonize(cython_ext,
language_level=3,
annotate=True,
build_dir="build")
#, include_path=["src","src/libecoPCR","src/libjson"]
classifiers=['Development Status :: 1 - Planning',
'Environment :: Console',
'Intended Audience :: Science/Research',
'License :: Other/Proprietary License',
'Operating System :: Unix',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: C',
'Topic :: Scientific/Engineering :: Bio-Informatics',
'Topic :: Utilities',
]
PYTHONMIN='3.4'
sys.path.append('distutils.ext')
sys.path.append(SRC)
if __name__=="__main__":
import sys
print("----------------")
print(" ".join(sys.argv))
print("----------------")
#
# Horrible hack
#
if sys.argv[0]=="-c":
sys.argv[0]="setup.py"
#
# End of the horrible hack
#
try:
from obitools3 import version
VERSION = version.version
except ImportError:
pass
from obidistutils.serenity import serenity_mode
serenity=serenity_mode(PACKAGE,VERSION)
from obidistutils.core import setup
from obidistutils.core import CTOOLS
from obidistutils.core import CEXES
from obidistutils.core import FILES
# Produce annotated html files
import Cython.Compiler.Options
Cython.Compiler.Options.annotate = True
setup(name=PACKAGE,
description=DESCRIPTION,
classifiers=classifiers,
version=VERSION,
author=AUTHOR,
author_email=EMAIL,
license=LICENSE,
url=URL,
python_src=SRC,
sse='sse2',
serenity=serenity,
pythonmin=PYTHONMIN)
setup(name=PACKAGE,
description=DESCRIPTION,
classifiers=classifiers,
version=VERSION,
author=AUTHOR,
author_email=EMAIL,
license=LICENSE,
url=URL,
ext_modules=xx,
packages = findPackage('python'),
package_dir = {"" : "python"},
scripts = ['scripts/obi']
)

5
src/.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
/CMakeFiles/
/CMakeCache.txt
/cmake_install.cmake
/libcobitools3.dylib
/Makefile

66
src/CMakeLists.txt Normal file
View File

@ -0,0 +1,66 @@
cmake_minimum_required(VERSION 3.12)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
SET(PYTHONLIB "po" CACHE STRING "Location of the python site-package directory")
project (cobitools3)
set(CMAKE_BUILD_TYPE Release)
SET(CMAKE_C_COMPILER gcc)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
file(GLOB_RECURSE CSRC "*.c")
add_library(cobitools3 SHARED obierrno.c
obidms_taxonomy.c
obiblob_indexer.c
obi_lcs.c
obidmscolumn_str.c
bloom.c
build_reference_db.c
obidmscolumn_array.c
obidmscolumn_idx.c
obidmscolumn_bool.c
libjson/json_utils.c
libjson/cJSON.c
obidmscolumn_blob.c
dna_seq_indexer.c
obi_ecotag.c
encode.c
obiavl.c
sse_banded_LCS_alignment.c
kmer_similarity.c
obidmscolumn_qual.c
obi_clean.c
utils.c
uint8_indexer.c
murmurhash2.c
obidmscolumn_char.c
obiview.c
obidmscolumn_int.c
linked_list.c
obiblob.c
hashtable.c
obidmscolumn.c
char_str_indexer.c
obidmscolumn_float.c
upperband.c
crc64.c
obidmscolumn_seq.c
obilittlebigman.c
obidmscolumndir.c
obidms.c
obi_ecopcr.c
libecoPCR/libthermo/nnparams.c
libecoPCR/ecoapat.c
libecoPCR/libapat/libstki.c
libecoPCR/libapat/apat_search.c
libecoPCR/libapat/apat_parse.c
libecoPCR/ecodna.c
libecoPCR/ecoMalloc.c
libecoPCR/ecoError.c
obitypes.c
array_indexer.c)
install(TARGETS cobitools3 DESTINATION ${PYTHONLIB})