How to force a python wheel to be platform specific when building it?

后端 未结 4 1856
南旧
南旧 2020-11-29 07:31

I am working on a python2 package in which the setup.py contains some custom install commands. These commands actually build some Rust code and output some

4条回答
  •  长情又很酷
    2020-11-29 08:18

    Neither the root_is_pure trick nor the empty ext_modules trick worked for me, but after MUCH searching myself, I finally found a working solution in 'pip setup.py bdist_wheel' no longer builds forced non-pure wheels

    Basically, you override the 'has_ext_modules' function in the Distribution class, and set distclass to point to the overriding class. At that point, setup.py will believe you have a binary distribution, and will create a wheel with the specific version of python, the ABI, and the current architecture. 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)
    

提交回复
热议问题