How to distribute binaries via pip.

huangapple go评论61阅读模式
英文:

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脚本。

问题如下:

  1. 是否已经有可能实现这一点(例如,使用setuptoolspython -m build等)?
  2. 如果不行,从理论上讲,是否可能实现(如果我编写自己的构建器)?
英文:

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:

  1. Is this possible already (e.g. using setuptools, python -m build, etc.)?
  2. 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.

huangapple
  • 本文由 发表于 2023年5月15日 04:55:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/76249634.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定