#!/usr/bin/env python # -*- coding: utf-8 -*- from __future__ import division, absolute_import, print_function, unicode_literals """ Build all pythons for all targets """ import os import subprocess workdir = os.getcwd() scriptname = 'pyside_builder.py' cpython_dir = 'cpython' if not os.path.exists(scriptname): raise RuntimeError( "this simplistic pyside builder must be started from the" " folder where the script is living.") def get_cpython(): """get a cpython repository""" if not os.path.exists('cpython/.hg'): print('cloning cpython') rc = subprocess.call(['hg', 'clone', '-U', 'http://hg.python.org/cpython/']) if rc: raise RuntimeError('could not get cpython') def get_pyside_setup(): """get a pyside_setup repository""" if not os.path.exists('pyside-setup/.git'): print('cloning pyside-setup') rc = subprocess.call(['git', 'clone', 'git@bitbucket.org:pydica/pyside-setup.git']) if rc: raise RuntimeError('could not get pyside-setup') def get_pip(): if not os.path.exists('get-pip.py'): print('pip is missing: obtaining get-git.py') print('cwd is', os.getcwd()) subprocess.check_call(['wget', 'https://raw.githubusercontent.com/pypa/pip/master/contrib/get-pip.py']) pip = os.path.realpath('get-pip.py') return pip """ Actually, I had a bad experience with get_pip. It gave weird problems with python 2.6. Therefore, I use ez_setup to get easy_install, and then upgrade to the freshest setuptools. """ def get_ez_setup(): if not os.path.exists('ez_setup.py'): print('ez_setup: obtaining ez_setup.py') print('cwd is', os.getcwd()) subprocess.check_call(['wget', 'https://bitbucket.org/pypa/setuptools/raw/bootstrap-py24/ez_setup.py']) ez = os.path.realpath('ez_setup.py') return ez def build_all_pythons(): for target in TARGETS: env = os.environ.copy() env.update( { 'MACOSX_DEPLOYMENT_TARGET': target, }) processes = [] for pydir, python in zip(PYTHONNAMES, PYTHONS): name = os.path.join(target, pydir) absname = os.path.realpath(name) print(target, pydir, python) if python.startswith('3'): binname = 'python3' else: binname = 'python' binpath = os.path.realpath(os.path.join(name, 'bin')) def bd(name): return os.path.join(binpath, name) exepath = bd(binname) if not os.path.exists(exepath): if os.path.exists(name + '.skip'): print('*** skipped', name) continue print('building', exepath) try: subprocess.check_call(['hg', 'clean', '--all'], cwd = cpython_dir) subprocess.check_call(['hg', 'up', python, '--clean'], cwd = cpython_dir) subprocess.check_call(['./configure', '--prefix=' + absname], cwd = cpython_dir, env=env) subprocess.check_call(['make'], cwd = cpython_dir, env=env) subprocess.check_call(['make', 'install'], cwd = cpython_dir, env=env) except subprocess.CalledProcessError as e: print(20 * "*") print(e) print('creating', name + '.skip') with open(name + '.skip', 'w') as outfile: print(e, file=outfile) continue if not os.path.exists(bd('wheel')): subprocess.check_call([exepath, get_ez_setup()]) subprocess.check_call([bd('easy_install'), 'pip']) subprocess.check_call([bd('pip'), 'install', 'setuptools', '-U']) subprocess.check_call([bd('pip'), 'install', 'wheel', '-U']) # clone pyside-setup clone_to = absname + '_setup' gitpath = os.path.join(clone_to, '.git') if not os.path.exists(gitpath): subprocess.check_call(['git', 'clone', 'pyside-setup', clone_to]) expect = os.path.join(clone_to, 'dist') if not os.path.exists(expect): print(expect) log = open(clone_to + '.log', 'w') p = subprocess.Popen([exepath, 'setup.py', 'bdist_wheel', 'bdist_egg', '--version=1.2.2'], cwd=clone_to, env=env, stderr=subprocess.STDOUT, stdout=log, ) processes.append(p) # now wait for the processes to end for proc in processes: proc.wait() def get_all_targets(): """ greate all targets from 10.6 to our current one """ import platform my_ver = map(int, platform.mac_ver()[0].split('.')[:2]) versions = list([10, x] for x in range(6, 100) if [10, x] <= my_ver) return map(lambda arg: "{}.{}".format(arg[0], arg[1]), versions) TARGETS = get_all_targets() # "10.6 10.7 10.8 10.9".split() PYTHONS = "2.6 2.7 3.3 3.4".split() TARGETS.reverse() # newest first PYTHONS.reverse() PYTHONNAMES = tuple("py" + names.replace('.', '') for names in PYTHONS) if __name__ == '__main__': get_cpython() get_pyside_setup() build_all_pythons()