Package: scons-tool-swigpy
SConstool to generate Python modules usingSwig.InstallationThere are few ways to install this tool for your project.FrompypiThis method may be preferable if you build your project under a virtualenv. To
add swigpy tool frompypi, type (within your wirtualenv):pipinstallscons-tool-loaderscons-tool-swigpyor, if your project usespipenv:pipenvinstall--devscons-tool-loaderscons-tool-swigpyAlternatively, you may add this to yourPipfile[dev-packages]
scons-tool-loader = "*"
scons-tool-swigpy = "*"The tool will be installed as a namespaced packagesconstool.swigpyin project’s virtual environment. You may further usescons-tool-loaderto load the tool.As a git submoduleCreate new git repository:mkdir/tmp/prj&&cd/tmp/prjtouchREADME.rstgitinitAdd thescons-tool-swigpyas a submodule:gitsubmoduleaddgit://github.com/ptomulik/scons-tool-swigpy.gitsite_scons/site_tools/swigpyFor python 2.x create__init__.pyinsite_toolsdirectory:touchsite_scons/site_tools/__init__.pythis will allow to directly importsite_tools.swigpy(this may be required by other tools).Usage exampleGit-based projectsCreate some source files, for examplesrc/hello.hppandsrc/hello.cpp:// src/hello.hpp#ifndef HELLO_HPP
#define HELLO_HPPvoidhello();#endif// src/hello.cpp#include"hello.hpp"#include<iostream>voidhello(){std::cout<<"Hello"<<std::endl;}Create swig interface filesrc/hello.i// src/hello.i%modulehello;%{#include"hello.hpp"%}%include"hello.hpp"WriteSConstructfile:# SConstructenv=Environment(tools=['default','swigpy'])SConscript('src/SConscript',exports=['env'],variant_dir='build',duplicate=0)Writesrc/SConscript:# src/SConscriptImport(['env'])env.Append(SWIGPY_CPPPATH=['.'])env.Append(SWIGPY_LIBPATH=['.'])env.Append(SWIGPY_SWIGFLAGS=['-c++'])env.SharedLibrary('hello',['hello.cpp'])env.SwigPyModule('hello',SWIGPY_LIBS=['$SWIGPY_PYTHONLIB','hello'])Try it out:sconsThis shall create a librarybuild/libhello.soand all the files that
comprise its python wrapper:ptomulik@tea:$lsbuild/hello.oshello.pychello_wrap.cclibhello.sohello.py_hello.sohello_wrap.osTest the generated wrapper:cdbuildLD_LIBRARY_PATH='.'python>>>importhello>>>hello.hello()DetailsModule descriptionThe module provides aSwigPyModule()builder which generates python module
based on a swig interface*.ifile:SwigPyModule(modname, **overrides)Themodnameis a name of the module being generated, for example'foo'or'foo.bar'(note, it’s neither the source file name nor target file
name). Theoverridesoverwrite construction variables such asSWIGFLAGSorCFLAGS.Example 1:The following code expects afoo.iinterface file to be present and
generates python module defined by this file.SwigPyModule('foo')Example 2:The following code expects afoo/bar.iinterface file to be present
and generates python module defined by this file undeffoosubdirectory.SwigPyModule('foo.bar')Construction variablesConstruction variables used bySwigPyModuleare summarized in the following
table. Note that there are two groups of variables. The first group are the
well known variables such asCFLAGSorSWIGFLAGS. The second group are
the variables prefixed withSWIGPY_. These variables, if defined, overwrite
the well known variables when generating python bindings.VariableDefaultSWIGSWIGVERSIONSWIGFLAGSSWIGDIRECTORSUFFIXSWIGCFILESUFFIXSWIGCXXFILESUFFIXSWIGPATHSWIGINCPREFIXSWIGINCSUFFIXSWIGCOMCPPPATHSHLIBPREFIXCCFLAGSCFLAGSCXXFLAGSLIBSLIBPATHLDFLAGSSWIGPY_SWIGSWIGPY_SWIGVERSIONSWIGPY_SWIGFLAGS[-python','-builtin']SWIGPY_SWIGDIRECTORSUFFIXSWIGPY_SWIGCFILESUFFIXSWIGPY_SWIGCXXFILESUFFIXSWIGPY_SWIGPATHSWIGPY_SWIGINCPREFIXSWIGPY_SWIGINCSUFFIXSWIGPY_SWIGCOMSWIGPY_CPPPATH["$SWIGPY_PYTHONINCDIR"]SWIGPY_SHOBJPREFIXSWIGPY_SHOBJSUFFIXSWIGPY_SHLIBPREFIX'_'SWIGPY_SHLIBSUFFIX.pydon WindowsSWIGPY_LIBPREFIX'_'SWIGPY_LIBSUFFIXSWIGPY_IMPLIBPREFIX'_'SWIGPY_IMPLIBSUFFIXSWIGPY_WINDOWSEXPPREFIX'_'SWIGPY_WINDOWSEXPSUFFIXSWIGPY_CCSWIGPY_CXXSWIGPY_SHCCSWIGPY_SHCXXSWIGPY_CCFLAGSSWIGPY_CFLAGSSWIGPY_CXXFLAGSSWIGPY_SHCCFLAGSSWIGPY_SHCFLAGSSWIGPY_SHCXXFLAGSSWIGPY_LIBS["$SWIGPY_PYTHONLIB"]SWIGPY_LIBPATH["$SWIGPY_PYTHONLIBDIR"]SWIGPY_LINKFLAGSSWIGPY_M2SWIGFILElambda parts:path.join(*parts)+ '.i'SWIGPY_M2CFILElambda parts:path.join(*parts)SWIGPY_M2SHLIBFILElambda parts:path.join(*parts)TheSWIGPY_M2SWIGFILElambda determines the name of swig interface (source
file). TheSWIGPY_M2CFILEdetermines the name (without suffix) of theCorC++wrapper file being generated byswig. TheSWIGPY_M2SHLIBFILEdetermines the name of shared library that will contain the wrapper binary code
after compilation (without prefix and suffix). Thepartsprovided to any of
these macros are the parts ofmodname, that is they’re result ofmodname.split('.').LICENSECopyright (c) 2014-2018 by Pawel Tomulik <ptomulik@meil.pw.edu.pl>Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE