用于加载使用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
许可协议
根据您的选择,许可协议为
- Apache License,版本 2.0,(LICENSE-APACHE 或 https://apache.ac.cn/licenses/LICENSE-2.0)
- MIT 许可证 (LICENSE-MIT 或 https://open-source.org.cn/licenses/MIT)
。
项目详情
下载文件
下载适用于您平台上的文件。如果您不确定要选择哪个,请了解更多关于 安装包 的信息。
源分发
maturin-import-hook-0.1.0.tar.gz (28.5 kB 查看哈希值)
构建分发
关闭
maturin-import-hook-0.1.0.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | b31457d421db2a6aa51a2431a0f343ace17f4f59944a9670f2e6be66b3ea0499 |
|
MD5 | 9584e2c085db65039986529696a93227 |
|
BLAKE2b-256 | efc76e111115358451e4dd65a83d7f47151cc177c219e58d544be53328073f4c |
关闭
maturin_import_hook-0.1.0-py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 05cfeb40a161ec910081914aaf8909498b39b0e06d3edd89fd618b7cee38cceb |
|
MD5 | 8d45df284181df661c11db2a1493092e |
|
BLAKE2b-256 | ddcbdebac4e82b2d0794488d638860a86ff7658cf5c4844e7519d09be4ed1e53 |