英文:
How to distribute binaries via pip
问题
I know that sounds a bit of a mad thing to do, but pip is probably the most likely-to-be-installed package manager in many cases, and also CMake does it (pip install cmake
is by far the easiest way to get an up-to-date build of CMake on Linux and Mac).
但不管怎样,我该如何实际操作呢?据我所知,根据wheel规范,wheels可以包含不必是Python脚本的“scripts”(它可以是本地可执行文件)。此外,wheels可以是特定平台的,因此我可以将Linux x86二进制文件放入一个wheel,将Mac ARM二进制文件放入另一个,将它们全部上传到PyPI,pip会自行处理。
但我该如何实际操作呢?我已经创建了一个包含[project.scripts]
条目的pyproject.toml
,但似乎这些条目必须是Python脚本。
问题如下:
- 是否已经有可能实现这一点(例如,使用
setuptools
,python -m build
等)? - 如果不行,从理论上讲,是否可能实现(如果我编写自己的构建器)?
英文:
I know that sounds a bit of a mad thing to do, but pip is probably the most likely-to-be-installed package manager in many cases, and also CMake does it (pip install cmake
is by far the easiest way to get an up-to-date build of CMake on Linux and Mac).
But anyway how would I actually do it? As far as I can tell from the wheel spec, wheels can include "scripts" that don't have to be Python scripts (it could be a native executable). Also wheels can be platform-specific, so I can put my Linux x86 binary in one wheel, Mac ARM one in another, upload them all to PyPI and pip will figure it out.
But how do I actually do that? I got as far as creating a pyproject.toml
with a [project.scripts]
entry, but it appears that those entries do have to be Python scripts.
The questions are:
- Is this possible already (e.g. using
setuptools
,python -m build
, etc.)? - If not, is this possible in theory (if I write my own builder)?
答案1
得分: 1
Ok, it seems like this is definitely possible. There is a Rust project called Maturin that builds wheels from Rust code. I think it's really designed for Python libraries that are thin wrappers around Rust libraries, but it also supports installing binaries as scripts. Here is an example.
I'm not sure what you'd do if your project wasn't a Rust project, but fortunately mine is. I guess take a look at the Maturin code to see what it does.
英文:
Ok it seems like this is definitely possible. There is a Rust project called Maturin that builds wheels from Rust code. I think it's really designed for Python libraries that are thin wrappers around Rust libraries, but it also supports installing binaries as scripts. Here is an example.
I'm not sure what you'd do if your project wasn't a Rust project, but fortunately mine is. I guess take a look at the Maturin code to see what it does.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论