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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
setup.py file for @SICONOS_PYTHON_PACKAGE@ python package
This uses Distutils (http://python.org/sigs/distutils-sig/) the standard
python mechanism for installing packages. For the easiest installation
just type the command (you'll probably need root privileges for that):
python setup.py install
This will install the library in the default location. For instructions on
how to customize the install procedure read the output of:
python setup.py --help install
In addition, there are some other commands:
python setup.py clean -> will clean all trash (*.pyc and stuff)
python setup.py test -> will run the complete test suite
python setup.py bench -> will run the complete benchmark suite
To get a full list of avaiable commands, read the output of:
python setup.py --help-commands
"""
from numpy.distutils.core import setup, Extension
from numpy.distutils.command.build_py import build_py
from distutils.core import Command
from distutils.command.install_lib import install_lib
from distutils import dir_util
from distutils.core import Command
from distutils.file_util import copy_file
from numpy.distutils.misc_util import Configuration
import numpy as np
import glob
import os
import sys
# Modified from distutils.dir_util to not attempt to overwrite
# symlinks if already present.
def copy_tree(src, dst, preserve_mode=1, preserve_times=1,
preserve_symlinks=0, update=0, verbose=1, dry_run=0):
if not dry_run and not os.path.isdir(src):
raise DistutilsFileError("cannot copy tree '%s': not a directory" % src)
try:
names = os.listdir(src)
except os.error as er:
(errno, errstr) = er
if dry_run:
names = []
else:
raise DistutilsFileError("error listing files in '%s': %s" % (src, errstr))
if not dry_run:
dir_util.mkpath(dst, verbose=verbose)
outputs = []
for n in names:
src_name = os.path.join(src, n)
dst_name = os.path.join(dst, n)
if n.startswith('.nfs'):
# skip NFS rename files
continue
if preserve_symlinks and os.path.islink(src_name):
link_dest = os.readlink(src_name)
if not dry_run:
if os.path.exists(dst_name):
if os.readlink(dst_name) != link_dest:
os.remove(dst_name)
if verbose >= 1:
dir_util.log.info("linking %s -> %s", dst_name, link_dest)
os.symlink(link_dest, dst_name)
elif verbose >= 1:
dir_util.log.info("leaving %s -> %s", dst_name, link_dest)
else:
if verbose >= 1:
dir_util.log.info("linking %s -> %s", dst_name, link_dest)
os.symlink(link_dest, dst_name)
outputs.append(dst_name)
elif os.path.isdir(src_name):
outputs.extend(
copy_tree(src_name, dst_name, preserve_mode,
preserve_times, preserve_symlinks, update,
verbose=verbose, dry_run=dry_run))
else:
copy_file(src_name, dst_name, preserve_mode,
preserve_times, update, verbose=verbose,
dry_run=dry_run)
outputs.append(dst_name)
return outputs
# Make sure I have the right Python version.
if sys.version_info[:2] < (2,6):
print("Siconos requires Python 2.6 or newer. Python %d.%d detected".format(
sys.version_info[0], sys.version_info[1]))
sys.exit(-1)
class PyTest(Command):
"""To run tests using 'python setup.py test'
"""
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
import subprocess
import sys
errno = subprocess.call([sys.executable, 'runtests.py', 'build', '-s'])
raise SystemExit(errno)
class clean(Command):
"""Cleans *.pyc and debian trashs, so you should get the same copy as
is in the VCS.
"""
description = "remove build files"
user_options = [("all","a","the same")]
def initialize_options(self):
self.all = None
def finalize_options(self):
pass
def run(self):
import os
os.system("py.cleanup")
os.system("rm -f python-build-stamp-2.4")
os.system("rm -f MANIFEST")
os.system("rm -rf build")
os.system("rm -rf dist")
os.system("rm -rf doc/_build")
class build_py_symlink(build_py):
def build_module(self, module, module_file, package):
if isinstance(package, str):
package = package.split('.')
elif not isinstance(package, (list, tuple)):
raise TypeError(
"'package' must be a string (dot-separated), list, or tuple")
# Now put the module source file into the "build" area -- this is
# easy, we just copy it somewhere under self.build_lib (the build
# directory for Python source).
outfile = self.get_module_outfile(self.build_lib, package, module)
dir = os.path.dirname(outfile)
self.mkpath(dir)
if os.path.exists(outfile) and os.path.realpath(outfile) != module_file:
os.remove(outfile)
return copy_file(module_file, outfile, preserve_mode=0,
link='sym', update=True, verbose=1)
class install_lib_symlink(install_lib):
def install(self):
if os.path.isdir(self.build_dir):
outfiles = copy_tree(self.build_dir, self.install_dir,
preserve_symlinks=True, update=True, verbose=1)
else:
self.warn("'%s' does not exist -- no Python modules to install" %
self.build_dir)
return
return outfiles
class TestSiconos(Command):
"""Runs all tests under the tests/ folder
"""
description = "Run all tests and doctests; also see bin/test and bin/doctest"
user_options = [] # distutils complains if this is not here.
def __init__(self, *args):
self.args = args[0] # so we can pass it to other classes
Command.__init__(self, *args)
def initialize_options(self): # distutils wants this
pass
def finalize_options(self): # this too
pass
def run(self):
from subprocess import call
# hu?
call("py.test" + " siconos/tests", shell=True, env={"PYTHONPATH": "${CMAKE_BINARY_DIR}/wrap/"})
def get_cmake_option(option):
opt = option.upper()
return opt == "ON" or opt == "1" or opt == "TRUE"
# Full package name
name = '@SICONOS_PYTHON_PACKAGE@'
# List of python modules (directories) to be included
packages = ['siconos',
]
with_component = {}
components_list = "@SICONOS_PYTHON_MODULES@"
# kernel, numerics and io are just 'so' in siconos.
# This will probably change if we split each python interface for those packages.
#with_component['numerics'] = True
#with_component['kernel'] = "@HAVE_SICONOS_KERNEL@" is "TRUE"
with_component['control'] = get_cmake_option("@HAVE_SICONOS_CONTROL@")
with_component['mechanics'] = get_cmake_option("@HAVE_SICONOS_MECHANICS@")
with_component['io'] = get_cmake_option("@HAVE_SICONOS_IO@")
with_component['mechanisms'] = get_cmake_option("@HAVE_SICONOS_MECHANISMS@")
with_bullet = get_cmake_option("@WITH_BULLET@")
with_oce = get_cmake_option("@WITH_OCE@")
packages_for_tests = []
with_testing = get_cmake_option("@WITH_TESTING@")
if with_testing:
packages_for_tests.append('siconos.tests')
for comp in list(with_component.keys()):
if with_component[comp]:
packages.append('siconos.' + comp)
if with_component['mechanics']:
packages.append('siconos.mechanics.collision')
packages += packages_for_tests
# Enable this to get debug info
DISTUTILS_DEBUG = 1
# C files and swig interface
# swig =''
# for mod in packages_src_dirs:
# swig_dir = os.path.join(os.path.join('@CMAKE_SOURCE_DIR@', mod), 'swig')
#extra_link_args = ['-lopenblas', '-lgomp']
#swig_opts = ['-modern', '-I./']
#swig_ext = Extension('_numerics', swig, language='c++',
# swig_opts=swig_opts,
# extra_link_args=extra_link_args,
# extra_compile_args=[''])
ext_modules = []
include_dirs = [np.get_include()]
descr = 'Python bindings for the @PROJECT_NAME@ software.'
authors = 'Siconos team.'
cmdclass={'test': PyTest,
'clean': clean}
try:
install_symlinks = ("@INSTALL_PYTHON_SYMLINKS@".lower()=='on'
or "@INSTALL_PYTHON_SYMLINKS@".lower()=='true'
or int("@INSTALL_PYTHON_SYMLINKS@")!=0)
except ValueError:
install_symlinks = False
if install_symlinks:
cmdclass['build_py'] = build_py_symlink
cmdclass['install_lib'] = install_lib_symlink
config = Configuration(
name=name,
version='@SICONOS_VERSION@',
description=descr,
author=authors,
author_email='siconos-team@lists.gforge.fr',
url='http://siconos.gforge.inria.fr',
package_dir={'': '@CMAKE_CURRENT_BINARY_DIR@'},
ext_modules=ext_modules,
packages=packages,
py_modules=[],
include_dirs=include_dirs,
cmdclass=cmdclass,
classifiers=['License :: OSI Approved :: Apache Software License',
'Operating System :: MacOS',
'Operating System :: Microsoft :: Windows',
'Operating System :: POSIX :: Linux',
'Topic :: Scientific/Engineering :: Mathematics',
'Topic :: Scientific/Engineering :: Physics']
)
setup(**config.todict())
|