Search code examples
c++python-3.xpypipybind11

Linux platform tag for python module built with pybind11


I am using pybind11 and build the python module with setuptools and cmake as described in pybind/cmake_example:

setup(
    name='libraryname',
    ...
    ext_modules=[CMakeExtension('libraryname')],
    cmdclass=dict(build_ext=CMakeBuild),
)

Locally, using python setup.py sdist build everything is fine and I can use and/or install the package from the generated files.

I now want to upload the package to PyPI. From a different python package I know how to generate a general linux library (see also here) by manipulating the platform tag of a wheel:

class bdist_wheel(bdist_wheel_):
    def finalize_options(self):
        from sys import platform as _platform
        platform_name = get_platform()
        if _platform == "linux" or _platform == "linux2":
            # Linux
            platform_name = 'manylinux1_x86_64'

        bdist_wheel_.finalize_options(self)
        self.universal = True
        self.plat_name_supplied = True
        self.plat_name = platform_name

setup(
    ...
    cmdclass = {'bdist_wheel': bdist_wheel},
)

The Question:

How to generate the appropriate platform tag when no bdist_wheel is built? Should this be somehow built as wheel instead of as an extension (possibly related to this issue on GH)?

Also, how does pybind11 decide the suffix of the generated libraries (on my linux it is not just .so but .cpython-35m-x86_64-linux-gnu.so)?

Follow-up:

  • The main problem is that I cannot update the current Ubuntu-built package to PyPI: ValueError: Unknown distribution format: 'libraryname-0.8.0.cpython-35m-x86_64-linux-gnu.so'
  • If the platform tag cannot or should not be changed: what is best practice for uploading a pybind11 module to PyPI across platforms?

Solution

  • My bad!

    It turns out the confusion was due to a build error I had when I initially tried running python setup.py sdist bdist_wheel. Manually building with python setup.py build was not the right approach for publishing the package.

    Note: the name of the .so file needed to be set without the -0.8.0 version identifier in order for python do be able to do the import from the wheel.

    To Summarize: Building and publishing binary wheels works exactly the same with pybind11 as with e.g. cpython and it should work just fine to follow the pybind/cmake_example.