Search code examples
pythonpython-3.xpipattributeerrorsetup.py

pip install throwing error relating to a function in setup.py


I tried a pip install /Users/me/git/sdk-python/ of my sdk-python package to a test project I have but it give this error:

(venv) Pauls-MBP-2:ibm-cos-sdk-python-config-test paulcarron$ python -m pip install /Users/paulcarron/git/ibm-cos-sdk-python-config/
Processing /Users/paulcarron/git/ibm-cos-sdk-python-config
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/k1/h29nn0z959q0dr6b44kxx_8h0000gn/T/pip-req-build-cmc5fb_p/setup.py", line 24, in <module>
        version=get_version(),
      File "/private/var/folders/k1/h29nn0z959q0dr6b44kxx_8h0000gn/T/pip-req-build-cmc5fb_p/setup.py", line 19, in get_version
        return VERSION_RE.search(init).group(1)
    AttributeError: 'NoneType' object has no attribute 'group'

This is my setup.py:

#!/usr/bin/env python
import os
import re
import sys

from setuptools import setup, find_packages
# sdk python version check
_valid  =  sys.version_info[:2] == (2, 7) or sys.version_info >= (3,4)
if not _valid:
    sys.exit("Sorry, SDK only supports versions 2.7, 3.4, 3.5, 3.6, 3.7 of python.")


ROOT = os.path.dirname(__file__)
VERSION_RE = re.compile(r'''__version__ = ['"]([a-z0-9.]+)['"]''')


def get_version():
    init = open(os.path.join(ROOT, 'python_sdk', '__init__.py')).read()
    return VERSION_RE.search(init).group(1)


setup(
    name='sdk-python',
    version=get_version(),
    description='SDK for Python',
    long_description=open('README.md').read(),
    author='me',
    url='https://github.company.com/org/sdk-python',
    scripts=[],
    packages=find_packages(exclude=['tests*']),
    include_package_data=True,
    license="Apache License 2.0",
    classifiers=[
        'Development Status :: 5 - Production/Stable',
        'Intended Audience :: Developers',
        'Natural Language :: English',
        'License :: OSI Approved :: Apache Software License',
        'Programming Language :: Python',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.4',
        'Programming Language :: Python :: 3.5',
        'Programming Language :: Python :: 3.6',
        'Programming Language :: Python :: 3.7',
    ],
)

This previously worked but something has obviously changed. I'm just not sure what and based on the error, I don't know where to begin, other than it may be something to do with get_version in my setup.py. I'm also not sure where the egg reference is coming from.


Solution

  • I had updated __version__ to contain a _ character but get_version contains [a-z0-9.] which prevent's the _ character from being allowed so I changed it to [a-z0-9._] and I can now install the package.