make_vars.py (1782B)
1 #!/usr/bin/env python 2 3 from __future__ import ( 4 absolute_import, 5 division, 6 generators, 7 print_function, 8 with_statement, 9 ) 10 11 import sys 12 13 try: 14 import venv 15 except ImportError: 16 venv = None 17 18 try: 19 from packaging.tags import sys_tags 20 21 def get_tag(): 22 tag = sys_tags().__next__() 23 return (tag.interpreter, tag.abi, tag.platform) 24 25 except ImportError: 26 from wheel.pep425tags import get_abbr_impl, get_abi_tag, get_impl_ver, get_platform 27 28 # sporked from wheel.bdist_wheel.get_tag 29 def get_tag(): 30 """Get the specific implementation name in a wheel-compatible format.""" 31 plat_name = get_platform().replace('-', '_').replace('.', '_') 32 impl_name = get_abbr_impl() 33 impl_ver = get_impl_ver() 34 impl = impl_name + impl_ver 35 abi_tag = str(get_abi_tag()).lower() 36 tag = (impl, abi_tag, plat_name) 37 return tag 38 39 40 PY2 = sys.version_info[0] == 2 41 42 43 def main(): 44 tag = '%s-%s-%s' % get_tag() 45 mk_filename = 'make/python_vars_%s.mk' % tag 46 with open(mk_filename, 'wt') as f: 47 # TODO: add proper escaping whenever I feel like staring into the abyss 48 f.write('PYTHON_IMPL:=%s\n' % tag) 49 50 f.write( 51 "PYTHON_VENV:=%s\n" 52 % ( 53 "virtualenv -p $(PYTHON_EXE)" 54 if venv is None 55 else "$(PYTHON_EXE) -m venv" 56 ) 57 ) 58 59 f.write( 60 "PYTHON_VENV_INSTALL:=%s\n" 61 % ("'setuptools<45.0.0' 'pip<20.3' 'pip-tools<6'" if PY2 else "'pip-tools'") 62 ) 63 print("include %s" % mk_filename) 64 65 66 if __name__ == '__main__': 67 main() 68 69 # pylama:linters=pycodestyle,pyflakes:ignore=D212,D203,D100,D101,D102,D107 70 # vim: fileencoding=utf-8 ft=python et sw=4 ts=4 sts=4 tw=79