跳转到主要内容

用于加载使用maturnin构建的rust项目的导入钩子

项目描述

Maturin导入钩子

一个Python导入钩子,可自动重建maturin项目并导入独立的rust文件。

使用此导入钩子可以减少开发混合Python/rust代码库时的摩擦,因为对rust组件所做的更改会像对Python组件所做的更改一样自动生效。

此导入钩子还提供了例如对maturin项目importlib.reload()的支持等便利。

用法

安装maturin后,使用以下命令将导入钩子安装到Python虚拟环境中:

pip install maturin_import_hook

然后,可选地使用以下命令自动激活钩子:

python -m maturin_import_hook site install

这只需在每个虚拟环境中运行一次。

或者,将以下内容放在每个您想使用钩子的Python脚本顶部:

import maturin_import_hook

# install the import hook with default settings.
# this call must be before any imports that you want the hook to be active for.
maturin_import_hook.install()

# when a rust package that is installed in editable mode is imported,
# that package will be automatically recompiled if necessary.
import pyo3_pure

# when a .rs file is imported a project will be created for it in the
# maturin build cache and the resulting library will be loaded.
#
# assuming subpackage/my_rust_script.rs defines a pyo3 module:
import subpackage.my_rust_script

一旦激活钩子,任何导入可编辑安装的maturin项目的import语句在导入之前将自动重建(如果需要)。

命令行界面

该软件包提供了一个命令行界面,用于获取有关构建缓存的地理位置和大小等信息,并管理安装到 sitecustomize.py 的过程。有关详细信息,请运行

python -m maturin_import_hook --help

调试

如果您遇到问题,启用导入钩子的调试日志是一个了解发生了什么的好方法。这可以通过在引起问题的导入上方放置以下行来实现

# configure logging if you haven't already (make sure DEBUG level is visible)
logging.basicConfig(format="%(name)s [%(levelname)s] %(message)s", level=logging.DEBUG)
maturin_import_hook.reset_logger()

import some_package

许可协议

根据您的选择,许可协议为

项目详情


下载文件

下载适用于您平台上的文件。如果您不确定要选择哪个,请了解更多关于 安装包 的信息。

源分发

maturin-import-hook-0.1.0.tar.gz (28.5 kB 查看哈希值)

上传时间

构建分发

maturin_import_hook-0.1.0-py3-none-any.whl (27.9 kB 查看哈希值)

上传时间 Python 3

由以下支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面