10

How do I build a universal wheel from setup.py? I would prefer not to pass in the --universal option each time or to create a setup.cfg file just for this option.

I am aware of the workaround in https://stackoverflow.com/a/35112241/6947337, but is there a clean way of doing this without creating a setup.cfg file temporarily?

Community
  • 1
  • 1
rlee827
  • 1,853
  • 2
  • 13
  • 32
  • 4
    Any good reason you needed to avoid using a `setup.cfg`, or just perfectionism? – wim Apr 12 '17 at 19:09
  • There is no reason that I can't use a `setup.cfg` in this case, so this is just perfectionism and curiosity :) – rlee827 Apr 12 '17 at 19:19

2 Answers2

11

setup.py's setup() supports an options argument to pass options to any command. It is a dictionary of command names and command options. You can instruct it to build a universal wheel by providing any truthy value accepted by strtobool e.g.

setup(options={'bdist_wheel':{'universal':'1'}})

or

setup(options={'bdist_wheel':{'universal':True}})

See also https://github.com/python/cpython/blob/master/Lib/distutils/dist.py#L247

If you only want to make a Python 3 compatible wheel, you don't have to pass any argument. The wheel will automatically be tagged as py3 if it it is built in a Python 3 interpreter.

Brendan Abel
  • 35,343
  • 14
  • 88
  • 118
joeforker
  • 40,459
  • 37
  • 151
  • 246
0

You can use the script_args option to setup() to override the command line. So you could do:

import sys
from setuptools import setup
setup(script_args=sys.argv[1:]+['--universal'])

This is not superbly elegant, but perhaps less ugly than creating a temporary setup.cfg

jochietoch
  • 176
  • 1
  • 3