PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0
Showing posts with label setuptools. Show all posts
Showing posts with label setuptools. Show all posts

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)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Thursday, August 25, 2022

[FIXED] What do I need to do to my python code to get it to be a module?

 August 25, 2022     distutils, module, python, setuptools     No comments   

Issue

Can someone tell me what I'm doing wrong to package this as a module: https://github.com/xamox/python-zxing.

My setup.py is as follows:

#!/usr/bin/env python

from distutils.core import setup

setup(
    name='zxing',
    version='0.1',
    description="wrapper for zebra crossing (zxing) barcode library",
    url='http://simplecv.org',
    author='Ingenuitas',
    author_email='public.relations@ingenuitas.com',
    packages=['zxing'],
)

I am trying to do "import zxing". I do setup.py install, puts it in /usr/local/lib/python2.7/dist-packages/, but import zxing doesn't work.

I get the following error:

In [1]: import zxing.zxing
---------------------------------------------------------------------------
ResolutionError                           Traceback (most recent call last)
/home/xamox/<ipython-input-1-9ff7d0755c55> in <module>()
----> 1 import zxing.zxing

/usr/local/bin/zxing.py in <module>()
      3 __requires__ = 'zxing==0.1'
      4 import pkg_resources
----> 5 pkg_resources.run_script('zxing==0.1', 'zxing.py')

/usr/lib/python2.7/dist-packages/pkg_resources.pyc in run_script(self, requires, script_name)
    465         ns.clear()
    466         ns['__name__'] = name
--> 467         self.require(requires)[0].run_script(script_name, ns)
    468 
    469 

/usr/lib/python2.7/dist-packages/pkg_resources.pyc in run_script(self, script_name, namespace)
   1192         script = 'scripts/'+script_name
   1193         if not self.has_metadata(script):
-> 1194             raise ResolutionError("No script named %r" % script_name)
   1195         script_text = self.get_metadata(script).replace('\r\n','\n')
   1196         script_text = script_text.replace('\r','\n')

ResolutionError: No script named 'zxing.py'

Solution

Have a look in the stack trace whose URL you showed in a comment:

/usr/local/bin/zxing.py in <module>()
      3 __requires__ = 'zxing==0.1'
      4 import pkg_resources
----> 5 pkg_resources.run_script('zxing==0.1', 'zxing.py')

That indicates that it is trying to load some guff from /usr/local/bin/zxing.py which contains code that's not in your current version e.g. "import pkg_resources". Looks like debris from a previous experiment. Get rid of it.

Now that you have a clean deck:

It seems rather pointless having an empty __init__.py and a one-source-file package. I suggest that you delete the __init__.py and remove all traces of other experiments (especially "build" directories). If there is a folder /usr/local/lib/python2.7/dist-packages/zxing, remove it.



Answered By - John Machin
Answer Checked By - David Marino (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Older Posts Home
View mobile version

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
All Comments
Atom
All Comments

Copyright © PHPFixing