3

Trying to create a wheel from an empty project, using this setup.py:

setup.py


from setuptools import setup
setup(name='bla', version='1')

I invoke with python setup.py bdist_wheel --python-tag py35 --plat-name linux_x86_64 and get bla-1-py35-none-linux_x86_64.whl

My machine stats


python -V: Python 3.6.9
uname -p: x86_64
  1. How to enforce abi? (make it bla-1-py35-cp35-linux_x86_64.whl)
  2. How to decide between py35 and cp35 in my python-tag?
CIsForCookies
  • 12,097
  • 11
  • 59
  • 124

2 Answers2

6

After MUCH searching myself, I finally found a working solution in 'pip setup.py bdist_wheel' no longer builds forced non-pure wheels

Basically, if setup.py believes you have a binary distribution, it will create a wheel with the specific version of python, the ABI, and the current architecture. You can do that by overriding the 'has_ext_modules' function in the Distribution class. As suggested by https://stackoverflow.com/users/5316090/py-j:

from setuptools import setup
from setuptools.dist import Distribution

DISTNAME = "packagename"
DESCRIPTION = ""
MAINTAINER = ""
MAINTAINER_EMAIL = ""
URL = ""
LICENSE = ""
DOWNLOAD_URL = ""
VERSION = '1.2'
PYTHON_VERSION = (2, 7)


# Tested with wheel v0.29.0
class BinaryDistribution(Distribution):
    """Distribution which always forces a binary package with platform name"""
    def has_ext_modules(foo):
        return True


setup(name=DISTNAME,
      description=DESCRIPTION,
      maintainer=MAINTAINER,
      maintainer_email=MAINTAINER_EMAIL,
      url=URL,
      license=LICENSE,
      download_url=DOWNLOAD_URL,
      version=VERSION,
      packages=["packagename"],

      # Include pre-compiled extension
      package_data={"packagename": ["_precompiled_extension.pyd"]},
      distclass=BinaryDistribution)

Then you run the setup.py file from whatever Python version/architecture you need, and it will create a platform-specific wheel for each.

Lucian
  • 461
  • 5
  • 6
-1

The ABI tag depends on your Python version. It will be automatically added to your wheel file name. The command python setup.py bdist_wheel is enough for building the wheel file.

To create wheel packages with different ABI tags, a simple way is to run different Python versions in different Docker containers.

enter image description here

The wheel packages I published to pypi.org

enter image description here

The pattern of my package name (package-cp(python version)-cp(python version)m-manylinux1_x86_64.whl) is a little bit from yours. You can't add cp35 to the package built using Python 3.6.

yushulx
  • 11,695
  • 8
  • 37
  • 64