summaryrefslogtreecommitdiff
path: root/setup.py
blob: 9afd66ba8d7401e1828771de9f7b58067a7d6505 (plain)
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
from setuptools import setup, find_packages, Extension
import subprocess
import os

libraries = ['boost_python']
extra_objects = []

if 'VIRTUAL_ENV' in os.environ:
    boost_lib = os.path.join(os.environ['VIRTUAL_ENV'],'lib','libboost_python.so')
    print boost_lib
    if os.path.exists(boost_lib):
        # use local copy of boost
        extra_objects.append(boost_lib)
        libraries.remove('boost_python')

def check_output(*popenargs, **kwargs):
    if 'stdout' in kwargs:
        raise ValueError('stdout argument not allowed, it will be overridden.')
    process = subprocess.Popen(stdout=subprocess.PIPE, *popenargs, **kwargs)
    output, unused_err = process.communicate()
    retcode = process.poll()
    if retcode:
        cmd = kwargs.get("args")
        if cmd is None:
            cmd = popenargs[0]
        raise subprocess.CalledProcessError(retcode, cmd, output=output)
    return output

geant4_cflags = check_output(['geant4-config','--cflags']).split()
geant4_libs = check_output(['geant4-config','--libs']).split()
# For GEANT4.9.4 built without cmake
try:
    clhep_libs = check_output(['clhep-config','--libs']).split()
except OSError:
    clhep_libs = []


include_dirs=['src']

##### figure out location of pyublas headers
try:
    from imp import find_module
    file, pathname, descr = find_module("pyublas")
    from os.path import join
    include_dirs.append(join(pathname, "include"))
except:
    pass  # Don't throw exceptions if prereqs not installed yet

#####

if 'VIRTUAL_ENV' in os.environ:
    include_dirs.append(os.path.join(os.environ['VIRTUAL_ENV'], 'include'))
try:
    import numpy.distutils
    include_dirs += numpy.distutils.misc_util.get_numpy_include_dirs()
except:
    pass # if numpy doesn't exist yet

setup(
    name = 'Chroma',
    version = '0.5',
    packages = find_packages(),
    include_package_data=True,

    scripts = ['bin/chroma-sim', 'bin/chroma-cam',
               'bin/chroma-geo', 'bin/chroma-bvh',
               'bin/chroma-server'],
    ext_modules = [
        Extension('chroma.generator._g4chroma',
                  ['src/G4chroma.cc'],
                  include_dirs=include_dirs,
                  extra_compile_args=geant4_cflags,
                  extra_link_args=geant4_libs+clhep_libs,
                  extra_objects=extra_objects,
                  libraries=libraries,
                  ),
        Extension('chroma.generator.mute',
                  ['src/mute.cc'],
                  include_dirs=include_dirs,
                  extra_compile_args=geant4_cflags,
                  extra_link_args=geant4_libs+clhep_libs,
                  extra_objects=extra_objects,
                  libraries=libraries),
        ],
 
    setup_requires = ['pyublas'],
    install_requires = ['uncertainties','pyzmq-static','spnav', 'pycuda', 
                        'numpy>=1.6', 'pygame', 'nose', 'sphinx', 'unittest2'],
    test_suite = 'nose.collector',
    
)