Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add a Python tag to the bdist_wheel command using setuptools?

Let's say I have a simple library which uses setuptools for packaging and distributing. The library in this case also requires a minimum version of Python 3.6, meaning my setup.py would be something like as follows:

from setuptools import setup, find_packages

setup(
    name='something',
    version='0.0.1',

    description='description',
    long_description=long_description,

    # More metadata

    packages=find_packages(exclude=['tests', 'docs']),

    python_requires='>=3.6'
)

Now, when I run python setup.py bdist_wheel, I get a file named something-0.0.1-py3-none-any.whl. As evident here, wheel is ignoring the python_requires option in setuptools when determining the Python tag for my wheel (it should be py36 but is the default py3). Obviously, I realize that I can just pass in --python-tag py36 from the command line, which will do the job, but the continuous deployment service I am using for deploying my library only takes in the name of the distribution I am using (bdist_wheel). As such, I cannot pass any command line parameters.

After doing a bit of research, I found that I could inherit from the bdist_wheel class and override the python_tag member variable, but according to the wheel README:

It should be noted that wheel is not intended to be used as a library, and as such there is no stable, public API.

Because of this, I want to avoid inheriting from the bdist_wheel class which might force me to rewrite my class every time some breaking change occurs.

Is there any alternative way through setuptools which allows me to pass in the Python tag for a wheel?

like image 236
Arnav Borborah Avatar asked Oct 02 '18 13:10

Arnav Borborah


1 Answers

Every command line argument for every distutils command can be persisted in setup config file. Create a file named setup.cfg in the same directory your setup.py resides in and store the custom bdist_wheel configuration in there:

# setup.cfg
[bdist_wheel]
python-tag=py36

Now running python setup.py bdist_wheel will be essentially the same as running python setup.py bdist_wheel --python-tag py36.

Relevant article in the distutils docs: Writing the Setup Configuration File.

like image 114
hoefling Avatar answered Nov 08 '22 03:11

hoefling