1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
|
#! /usr/bin/env python
"""Overall test runner to test matrix of system options..."""
import os,sys,subprocess,logging, glob, shutil
log = logging.getLogger( 'overallrunner' )
HERE = os.path.abspath(os.path.dirname( __file__ ))
TEST_ENVS = os.path.join( HERE, '.test-envs' )
WHEEL_DIR = os.path.join( HERE, '.wheels' )
PYTHONS = [
# order is so that most-important platforms are checked first
'python3.10',
'python3.9',
'python3.8',
'python3.6',
'python2.7',
# python2.6 support is less important than the above at this point,
# and doing a --user install clobbers 2.7's version of the packages
# should use a virtualenv for all of them, really...
#'python2.6',
]
PYGAME_SOURCE = os.path.join( HERE, '.pygame' )
FLAGS = [
'USE_ACCELERATE',
'ERROR_ON_COPY',
'ARRAY_SIZE_CHECKING',
'ERROR_CHECKING',
'STORE_POINTERS',
'CONTEXT_CHECKING',
'ALLOW_NUMPY_SCALARS',
'UNSIGNED_BYTE_IMAGES_AS_STRING',
]
def short_name( python ):
if python.startswith( 'python' ):
return 'cp' + python[6:].replace('.','')
raise ValueError( "Don't know wheel format for %s"%(python,))
def have_wheel( package,python ):
"""Do we have this wheel built for the given package and python?"""
current = os.listdir( WHEEL_DIR )
short = short_name( python )
for item in current:
split = item.split('-')
if package in item and short in item:
return True
return False
def get_pygame():
if os.path.exists( PYGAME_SOURCE ):
subprocess.check_call( 'cd .pygame && hg pull && hg update', shell=True )
else:
subprocess.check_call( 'hg clone https://bitbucket.org/pygame/pygame .pygame', shell=True )
return PYGAME_SOURCE
def pip_command( python, command, **named ):
if python == 'python2.6':
prefix = ['pip2.6']
else:
prefix = [
python, '-m', 'pip'
]
command = prefix + command
return subprocess.check_call( command, **named )
def build_pygame(pythons=PYTHONS):
get_pygame()
cwd = os.path.join( HERE, '.pygame' )
for python in [p for p in pythons if have_python(p)]:
for path in [
os.path.join(cwd, 'Setup' ),
os.path.join(cwd, 'build' ),
]:
if os.path.isdir( path ):
shutil.rmtree( path )
elif os.path.exists( path ):
os.remove( path )
subprocess.check_call( [python,'config.py'], cwd=cwd )
pip_command( python, [
'install','--user','--upgrade','pip',
], cwd=cwd )
pip_command( python, [
'install', '--upgrade','--user','wheel',
], cwd=cwd )
if not have_wheel( 'pygame', python ):
pip_command( python, [
'wheel','--wheel-dir',WHEEL_DIR, '.pygame',
], cwd=HERE )
if not have_wheel( 'numpy', python ):
pip_command( python, [
'wheel','--wheel-dir',WHEEL_DIR, '.numpy',
], cwd=HERE )
def have_python( python ):
try:
subprocess.check_call( ['which',python])
except subprocess.CalledProcessError as err:
log.error( "Unable to find %s", python )
return None
else:
return python
def has_module( python, module ):
try:
subprocess.check_call( [python, '-c', 'import %s'%(module)])
return True
except subprocess.CalledProcessError as err:
return False
def has_pygame( python ):
return has_module( python, 'pygame' )
def has_numpy( python ):
return has_module( python, 'numpy' )
def ensure_virtualenv( python, numpy=True ):
"""Check/create virtualenv using our naming scheme"""
expected_name = os.path.join( TEST_ENVS, python+['-nonum','-num'][bool(numpy)])
log.info( 'Ensuring %s', expected_name )
bin_path = os.path.join( expected_name, 'bin' )
if not os.path.exists( expected_name ):
if not os.path.exists( TEST_ENVS ):
os.makedirs( TEST_ENVS )
subprocess.check_call([
'virtualenv', '-p', python, expected_name
])
target_python = os.path.join( bin_path, 'python' )
to_install = []
if not has_pygame( target_python ):
to_install.append( 'pygame' )
if numpy and not has_numpy( target_python ):
to_install.append( 'numpy' )
if to_install:
subprocess.check_call([
os.path.join( bin_path, 'pip' ),
'install',
'-f', WHEEL_DIR,
'--pre',
'--no-index',
]+to_install)
subprocess.check_call([
os.path.join( bin_path, 'python' ),
'setup.py',
'build_ext', '--force',
'install',
], cwd = os.path.join( HERE, '..','OpenGL_accelerate' ))
subprocess.check_call([
os.path.join( bin_path, 'python' ),
'setup.py',
'develop',
], cwd = os.path.join( HERE, '..' ))
def env_setup():
our_pythons = [p for p in PYTHONS if have_python(p)]
for p in our_pythons:
for numpy in [True,False]:
ensure_virtualenv(p,numpy)
def main():
env_setup()
our_pythons = glob.glob( os.path.join( TEST_ENVS, '*','bin','python' ))
our_pythons.sort()
our_pythons.reverse()
for flag in FLAGS:
for python in our_pythons:
for b in [True,False]:
env = os.environ.copy()
env['PYOPENGL_'+ flag] = str(b)
command = [python,'test_core.py', '-v']
if 'python2.6' not in python:
command.append( '-f')
log.info( 'Starting PYOPENGL_%s=%s %s',flag, b, ' '.join(command))
subprocess.check_call( command, env=env)
if __name__ == "__main__":
logging.basicConfig( level = logging.INFO )
main()
|