From c9e0e1ea17e20cc07e5e61fff5a93d9cf28897a3 Mon Sep 17 00:00:00 2001 From: Nate Coraor Date: Tue, 27 Oct 2009 11:36:57 -0400 Subject: [PATCH] A get_platform() monkeypatch for fat versions of python on Mac. Also do more explicit version checking ( >= 2.4, <= 2.5 ) and provide helpful messages if the version is not supported. --- lib/galaxy/__init__.py | 27 ++++++++++++++++- lib/galaxy/eggs/__init__.py | 9 +++--- scripts/check_python.py | 22 ++++++++++++++ scripts/get_python.sh | 60 ------------------------------------- scripts/paster.py | 7 ++++- setup.sh | 3 ++ 6 files changed, 62 insertions(+), 66 deletions(-) create mode 100644 scripts/check_python.py delete mode 100755 scripts/get_python.sh diff --git a/lib/galaxy/__init__.py b/lib/galaxy/__init__.py index 9e4f983e606..bfb8f90a426 100644 --- a/lib/galaxy/__init__.py +++ b/lib/galaxy/__init__.py @@ -2,4 +2,29 @@ Galaxy root package -- this is a namespace package. """ -__import__( "pkg_resources" ).declare_namespace( __name__ ) \ No newline at end of file +# Starting somewhere in 2.5.x, Python on Mac became broken - despite being fat, +# the machine portion of the platform is not set to 'fat'. +# +# For more, see: +# +# http://bugs.python.org/setuptools/issue19 +# +import os, sys +from distutils.sysconfig import get_config_vars + +if ( os.uname()[-1] in ( 'i386', 'ppc' ) and sys.platform == 'darwin' and sys.prefix.startswith( '/System' ) ) or \ + ( sys.platform == 'darwin' and get_config_vars().get('UNIVERSALSDK', '').strip() ): + # Has to be before anything imports pkg_resources + def _get_platform_monkeypatch(): + plat = distutils.util._get_platform() + if plat.startswith( 'macosx-' ): + plat = 'macosx-10.3-fat' + return plat + import distutils.util + try: + assert distutils.util._get_platform + except: + distutils.util._get_platform = distutils.util.get_platform + distutils.util.get_platform = _get_platform_monkeypatch + +__import__( "pkg_resources" ).declare_namespace( __name__ ) diff --git a/lib/galaxy/eggs/__init__.py b/lib/galaxy/eggs/__init__.py index 2b4363f1664..ec663417658 100644 --- a/lib/galaxy/eggs/__init__.py +++ b/lib/galaxy/eggs/__init__.py @@ -533,9 +533,9 @@ def require( pkg ): egg = c.get_for_require( name ) try: if egg is None: - pkg_resources.working_set.require( pkg ) + return pkg_resources.working_set.require( pkg ) else: - pkg_resources.working_set.require( "%s==%s" % ( name, egg.get_vertag() ) ) + return pkg_resources.working_set.require( "%s==%s" % ( name, egg.get_vertag() ) ) except pkg_resources.VersionConflict, e: # there's a conflicting egg on the pythonpath, remove it dist = e.args[0] @@ -551,9 +551,10 @@ def require( pkg ): del working_set.by_key[dist.key] working_set.entry_keys[entry] = [] sys.path.remove(entry) - require( pkg ) + r = require( pkg ) if location is not None and not location.endswith( '.egg' ): working_set.entries.append( location ) # re-add to the set if it's a dir. + return r except pkg_resources.DistributionNotFound, e: # the initial require itself is the first dep, but it can have # multiple deps, which will be fetched by the require below. @@ -566,7 +567,7 @@ def require( pkg ): if not egg.have: if not egg.fetch(): raise EggNotFetchable( egg.name ) - require( pkg ) + return require( pkg ) # convenience stuff def get_ucs(): diff --git a/scripts/check_python.py b/scripts/check_python.py new file mode 100644 index 00000000000..3b8b193024f --- /dev/null +++ b/scripts/check_python.py @@ -0,0 +1,22 @@ +import os, sys + +def check_python(): + try: + assert sys.version_info[:2] >= ( 2, 4 ) and sys.version_info[:2] <= ( 2, 5 ) + except AssertionError: + print >>sys.stderr, "ERROR: Your Python version is:", sys.version.split( ' ', 1 )[0] + print >>sys.stderr, "Galaxy is currently only supported on Python 2.4 and Python 2.5." + if sys.version_info[:2] < ( 2, 4 ): + print >>sys.stderr, "To run Galaxy, please download and install Python 2.5 from http://python.org" + else: + print >>sys.stderr, "To track the progress of Python 2.6 support, please see:" + print >>sys.stderr, " http://bitbucket.org/galaxy/galaxy-central/issue/76/support-python-26" + print >>sys.stderr, "For hints on how to direct Galaxy to use a different python installation, see:" + print >>sys.stderr, " http://bitbucket.org/galaxy/galaxy-central/wiki/GetGalaxy" + raise + +if __name__ == '__main__': + try: + check_python() + except: + sys.exit( 1 ) diff --git a/scripts/get_python.sh b/scripts/get_python.sh deleted file mode 100755 index 95cc16be725..00000000000 --- a/scripts/get_python.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/bin/sh -# -# Try to find a usable python -# - -if [ "$GALAXY_PYTHON" != "" ]; then - PYTHONS="$GALAXY_PYTHON" -else - PYTHONS="python python2.4 python2.5" -fi - -found="" -for python in $PYTHONS; do - version=`$python -c 'import sys; print sys.version[:3]' 2>/dev/null` - if [ $? -eq 0 ]; then - case $version in - 2.4|2.5) - found="$python" - break - ;; - esac - fi -done - -if [ "$found" != "" ]; then - GALAXY_PYTHON="$found" -else - - # user manually defined $GALAXY_PYTHON - if [ "$GALAXY_PYTHON" != "" ]; then - - /bin/cat <= ( 2, 4 ) +# ensure supported version +from check_python import check_python +try: + check_python() +except: + sys.exit( 1 ) new_path = [ os.path.join( os.getcwd(), "lib" ) ] new_path.extend( sys.path[1:] ) # remove scripts/ from the path diff --git a/setup.sh b/setup.sh index b0f504ccac9..fc8e3edb9fa 100644 --- a/setup.sh +++ b/setup.sh @@ -1,5 +1,8 @@ #!/bin/sh +python ./scripts/check_python.py +[ $? -ne 0 ] && exit 1 + SAMPLES=" datatypes_conf.xml.sample reports_wsgi.ini.sample