PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, September 27, 2022

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

 September 27, 2022     continuous-deployment, python, python-wheel, setuptools     No comments   

Issue

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?


Solution

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.



Answered By - hoefling
Answer Checked By - Willingham (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing