使用cffi对抗rust实现的libdeltachat核心库的python绑定
deltachat的Python项目详细描述
此包提供到deltachat-corerust-library的绑定 它提供imap/smtp/crypto处理以及聊天/群组/消息 处理Android、桌面和IO用户界面。
安装预构建的软件包(仅限Linux)
如果您有Linux系统,可以安装deltachatbinary“wheel”包 没有任何“从源代码构建”步骤。
Install virtualenv, 然后创建一个新的python环境并在shell中激活它:
virtualenv -p python3 venv source venv/bin/activate
之后,调用python或pip install只会 修改venv目录中的文件并保留系统安装 独自一人。
安装Linux控制盘:
pip install deltachat Verify it worked by typing:: python -c "import deltachat"
从PR/分支安装车轮
对于linux,我们自动为所有github pr分支构建轮子 并将它们推送到python包索引。安装最新的githubmasterbranch:
pip install -i https://m.devpi.net/dc/master deltachat
从源安装绑定
如果不能使用上面的“二进制”方法,则需要编译 至核心Deltachat库:
git clone https://github.com/deltachat/deltachat-core-rust cd deltachat-core-rust cargo build -p deltachat_ffi --release
这将产生一个libdeltachat.so和libdeltachat.a文件 在target/release目录中。这些文件是 为deltachat创建python绑定:
cd python DCC_RS_DEV=`pwd`/.. pip install -e .
现在测试绑定是否找到正确的库:
python -c 'import deltachat ; print(deltachat.__version__)'
这将打印Deltachat绑定版本。
注意
如果你能帮助自动生成Mac或Windows的控制盘, 非常感谢!那就去吧 in contact with us。
使用系统安装的Deltachat铁锈
调用pip而不指定DCC_RS_DEV环境时 变量cffi将尝试从系统位置使用deltachat.h。 类似于/usr/local/include,并将尝试动态链接到 libdeltachat.so在类似的位置(例如/usr/local/lib)。
代码示例
你可以看看examples。
运行测试
签出deltachat-core-rust github repository并键入:
pip install tox ./run-integration-tests.sh
如果您想用real运行功能测试 通过电子邮件测试帐户,生成一个“liveconfig”文件,其中 行包含测试帐户设置,例如:
# 'liveconfig' file specifying imap/smtp accounts addr=some-email@example.org mail_pw=password addr=other-email@example.org mail_pw=otherpassword
“keyword=value”样式允许指定 deltachat account config setting因此您还可以指定smtp或imap服务器、端口、ssl模式等。 通常DC的自动配置允许不指定这些设置。
run-integration-tests.sh脚本将自动使用 {t1616}如果存在,手动运行此测试 liveconfig文件使用:
tox -- --liveconfig liveconfig
使用调试生成运行测试
如果需要检查coredump,则可能需要运行测试 使用调试生成:
DCC_RS_TARGET=debug ./run-integration-tests.sh -e py37 -- -x -v -k failing_test
制造manylinux1车轮
使用libdeltachat.so构建便携式manylinux1轮子 它的所有依赖项都很容易使用提供的docker工具。
使用Docker Pull/Premade图像
我们在deltachat/wheel标记下发布了一个构建环境,因此 你可以从hub.docker.com站点的“deltachat”中提取它 组织:
$ docker pull deltachat/wheel
deltachat/wheel映像可用于构建两个libdeltachat.so 以及python轮子:
$ docker run --rm -it -v $(pwd):/io/ deltachat/wheel /io/python/wheelbuilder/build-wheels.sh
此命令在将$(pwd)作为/io装入 Docker图像。脚本被指定为docker映像文件系统中的路径。 生成的控制盘文件将位于python/wheelhouse中。
可选择创建自己的Docker图像
如果您想建立自己的自定义Docker图像,可以这样做:
$ cd deltachat-core # cd to deltachat-core checkout directory $ docker build -t deltachat/wheel python/wheelbuilder/
这将使用python/wheelbuilder/Dockerfile来构建 叫deltachat/wheel的Docker图片。以后你可以 使用:
$ docker images
故障排除
在最近运行Docker映像的系统上可能会崩溃。你可以 通过将vsyscall=emulate添加到Linux内核引导来解决此问题 参数命令行。例如,在Debian上,您可以将此添加到 GRUB_CMDLINE_LINUX_DEFAULT输入/etc/default/grub。