问题
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?
回答1:
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.
回答2:
You could hack in something like
if 'bdist_wheel' in sys.argv:
if not any(arg.startswith('--python-tag') for arg in sys.argv):
sys.argv.extend(['--python-tag', 'py36'])
but it's arguably just as brittle...
来源:https://stackoverflow.com/questions/52609945/how-do-i-add-a-python-tag-to-the-bdist-wheel-command-using-setuptools