Commit 2a9577c7217921ba6f62b1a67fb91f4c5c73129d

Authored by knodlseder
1 parent 39ec93c0

break down interface into modules

pyext/Makefile.am
... ... @@ -5,38 +5,43 @@
5 5  
6 6 if WITH_PYTHON
7 7  
8   -# Set SWIG interface filename
9   -SWIG_INTERFACE = gammalib.i
10   -
11   -# Define the targets that should be built before anything else.
12   -# These are honored by 'make all', 'make check' and 'make install'.
13   -if HAVE_SWIG
14   - BUILT_SOURCES = gammalib_wrap.cpp gammalib.py
15   -endif
16   -
17   -# Set files to be removed in clean
18   -if HAVE_SWIG
19   - CLEANFILES = gammalib_wrap.cpp gammalib.py
20   -endif
21   -
22   -# Set extra files to distribute
23   -#EXTRA_DIST = runme.py
24   -
25   -# Set instrument specific SWIG options (those will be catched in gammalib.i)
  8 +# Set instrument specific SWIG targets
26 9 if WITH_INST_MWL
27   - OPT_MWL = -DWITH_INST_MWL
28   - INC_MWL = -I$(top_srcdir)/inst/mwl/pyext
  10 + MWL_SWIG_TARGETS = $(top_srcdir)/inst/mwl/pyext/mwl_wrap.cpp \
  11 + $(top_srcdir)/inst/mwl/pyext/mwl.py
29 12 endif
30 13 if WITH_INST_CTA
31   - OPT_CTA = -DWITH_INST_CTA
32   - INC_CTA = -I$(top_srcdir)/inst/cta/pyext
  14 + CTA_SWIG_TARGETS = $(top_srcdir)/inst/cta/pyext/cta_wrap.cpp \
  15 + $(top_srcdir)/inst/cta/pyext/cta.py
33 16 endif
34 17 if WITH_INST_LAT
35   - OPT_LAT = -DWITH_INST_LAT
36   - INC_LAT = -I$(top_srcdir)/inst/lat/pyext
  18 + LAT_SWIG_TARGETS = $(top_srcdir)/inst/lat/pyext/lat_wrap.cpp \
  19 + $(top_srcdir)/inst/lat/pyext/lat.py
  20 +endif
  21 +INST_SWIG_TARGETS = $(MWL_SWIG_TARGETS) $(CTA_SWIG_TARGETS) $(LAT_SWIG_TARGETS)
  22 +
  23 +# Sources that are required for the build. All targets in the list will be built
  24 +# before anything. These are honored by 'make all', 'make check' and 'make install'.
  25 +# We use this here to make sure that all these targets are build by swig before we
  26 +# start compiling the Python modules.
  27 +BUILT_SOURCES = gammalib/app_wrap.cpp gammalib/app.py \
  28 + gammalib/fits_wrap.cpp gammalib/fits.py \
  29 + gammalib/linalg_wrap.cpp gammalib/linalg.py \
  30 + gammalib/model_wrap.cpp gammalib/model.py \
  31 + gammalib/numerics_wrap.cpp gammalib/numerics.py \
  32 + gammalib/obs_wrap.cpp gammalib/obs.py \
  33 + gammalib/opt_wrap.cpp gammalib/opt.py \
  34 + gammalib/sky_wrap.cpp gammalib/sky.py \
  35 + gammalib/support_wrap.cpp gammalib/support.py \
  36 + gammalib/xml_wrap.cpp gammalib/xml.py \
  37 + $(INST_SWIG_TARGETS)
  38 +
  39 +# Set files to be removed in clean. We remove only the SWIG interface files if swig
  40 +# is available to rebuild them.
  41 +if HAVE_SWIG
  42 + CLEAN_FILES = $(BUILT_SOURCES)
37 43 endif
38   -INC_INST = $(INC_MWL) $(INC_CTA) $(INC_LAT)
39   -OPT_INST = $(OPT_MWL) $(OPT_CTA) $(OPT_LAT)
  44 +CLEANFILES = $(CLEAN_FILES)
40 45  
41 46 all-local: build
42 47  
... ... @@ -45,19 +50,23 @@ all-local: build
45 50 # of this specific directory. So we build one instance for checking, the other
46 51 # for installation. If we could get the name built by distutils we could avoid
47 52 # this.
48   -build: gammalib_wrap.cpp gammalib.py
49   - $(PYTHON_BUILD_PREFIX) $(PYTHON) setup.py build --build-platlib build
50   - $(PYTHON_BUILD_PREFIX) $(PYTHON) setup.py build
  53 +#$(PYTHON_BUILD_PREFIX) $(PYTHON) setup.py build_ext --build-platlib build
  54 +build: $(BUILT_SOURCES)
  55 + $(PYTHON_BUILD_PREFIX) $(PYTHON) setup.py build_ext
  56 +
  57 +# make check installs the gammalib extension for checking in the install directory
  58 +check-local:
  59 + $(PYTHON) setup.py install --home=install
51 60  
52 61 install-exec-local:
53 62 $(PYTHON) setup.py install --prefix=$(prefix)
54 63  
55 64 clean-local:
56   - rm -rf build
  65 + rm -rf build install
57 66  
58 67 if HAVE_SWIG
59   -gammalib_wrap.cpp gammalib.py: $(SWIG_INTERFACE)
60   - $(SWIG) -c++ -python -Wall -I$(top_srcdir)/src $(INC_INST) $(OPT_INST) -o gammalib_wrap.cpp -outdir . $(srcdir)/$(SWIG_INTERFACE)
  68 +%_wrap.cpp %.py: %.i
  69 + $(SWIG) -c++ -python -Wall -o $@ -outdir gammalib $<
61 70 endif # HAVE_SWIG
62 71  
63 72 endif # WITH_PYTHON
... ...
pyext/setup.py.in
... ... @@ -4,41 +4,27 @@ import glob
4 4 import os
5 5 import sys
6 6  
7   -# Removes list of bad prefixes from list
8   -def remove_prefixes(optlist, bad_prefixes):
9   - for bad_prefix in bad_prefixes:
10   - for i, flag in enumerate(optlist):
11   - if flag.startswith(bad_prefix):
12   - optlist.pop(i)
13   - break
14   - return optlist
15   -
16   -# Adjust compile options for darwin
17   -#if sys.platform.lower().startswith("darwin"):
18   -#
19   -# # Remove some time consuming options
20   -# cvars = sysconfig.get_config_vars()
21   -# cflags = cvars.get('OPT')
22   -# if cflags:
23   -# cflags = remove_prefixes(cflags.split(),
24   -# ['-g', '-O', '-Wstrict-prototypes', '-DNDEBUG'])
25   -# cvars['OPT'] = str.join(' ', cflags)
26   -# cvars['CFLAGS'] = cvars['BASECFLAGS'] + ' ' + cvars['OPT']
27   -#
28   -# # Remove -arch flags. This prevents building a fat library
29   -# cvars['ARCHFLAGS'] = ''
30   -#
31   -# # Signal darwin compiler adjustments
32   -# print 'Adjust default distutils compiler options for darwin.'
  7 +# Define package name
  8 +pkg_name = 'gammalib'
  9 +
  10 +# Define core modules
  11 +core_modules = ['app', 'fits', 'linalg', 'model', 'numerics', \
  12 + 'obs', 'opt', 'sky', 'support', 'xml']
  13 +
  14 +# Check on test install
  15 +if (len(sys.argv) == 3):
  16 + if (sys.argv[2] == '--home=install'):
  17 + print "This install is for unit testing."
  18 +
33 19  
34 20 # Set GammaLib library name. If we're about to make the test build then
35 21 # create a symbolic link to the static library to enforce static linking.
36 22 # This is required on some system (such as Mac OS X) to avoid problems
37 23 # with finding the shared library during unit testing.
38 24 libgamma='gamma'
39   -if (len(sys.argv) > 3):
40   - if (sys.argv[3] == 'build'):
41   -
  25 +if (len(sys.argv) > 1):
  26 + if (1 == 1):
  27 +
42 28 # Remove any existing symbolic link to libgamma.a. This will
43 29 # prevent any exception in creating the symbolic link due to
44 30 # an already existing link.
... ... @@ -58,16 +44,17 @@ if (len(sys.argv) &gt; 3):
58 44 print 'WARNING: Failed to create symbolic link to static library. Link dynamically.'
59 45  
60 46 # Set default include directories and data files
61   -include_dirs = ['@top_srcdir@/include']
62   -data_files = glob.glob('@top_srcdir@/pyext/*.i')
63   -library_dirs = ['../src/.libs']
64   -libraries = [libgamma]
  47 +include_dirs = ['@top_srcdir@/include']
  48 +data_files = glob.glob('@top_srcdir@/pyext/*.i')
  49 +library_dirs = ['../src/.libs']
  50 +libraries = [libgamma]
65 51  
66 52 # Set default runtime library directories
67 53 if os.path.exists('@prefix@/lib'):
68 54 runtime_library_dirs = ['@prefix@/lib']
69 55 else:
70 56 runtime_library_dirs = []
  57 +runtime_library_dirs = []
71 58  
72 59 # Add cfitsio library only if available
73 60 if '@WITH_CFITSIO_TRUE@' != '#':
... ... @@ -89,7 +76,7 @@ for extra_lib in extra_libs:
89 76 # Get extra library paths
90 77 extra_lib_paths = ('@LDFLAGS@').split(' ')
91 78 for extra_lib_path in extra_lib_paths:
92   - if extra_lib_path.lstrip().find('-L') == 0:
  79 + if extra_lib_path.lstrip().find('-L') == 0:
93 80 dir = extra_lib_path.lstrip().lstrip('-L')
94 81 if len(dir) > 0:
95 82 library_dirs.append(dir)
... ... @@ -98,37 +85,79 @@ for extra_lib_path in extra_lib_paths:
98 85 # Get extra include directories
99 86 extra_inc_paths = ('@CPPFLAGS@').split(' ')
100 87 for extra_inc_path in extra_inc_paths:
101   - if extra_inc_path.lstrip().find('-I') == 0:
  88 + if extra_inc_path.lstrip().find('-I') == 0:
102 89 dir = extra_inc_path.lstrip().lstrip('-I')
103 90 if len(dir) > 0:
104 91 include_dirs.append(dir)
105 92  
106   -# Add instrument specific include directories and data files
  93 +# Add definitions for instrument specific modules
  94 +inst_modules = []
107 95 if '@WITH_INST_MWL_TRUE@' != '#':
108 96 print "Include multi-wavelength interface in gammalib Python bindings."
109   - include_dirs.append('@top_srcdir@/inst/mwl/include')
110   - data_files.extend(glob.glob('@top_srcdir@/inst/mwl/pyext/*.i'))
  97 + inst_modules.append('mwl')
111 98 if '@WITH_INST_CTA_TRUE@' != '#':
112 99 print "Include CTA instrument interface in gammalib Python bindings."
113   - include_dirs.append('@top_srcdir@/inst/cta/include')
114   - data_files.extend(glob.glob('@top_srcdir@/inst/cta/pyext/*.i'))
  100 + inst_modules.append('cta')
115 101 if '@WITH_INST_LAT_TRUE@' != '#':
116 102 print "Include Fermi/LAT instrument interface in gammalib Python bindings."
117   - include_dirs.append('@top_srcdir@/inst/lat/include')
118   - data_files.extend(glob.glob('@top_srcdir@/inst/lat/pyext/*.i'))
  103 + inst_modules.append('lat')
  104 +
  105 +# Set extension definition for core modules
  106 +ext_modules = []
  107 +py_modules = []
  108 +for module in core_modules:
  109 +
  110 + # Define module
  111 + ext_module = Extension('_'+module, [pkg_name+'/'+module+'_wrap.cpp'], \
  112 + include_dirs=include_dirs, \
  113 + libraries=libraries,
  114 + library_dirs=library_dirs,
  115 + runtime_library_dirs=runtime_library_dirs)
  116 + ext_modules.append(ext_module)
  117 + py_modules.append(pkg_name+'.'+module)
  118 +
  119 +# Set extension definition for instrument dependent modules
  120 +for module in inst_modules:
  121 +
  122 + # Define paths
  123 + pyext_path = '@top_srcdir@/inst/'+module+'/pyext'
  124 + include_path = '@top_srcdir@/inst/'+module+'/include'
  125 +
  126 + # Set include directories for module
  127 + include_inst_dirs = include_dirs
  128 + include_inst_dirs.append(include_path)
  129 +
  130 + # Add SWIG files to data_files
  131 + data_files.extend(glob.glob(pyext_path+'/*.i'))
  132 +
  133 + # Define module
  134 + ext_module = Extension('_'+module, [pyext_path+'/'+module+'_wrap.cpp'], \
  135 + include_dirs=include_dirs, \
  136 + libraries=libraries,
  137 + library_dirs=library_dirs,
  138 + runtime_library_dirs=runtime_library_dirs)
  139 + ext_modules.append(ext_module)
  140 + py_modules.append(pkg_name+'.'+module)
  141 +
  142 +# Create gammalib/__init__.py file
  143 +file = open(pkg_name+'/__init__.py', 'w')
  144 +for module in core_modules:
  145 + file.write('from '+module+' import *\n')
  146 +for module in inst_modules:
  147 + file.write('from '+module+' import *\n')
  148 +file.close()
  149 +
119 150  
120 151 # Setup
121 152 setup(name='@PACKAGE_NAME@',
122 153 version='@PACKAGE_VERSION@',
123 154 description='gammalib Python bindings',
124   - author='Jurgen Knodlseder',
  155 + author='Juergen Knoedlseder',
125 156 author_email='@PACKAGE_BUGREPORT@',
126 157 url='http://gammalib.sourceforge.net/',
127   - py_modules=['gammalib'],
128   - ext_modules=[Extension('_gammalib', ['gammalib_wrap.cpp'],
129   - include_dirs=include_dirs,
130   - library_dirs=library_dirs,
131   - libraries=libraries,
132   - runtime_library_dirs=runtime_library_dirs)],
133   - data_files=[('@prefix@/share/gammalib/swig', data_files)],
134   - )
  158 + packages=[pkg_name],
  159 + ext_package=pkg_name,
  160 + ext_modules=ext_modules,
  161 + py_modules=py_modules,
  162 + )
  163 +#data_files=[('@prefix@/share/gammalib/swig', data_files)],
... ...