mirror of
https://github.com/saltstack/salt.git
synced 2025-04-16 09:40:20 +00:00
Handle pipenv like version restrictions
We need to handle python_version filters in requirement files in order to install cleanly using pip
This commit is contained in:
parent
2a9bf170da
commit
0de189d272
1 changed files with 80 additions and 3 deletions
83
setup.py
83
setup.py
|
@ -15,6 +15,8 @@ import os
|
||||||
import sys
|
import sys
|
||||||
import glob
|
import glob
|
||||||
import time
|
import time
|
||||||
|
import operator
|
||||||
|
import platform
|
||||||
try:
|
try:
|
||||||
from urllib2 import urlopen
|
from urllib2 import urlopen
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -136,6 +138,74 @@ exec(compile(open(SALT_VERSION).read(), SALT_VERSION, 'exec'))
|
||||||
|
|
||||||
|
|
||||||
# ----- Helper Functions -------------------------------------------------------------------------------------------->
|
# ----- Helper Functions -------------------------------------------------------------------------------------------->
|
||||||
|
|
||||||
|
def _parse_op(op):
|
||||||
|
'''
|
||||||
|
>>> _parse_op('>')
|
||||||
|
'gt'
|
||||||
|
>>> _parse_op('>=')
|
||||||
|
'ge'
|
||||||
|
>>> _parse_op('=>')
|
||||||
|
'ge'
|
||||||
|
>>> _parse_op('=> ')
|
||||||
|
'ge'
|
||||||
|
>>> _parse_op('<')
|
||||||
|
'lt'
|
||||||
|
>>> _parse_op('<=')
|
||||||
|
'le'
|
||||||
|
>>> _parse_op('==')
|
||||||
|
'eq'
|
||||||
|
>>> _parse_op(' <= ')
|
||||||
|
'le'
|
||||||
|
'''
|
||||||
|
op = op.strip()
|
||||||
|
if '>' in op:
|
||||||
|
if '=' in op:
|
||||||
|
return 'ge'
|
||||||
|
else:
|
||||||
|
return 'gt'
|
||||||
|
elif '<' in op:
|
||||||
|
if '=' in op:
|
||||||
|
return 'le'
|
||||||
|
else:
|
||||||
|
return 'lt'
|
||||||
|
elif '!' in op:
|
||||||
|
return 'ne'
|
||||||
|
else:
|
||||||
|
return 'eq'
|
||||||
|
|
||||||
|
|
||||||
|
def _parse_ver(ver):
|
||||||
|
'''
|
||||||
|
>>> _parse_ver("'3.4' # pyzmq 17.1.0 stopped building wheels for python3.4")
|
||||||
|
'3.4'
|
||||||
|
>>> _parse_ver('"3.4"')
|
||||||
|
'3.4'
|
||||||
|
>>> _parse_ver('"2.6.17"')
|
||||||
|
'2.6.17'
|
||||||
|
'''
|
||||||
|
if '#' in ver:
|
||||||
|
ver, _ = ver.split('#', 1)
|
||||||
|
ver = ver.strip()
|
||||||
|
return ver.strip('\'').strip('"')
|
||||||
|
|
||||||
|
|
||||||
|
def _check_ver(pyver, op, wanted):
|
||||||
|
'''
|
||||||
|
>>> _check_ver('2.7.15', 'gt', '2.7')
|
||||||
|
True
|
||||||
|
>>> _check_ver('2.7.15', 'gt', '2.7.15')
|
||||||
|
False
|
||||||
|
>>> _check_ver('2.7.15', 'ge', '2.7.15')
|
||||||
|
True
|
||||||
|
>>> _check_ver('2.7.15', 'eq', '2.7.15')
|
||||||
|
True
|
||||||
|
'''
|
||||||
|
pyver = distutils.version.LooseVersion(pyver)
|
||||||
|
wanted = distutils.version.LooseVersion(wanted)
|
||||||
|
return getattr(operator, '__{}__'.format(op))(pyver, wanted)
|
||||||
|
|
||||||
|
|
||||||
def _parse_requirements_file(requirements_file):
|
def _parse_requirements_file(requirements_file):
|
||||||
parsed_requirements = []
|
parsed_requirements = []
|
||||||
with open(requirements_file) as rfh:
|
with open(requirements_file) as rfh:
|
||||||
|
@ -150,7 +220,16 @@ def _parse_requirements_file(requirements_file):
|
||||||
# Python 3 already has futures, installing it will only break
|
# Python 3 already has futures, installing it will only break
|
||||||
# the current python installation whenever futures is imported
|
# the current python installation whenever futures is imported
|
||||||
continue
|
continue
|
||||||
parsed_requirements.append(line)
|
try:
|
||||||
|
pkg, pyverspec = line.rsplit(';', 1)
|
||||||
|
except ValueError:
|
||||||
|
pkg, pyverspec = line, ''
|
||||||
|
pyverspec = pyverspec.strip()
|
||||||
|
if pyverspec:
|
||||||
|
_, op, ver = pyverspec.split(' ', 2)
|
||||||
|
if not _check_ver(platform.python_version(), _parse_op(op), _parse_ver(ver)):
|
||||||
|
continue
|
||||||
|
parsed_requirements.append(pkg)
|
||||||
return parsed_requirements
|
return parsed_requirements
|
||||||
# <---- Helper Functions ---------------------------------------------------------------------------------------------
|
# <---- Helper Functions ---------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -362,7 +441,6 @@ class DownloadWindowsDlls(Command):
|
||||||
if getattr(self.distribution, 'salt_download_windows_dlls', None) is None:
|
if getattr(self.distribution, 'salt_download_windows_dlls', None) is None:
|
||||||
print('This command is not meant to be called on it\'s own')
|
print('This command is not meant to be called on it\'s own')
|
||||||
exit(1)
|
exit(1)
|
||||||
import platform
|
|
||||||
import pip
|
import pip
|
||||||
# pip has moved many things to `_internal` starting with pip 10
|
# pip has moved many things to `_internal` starting with pip 10
|
||||||
if LooseVersion(pip.__version__) < LooseVersion('10.0'):
|
if LooseVersion(pip.__version__) < LooseVersion('10.0'):
|
||||||
|
@ -932,7 +1010,6 @@ class SaltDistribution(distutils.dist.Distribution):
|
||||||
|
|
||||||
if IS_WINDOWS_PLATFORM:
|
if IS_WINDOWS_PLATFORM:
|
||||||
install_requires = _parse_requirements_file(SALT_WINDOWS_REQS)
|
install_requires = _parse_requirements_file(SALT_WINDOWS_REQS)
|
||||||
|
|
||||||
return install_requires
|
return install_requires
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
Loading…
Add table
Reference in a new issue