Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python wheel force ABI to "none"

Tags:

I would think this is an easy question, but I haven't found an answer yet, so I'm posting here.

I have a Python 3 app, that I package into a platform wheel. I have the setup.py and everything works as expected. The only thing I can't figure out is the generated wheel always includes an ABI tag (like"cp34m"), and when that's included I find that I can't actually install the wheel via pip. (My build script installs the latest pip, setuptools, and wheel before running.)

The solution is simple. I just change the file name of the wheel to change "cp34m" to "none". This is obviously easy to add into my build script, but I wonder if it's possible to set an option for bdist_wheel or something so that the .whl file that's generated has none set on its own?

The command I use to create the wheel is (for example on x64):

python setup.py bdist_wheel --plat-name win_amd64

That creates a wheel like:

mpf_mc-0.30.0.dev269-cp34-cp34m-win_amd64.whl

Which I then rename before uploading to PyPI to:

mpf_mc-0.30.0.dev269-cp34-none-win_amd64.whl

Everything seems to work fine by manually renaming it. But I wonder if this the right way to do it, or am I missing something?

like image 610
Brian Madden Avatar asked Mar 15 '16 19:03

Brian Madden


1 Answers

This is difficult to answer without seeing your setup.py file, but I will give my thought:

  • the naming of the wheel postfix is a combination of the python tag, ABI tag, and platform tag, as shown here. But it sounds like you already knew that.
    • This link explaining it all is less official, but clearer, and here is the definition of ABI. In my ignorant understanding, the ABI is the service level agreement (interface) between applications.
    • For the purposes of Python, the ABI is often the same as the python tag, with some additional info like the m you have in your case, which means the Cython aspects of it used malloc.

Reason Your Solution Works

So, I would guess the reason things do not work when you use the original name and do work once you change the name is:

  1. pip will not let you install things using the m part of the ABI tag... probably because it has not been vetted, and not because of any real problem, and/or
  2. you are not actually using any aspects of Cython that depend upon malloc.

Reason The ABI Tag Is Being Added

Now, if we assume that there is no real need for the m tag, as I said, then the reason it is probably being added is that you have a dependency in your setup file that needs it.

I am primarily a data scientist, so I will use a common example from there: numpy is compiled down to C code and has many Python calls to that lower level language to boost speed. Even if I write pure Python 3 code, and do not even use numpy anywhere, if I have a dependency in my setup file that asks for numpy, then I will have a platform-specific build. However, more common is that I am in fact using numpy, but I may not be using any aspects of it that rely upon C. (in numpy, that is rare, as all array initializations happen in C, but I hope you get the idea.) I do not know what forces ABI-specific builds, but I would guess you have some dependency asking for it, but which is never really used.

like image 104
Mike Williamson Avatar answered Sep 17 '22 15:09

Mike Williamson