def build(self, libsources=None, libdirs=None, compiler=None): if _exists(self.extfile, self.tempdir): # DLL file already exists and we can't overwrite it at this time self._fail() return common = ["integration.c", "interface.c", "eventFinding.c", "memory.c"] sources = [os.path.join(self.tempdir, self.vfname + ".c")] sources.extend(self.sources) sources.extend(full_path(common)) sources.extend(libsources or []) # The following if statement attempts to avoid recompiling the SWIG # wrapper if the files mentioned already exist, because in principle # the SWIG interface only needs compiling once. But this step doesn't # seem to work yet. Instead, it seems that SWIG always gets recompiled # with everything else (at least on Win32). Maybe the list of files is # incorrect... swigfile = self._prepare_swig_file() files = [t.format(self.modname) for t in ['{0}_wrap.o', 'lib_{0}.a', '{0}.py', '_{0}.def']] if not all(_exists(f, self.tempdir) for f in files): sources.append(swigfile) script_args = [ "build_ext", "--inplace", "--verbose", "--build-temp={0}".format(self.tempdir), ] if compiler: script_args.append("-c" + str(compiler)) # include directories for libraries incdirs = [get_include()] incdirs.extend([os.getcwd(), _sourcedir]) incdirs.extend(libdirs or []) # Use distutils to perform the compilation of the selected files extmod = Extension( '.'.join([self.tempdir, "_" + self.modname]), sources=sources, include_dirs=incdirs, extra_compile_args=utils.extra_arch_arg( ["-w", "-std=c99", "-Wall", "-Wno-unused-function"]) + self.cflags, extra_link_args=utils.extra_arch_arg(["-w"]), libraries=self.libs ) with RedirectStdout(os.path.join(self.tempdir, 'build.log')): setup(name=self.description, author="PyDSTool (automatically generated)", script_args=script_args, ext_modules=[extmod], py_modules=[self.modname])
def compileAutoLib(self, libsources=[], libdirs=[]): """compileAutoLib generates a python extension DLL with continuer and vector field compiled and linked. libsources list allows additional library sources to be linked. libdirs list allows additional directories to be searched for precompiled libraries.""" if os.path.isfile(os.path.join(os.getcwd(), "_auto"+self._vf_filename_ext+self._dllext)): # then DLL file already exists and we can't overwrite it at this # time proceed = False print("\n") print("-----------------------------------------------------------") print("Present limitation of Python: Cannot rebuild library") print("without exiting Python and deleting the shared library") print(" " + str(os.path.join(os.getcwd(), "_auto"+self._vf_filename_ext+self._dllext))) print("by hand! If you made any changes to the system you should") print("not proceed with running the integrator until you quit") print("and rebuild.") print("-----------------------------------------------------------") print("\n") else: proceed = True if not proceed: print("Did not compile shared library.") return if self._autoMod is not None: self.forceAutoLibRefresh() vffile = os.path.join(self._compilation_tempdir, self._vf_file) try: ifacefile_orig = open(os.path.join(self._compilation_sourcedir, "automod.i"), 'r') ifacefile_copy = open(os.path.join(self._compilation_tempdir, "auto_"+self._vf_file[:-2]+".i"), 'w') firstline = ifacefile_orig.readline() ifacefile_copy.write('%module auto_'+self._vf_file[:-2]+'\n') iffilestr = ifacefile_orig.read() ifacefile_copy.write(iffilestr) ifacefile_orig.close() ifacefile_copy.close() except IOError: print("automod.i copying error in auto compilation directory") raise swigfile = os.path.join(self._compilation_tempdir, "auto"+self._vf_filename_ext+".i") automodfile = os.path.join(self._compilation_sourcedir, "automod.c") interfacefile = os.path.join(self._compilation_sourcedir, "interface.c") # source files if not (all([os.path.isfile(os.path.join(self._compilation_tempdir, sf)) for sf in ['auto'+self._vf_filename_ext+'_wrap.o', 'auto'+self._vf_filename_ext+'.py', '_auto'+self._vf_filename_ext+'.def']])): modfilelist = [swigfile] else: modfilelist = [] # FOR DIST (ADD) modfilelist.extend([os.path.join(self._compilation_sourcedir, "../src/"+x) \ for x in ['auto.c','autlib1.c','autlib2.c','autlib3.c','autlib4.c','autlib5.c', \ 'eispack.c', 'conpar.c','setubv.c','reduce.c','dmatrix.c','fcon.c','libf2c/cabs.c','libf2c/d_lg10.c', \ 'libf2c/i_nint.c','libf2c/pow_di.c','libf2c/r_lg10.c','libf2c/z_exp.c','libf2c/d_imag.c', \ 'libf2c/d_sign.c','libf2c/i_dnnt.c','libf2c/pow_dd.c','libf2c/pow_ii.c','libf2c/z_abs.c', \ 'libf2c/z_log.c']]) modfilelist.extend([automodfile, interfacefile, vffile]) # FOR DIST (SUBTRACT) #modfilelist.extend(libsources) # script args script_args = ['-q', 'build', '--build-lib=.', #+os.getcwd(), # '-t/', '-tauto_temp', #+self._compilation_tempdir, '--build-base=auto_temp'] #+self._compilation_sourcedir] if self.gensys._compiler != '': script_args.append('-c'+str(self.gensys._compiler)) # include directories for libraries narraydir = get_numarray_include() npydir = get_include() incdirs = [narraydir, npydir, os.getcwd(), os.path.join(self._compilation_sourcedir,"include"), self._compilation_tempdir, os.path.join(_pydstool_path,"PyCont/auto/src/include")] incdirs.extend(libdirs) # libraries # FOR DIST (SUBTRACT) #libdirs.append(os.path.join(_pydstool_path, "PyCont/auto/lib")) #libsources.append('auto2000') # Use distutils to perform the compilation of the selected files rout.start() # redirect stdout try: distobject = setup(name = "Auto 2000 continuer", author = "PyDSTool (automatically generated)", script_args = script_args, ext_modules = [Extension("_auto"+self._vf_filename_ext, sources=modfilelist, include_dirs=incdirs, extra_compile_args=utils.extra_arch_arg(['-w', '-D__PYTHON__', '-std=c99']), extra_link_args=utils.extra_arch_arg(['-w']), library_dirs=libdirs+['./'], libraries=libsources)]) except: rout.stop() print("\nError occurred in generating Auto system...") print(sys.exc_info()[0], sys.exc_info()[1]) raise RuntimeError rout.stop() # restore stdout try: # move library files into the user's CWD distdestdir = distutil_destination() if swigfile in modfilelist or not \ os.path.isfile(os.path.join(self._compilation_tempdir, "auto"+self._vf_filename_ext+".py")): shutil.move(os.path.join(os.getcwd(), self._compilation_tempdir, distdestdir, "auto_temp", "auto"+self._vf_filename_ext+".py"), os.path.join(os.getcwd(), "auto"+self._vf_filename_ext+".py")) except: print("\nError occurred in generating Auto system") print("(while moving library extension modules to CWD)") print(sys.exc_info()[0], sys.exc_info()[1]) raise RuntimeError
def compileAutoLib(self, libsources=[], libdirs=[]): """compileAutoLib generates a python extension DLL with continuer and vector field compiled and linked. libsources list allows additional library sources to be linked. libdirs list allows additional directories to be searched for precompiled libraries.""" if os.path.isfile( os.path.join(os.getcwd(), "_auto" + self._vf_filename_ext + self._dllext)): # then DLL file already exists and we can't overwrite it at this # time proceed = False print("\n") print( "-----------------------------------------------------------") print("Present limitation of Python: Cannot rebuild library") print("without exiting Python and deleting the shared library") print(" " + str( os.path.join(os.getcwd(), "_auto" + self._vf_filename_ext + self._dllext))) print("by hand! If you made any changes to the system you should") print("not proceed with running the integrator until you quit") print("and rebuild.") print( "-----------------------------------------------------------") print("\n") else: proceed = True if not proceed: print("Did not compile shared library.") return if self._autoMod is not None: self.forceAutoLibRefresh() vffile = os.path.join(self._compilation_tempdir, self._vf_file) try: ifacefile_orig = open( os.path.join(self._compilation_sourcedir, "automod.i"), 'r') ifacefile_copy = open( os.path.join(self._compilation_tempdir, "auto_" + self._vf_file[:-2] + ".i"), 'w') firstline = ifacefile_orig.readline() ifacefile_copy.write('%module auto_' + self._vf_file[:-2] + '\n') iffilestr = ifacefile_orig.read() ifacefile_copy.write(iffilestr) ifacefile_orig.close() ifacefile_copy.close() except IOError: print("automod.i copying error in auto compilation directory") raise swigfile = os.path.join(self._compilation_tempdir, "auto" + self._vf_filename_ext + ".i") automodfile = os.path.join(self._compilation_sourcedir, "automod.c") interfacefile = os.path.join(self._compilation_sourcedir, "interface.c") # source files if not (all([ os.path.isfile(os.path.join(self._compilation_tempdir, sf)) for sf in [ 'auto' + self._vf_filename_ext + '_wrap.o', 'auto' + self._vf_filename_ext + '.py', '_auto' + self._vf_filename_ext + '.def' ] ])): modfilelist = [swigfile] else: modfilelist = [] # FOR DIST (ADD) modfilelist.extend([os.path.join(self._compilation_sourcedir, "../src/"+x) \ for x in ['auto.c','autlib1.c','autlib2.c','autlib3.c','autlib4.c','autlib5.c', \ 'eispack.c', 'conpar.c','setubv.c','reduce.c','dmatrix.c','fcon.c','libf2c/cabs.c','libf2c/d_lg10.c', \ 'libf2c/i_nint.c','libf2c/pow_di.c','libf2c/r_lg10.c','libf2c/z_exp.c','libf2c/d_imag.c', \ 'libf2c/d_sign.c','libf2c/i_dnnt.c','libf2c/pow_dd.c','libf2c/pow_ii.c','libf2c/z_abs.c', \ 'libf2c/z_log.c']]) modfilelist.extend([automodfile, interfacefile, vffile]) # FOR DIST (SUBTRACT) #modfilelist.extend(libsources) # script args script_args = [ '--verbose', 'build', '--build-lib=.', #+os.getcwd(), # '-t/', '-tauto_temp', #+self._compilation_tempdir, '--build-base=auto_temp' ] #+self._compilation_sourcedir] if self.gensys._compiler != '': script_args.append('-c' + str(self.gensys._compiler)) # include directories for libraries incdirs = [get_include()] incdirs.extend([ os.getcwd(), os.path.join(self._compilation_sourcedir, "include"), self._compilation_tempdir, os.path.join(_pydstool_path, "PyCont/auto/src/include") ]) incdirs.extend(libdirs) # libraries # FOR DIST (SUBTRACT) #libdirs.append(os.path.join(_pydstool_path, "PyCont/auto/lib")) #libsources.append('auto2000') # Use distutils to perform the compilation of the selected files with RedirectStdout(os.path.join('auto_temp', 'auto.log')): setup(name="Auto 2000 continuer", author="PyDSTool (automatically generated)", script_args=script_args, ext_modules=[ Extension("_auto" + self._vf_filename_ext, sources=modfilelist, include_dirs=incdirs, extra_compile_args=utils.extra_arch_arg( ['-w', '-D__PYTHON__', '-std=c99']), extra_link_args=utils.extra_arch_arg(['-w']), library_dirs=libdirs + ['./'], libraries=libsources) ]) try: # move library files into the user's CWD distdestdir = distutil_destination() if swigfile in modfilelist or not \ os.path.isfile(os.path.join(self._compilation_tempdir, "auto"+self._vf_filename_ext+".py")): shutil.move( os.path.join(os.getcwd(), self._compilation_tempdir, distdestdir, "auto_temp", "auto" + self._vf_filename_ext + ".py"), os.path.join(os.getcwd(), "auto" + self._vf_filename_ext + ".py")) except: print("\nError occurred in generating Auto system") print("(while moving library extension modules to CWD)") print(sys.exc_info()[0], sys.exc_info()[1]) raise RuntimeError