SCons tool to generate Python modules using Swig.
Installation
There are few ways to install this tool for your project.
From pypi
This method may be preferable if you build your project under a virtualenv. To add swigpy tool from pypi, type (within your wirtualenv):
pip install scons-tool-loader scons-tool-swigpy
or, if your project uses pipenv:
pipenv install --dev scons-tool-loader scons-tool-swigpy
Alternatively, you may add this to your Pipfile
[dev-packages]
scons-tool-loader = "*"
scons-tool-swigpy = "*"
The tool will be installed as a namespaced package sconstool.swigpy in project’s virtual environment. You may further use scons-tool-loader to load the tool.
As a git submodule
Create new git repository:
mkdir /tmp/prj && cd /tmp/prj touch README.rst git initAdd the scons-tool-swigpy as a submodule:
git submodule add git://github.com/ptomulik/scons-tool-swigpy.git site_scons/site_tools/swigpyFor python 2.x create __init__.py in site_tools directory:
touch site_scons/site_tools/__init__.pythis will allow to directly import site_tools.swigpy (this may be required by other tools).
Usage example
Git-based projects
Create some source files, for example src/hello.hpp and src/hello.cpp:
// src/hello.hpp #ifndef HELLO_HPP #define HELLO_HPP void hello(); #endif// src/hello.cpp #include "hello.hpp" #include <iostream> void hello() { std::cout << "Hello" << std::endl; }Create swig interface file src/hello.i
// src/hello.i %module hello; %{ #include "hello.hpp" %} %include "hello.hpp"Write SConstruct file:
# SConstruct env = Environment(tools = [ 'default', 'swigpy' ]) SConscript('src/SConscript', exports=['env'], variant_dir='build', duplicate=0)Write src/SConscript:
# src/SConscript Import(['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 library build/libhello.so and all the files that comprise its python wrapper:
ptomulik@tea:$ ls build/ hello.os hello.pyc hello_wrap.cc libhello.so hello.py _hello.so hello_wrap.osTest the generated wrapper:
cd build LD_LIBRARY_PATH='.' python >>> import hello >>> hello.hello()
Details
Module description
The module provides a SwigPyModule() builder which generates python module based on a swig interface *.i file:
SwigPyModule(modname, **overrides)
The modname is 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). The overrides overwrite construction variables such as SWIGFLAGS or CFLAGS.
Example 1:
The following code expects a foo.i interface file to be present and generates python module defined by this file.
SwigPyModule('foo')
Example 2:
The following code expects a foo/bar.i interface file to be present and generates python module defined by this file undef foo subdirectory.
SwigPyModule('foo.bar')
Construction variables
Construction variables used by SwigPyModule are summarized in the following table. Note that there are two groups of variables. The first group are the well known variables such as CFLAGS or SWIGFLAGS. The second group are the variables prefixed with SWIGPY_. These variables, if defined, overwrite the well known variables when generating python bindings.
Variable |
Default |
|---|---|
SWIG |
|
SWIGVERSION |
|
SWIGFLAGS |
|
SWIGDIRECTORSUFFIX |
|
SWIGCFILESUFFIX |
|
SWIGCXXFILESUFFIX |
|
SWIGPATH |
|
SWIGINCPREFIX |
|
SWIGINCSUFFIX |
|
SWIGCOM |
|
CPPPATH |
|
SHLIBPREFIX |
|
CCFLAGS |
|
CFLAGS |
|
CXXFLAGS |
|
LIBS |
|
LIBPATH |
|
LDFLAGS |
|
SWIGPY_SWIG |
|
SWIGPY_SWIGVERSION |
|
SWIGPY_SWIGFLAGS |
[-python', '-builtin'] |
SWIGPY_SWIGDIRECTORSUFFIX |
|
SWIGPY_SWIGCFILESUFFIX |
|
SWIGPY_SWIGCXXFILESUFFIX |
|
SWIGPY_SWIGPATH |
|
SWIGPY_SWIGINCPREFIX |
|
SWIGPY_SWIGINCSUFFIX |
|
SWIGPY_SWIGCOM |
|
SWIGPY_CPPPATH |
["$SWIGPY_PYTHONINCDIR"] |
SWIGPY_SHOBJPREFIX |
|
SWIGPY_SHOBJSUFFIX |
|
SWIGPY_SHLIBPREFIX |
'_' |
SWIGPY_SHLIBSUFFIX |
.pyd on Windows |
SWIGPY_LIBPREFIX |
'_' |
SWIGPY_LIBSUFFIX |
|
SWIGPY_IMPLIBPREFIX |
'_' |
SWIGPY_IMPLIBSUFFIX |
|
SWIGPY_WINDOWSEXPPREFIX |
'_' |
SWIGPY_WINDOWSEXPSUFFIX |
|
SWIGPY_CC |
|
SWIGPY_CXX |
|
SWIGPY_SHCC |
|
SWIGPY_SHCXX |
|
SWIGPY_CCFLAGS |
|
SWIGPY_CFLAGS |
|
SWIGPY_CXXFLAGS |
|
SWIGPY_SHCCFLAGS |
|
SWIGPY_SHCFLAGS |
|
SWIGPY_SHCXXFLAGS |
|
SWIGPY_LIBS |
["$SWIGPY_PYTHONLIB"] |
SWIGPY_LIBPATH |
["$SWIGPY_PYTHONLIBDIR"] |
SWIGPY_LINKFLAGS |
|
SWIGPY_M2SWIGFILE |
lambda parts: path.join(*parts) + '.i' |
SWIGPY_M2CFILE |
lambda parts: path.join(*parts) |
SWIGPY_M2SHLIBFILE |
lambda parts: path.join(*parts) |
The SWIGPY_M2SWIGFILE lambda determines the name of swig interface (source file). The SWIGPY_M2CFILE determines the name (without suffix) of the C or C++ wrapper file being generated by swig. The SWIGPY_M2SHLIBFILE determines the name of shared library that will contain the wrapper binary code after compilation (without prefix and suffix). The parts provided to any of these macros are the parts of modname, that is they’re result of modname.split('.').
LICENSE
Copyright (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
Metadata
Release files for scons-tool-swigpy 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| scons-tool-swigpy-0.1.2.tar.gz | 8.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| scons_tool_swigpy-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.3 kB
Release files / scons-tool-swigpy-0.1.2.tar.gz
| Download URL | scons-tool-swigpy-0.1.2.tar.gz |
|---|---|
| Size | 8.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
71bcd58a72b513bec6ca29b32ee0dc5ef4f123408ca56fb847cde85d3aa2ebfb
|
|
BLAKE2b-256 checksum How to use checksums |
c99d5c421e08c7b69ca017877dfec50efd5b59d86e555486a8ce0d029cee3bf8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.9
|
Release files / scons_tool_swigpy-0.1.2-py3-none-any.whl
| Download URL | scons_tool_swigpy-0.1.2-py3-none-any.whl |
|---|---|
| Size | 9.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
57d18363d92cbe0e23745500297f1fd1328dc5df03a90fa3096fd92ec8345819
|
|
BLAKE2b-256 checksum How to use checksums |
c0eecf1f6024e3a0f4691f402b7b2c349026d2cf8bc1d81fc44c28eb4d2b7f26
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.9
|
Security for scons-tool-swigpy 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.