Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Providing pytz version in setup.py requirements

The problem

I wanted to include requirement for pytz in setup.py script in my library, but wanted also to set the minimal version required. But the version numbers used by pytz module (eg. "2012f") seem to be incompatible with what distutils wants to be provided (eg. "1.1.3").

Is there any way to include requirement for specific version of pytz (eg. >=2012f) without altering pytz or distutils?

Details

To do that I did something like that in setup.py file:

setup(
    # ... basic data here ...
    requires=[
        'pytz (>=2012f)',
    ],
    # ... some other data here ...
)

But when I was doing sudo python setup.py install, the following error appeared:

Traceback (most recent call last):
  File "setup.py", line 25, in <module>
    long_description=long_description,
  File "/usr/lib/python2.7/distutils/core.py", line 112, in setup
    _setup_distribution = dist = klass(attrs)
  File "/usr/lib/python2.7/distutils/dist.py", line 259, in __init__
    getattr(self.metadata, "set_" + key)(val)
  File "/usr/lib/python2.7/distutils/dist.py", line 1220, in set_requires
    distutils.versionpredicate.VersionPredicate(v)
  File "/usr/lib/python2.7/distutils/versionpredicate.py", line 115, in __init__
    self.pred = [splitUp(aPred) for aPred in str.split(",")]
  File "/usr/lib/python2.7/distutils/versionpredicate.py", line 25, in splitUp
    return (comp, distutils.version.StrictVersion(verStr))
  File "/usr/lib/python2.7/distutils/version.py", line 40, in __init__
    self.parse(vstring)
  File "/usr/lib/python2.7/distutils/version.py", line 107, in parse
    raise ValueError, "invalid version number '%s'" % vstring
ValueError: invalid version number '2012f'

Seemingly the issue is caused by distutils trying to match this regular expression:

version_re = re.compile(r'^(\d+) \. (\d+) (\. (\d+))? ([ab](\d+))?$',
                        re.VERBOSE)

and when it does not match, the above error is raised.

I have seen people altering the source code of pytz (to change the version into something more like 2012.6), but it looks like extremely bad idea to me. I hope there is another way that I missed.

Changing pytz (>=2012f) into pytz works, but it then does not limit the requirement to specific version of pytz module.

like image 710
Tadeck Avatar asked Nov 04 '22 14:11

Tadeck


1 Answers

Using install_requires setuptools option:

setup(
    # ... basic data here ...
    install_requires='pytz>=2012f', # distutils ignores it with a warning, pip uses it
    # ... some other data here ...
)
like image 194
jfs Avatar answered Nov 08 '22 12:11

jfs