make_vars.py (2185B)
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 os 12 import sys 13 14 try: 15 import venv 16 except ImportError: 17 venv = None 18 19 try: 20 from packaging.tags import sys_tags 21 22 def get_tag(): 23 tag = sys_tags().__next__() 24 return (tag.interpreter, tag.abi, tag.platform) 25 26 except ImportError: 27 from wheel.pep425tags import get_abbr_impl, get_abi_tag, get_impl_ver, get_platform 28 29 # sporked from wheel.bdist_wheel.get_tag 30 def get_tag(): 31 """Get the specific implementation name in a wheel-compatible format.""" 32 plat_name = get_platform().replace('-', '_').replace('.', '_') 33 impl_name = get_abbr_impl() 34 impl_ver = get_impl_ver() 35 impl = impl_name + impl_ver 36 abi_tag = str(get_abi_tag()).lower() 37 tag = (impl, abi_tag, plat_name) 38 return tag 39 40 41 PY2 = sys.version_info[0] == 2 42 43 44 def main(mk_dir): 45 tag = '%s-%s-%s' % get_tag() 46 mk_filename = '%s/python_vars_%s.mk' % (mk_dir, tag) 47 os.makedirs(mk_dir, exist_ok=True) 48 with open(mk_filename, 'wt') as f: 49 # TODO: add proper escaping whenever I feel like staring into the abyss 50 f.write('PYTHON_IMPL:=%s\n' % tag) 51 52 f.write( 53 "PYTHON_VENV:=%s\n" 54 % ( 55 "virtualenv -p $(PYTHON_EXE)" 56 if venv is None 57 else "$(PYTHON_EXE) -m venv" 58 ) 59 ) 60 61 f.write( 62 "PYTHON_VENV_INSTALL:=%s\n" 63 % ("'setuptools<45.0.0' 'pip<20.3' 'pip-tools<6'" if PY2 else "'pip-tools'") 64 ) 65 print("include %s" % mk_filename) 66 67 68 def usage(exitcode=100): 69 sys.stderr.write('usage: make_vars.py directory\n') 70 sys.exit(exitcode) 71 72 73 if __name__ == '__main__': 74 if len(sys.argv) < 2: 75 sys.stderr.write('make_vars.py: fatal: too few arguments\n') 76 usage() 77 if len(sys.argv) > 2: 78 sys.stderr.write('make_vars.py: fatal: too many arguments\n') 79 usage() 80 main(sys.argv[1]) 81 82 # pylama:linters=pycodestyle,pyflakes:ignore=D212,D203,D100,D101,D102,D107 83 # vim: fileencoding=utf-8 ft=python et sw=4 ts=4 sts=4 tw=79