Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create platform-specific Python wheel with build tool?

build (https://github.com/pypa/build) is a great tool to create wheels. However, I could not find a way to create platform-specific wheels that I can do with python setup.py --plat-name=linux_x86_64.

I have tried these approaches:

  • Add setup.cfg with [bdist_wheel] \ plat-name=linux_x86_64 content. It works well but I want to make this dynamic (on Windows, I want to use win_amd64).
  • I tried python -m build -w -n "--config-setting=--plat-name(=linux_x86_64)", no success.

Renaming the created .whl file feels a hacky solution.

What is the state-of-the-art way to resolve this?

like image 626
Tibor Takács Avatar asked Apr 01 '26 18:04

Tibor Takács


2 Answers

Creating a custom command class is not necessary. The syntax to provide plat_name explicitly is like this:

from setuptools import setup

def get_platname():
    # do whatever you need here
    return "potato"

setup(
    name="myproj",
    version="0.1",
    options={
        "bdist_wheel": {
            "plat_name": get_platname(),
        },
    },    
)
like image 115
wim Avatar answered Apr 03 '26 07:04

wim


Using a pure pyproject.toml setup the platform can be set via:

python -m build -w -C="--global-option=--plat-name" -C="--global-option=anything_you_like_here"

Kudos to @sinoroc in the comment above for sharing this link: https://github.com/pypa/build/issues/202

like image 38
Woltan Avatar answered Apr 03 '26 07:04

Woltan