Commit e0891e8ecdcd66b3537095d5b26a846cf90af47d

Authored by Jürgen Knödlseder
1 parent c9b8b0ed

Introduce Python compatibility brackets.

Add two variables PYTHON_OPEN and PYTHON_CLOSE that are either " " and "" (for Python 2) or "(" and ")" (for Python 3). These variables are used in setup.py to toggle between the Python 2 print statement and the Python 3 print function.
configure.ac
@@ -533,6 +533,17 @@ AM_PATH_PYTHON([2.2], @@ -533,6 +533,17 @@ AM_PATH_PYTHON([2.2],
533 [AC_MSG_WARN([Python >= 2.2 not found. Python >= 2.2 is required to build python binding. Python can be obtained from http://www.python.org])]) 533 [AC_MSG_WARN([Python >= 2.2 not found. Python >= 2.2 is required to build python binding. Python can be obtained from http://www.python.org])])
534 if test "x$has_python" = "xyes"; then 534 if test "x$has_python" = "xyes"; then
535 535
  536 + # Set opening and closing symbols to make setup.py compatible for versions 2 and 3
  537 + if test ${PYTHON_VERSION} '<' 3; then
  538 + PYTHON_OPEN=" "
  539 + PYTHON_CLOSE=""
  540 + else
  541 + PYTHON_OPEN="("
  542 + PYTHON_CLOSE=")"
  543 + fi
  544 + AC_SUBST(PYTHON_OPEN)
  545 + AC_SUBST(PYTHON_CLOSE)
  546 +
536 # Do we have distutils? 547 # Do we have distutils?
537 AC_MSG_CHECKING([for the distutils Python package]) 548 AC_MSG_CHECKING([for the distutils Python package])
538 ac_distutils_result=`$PYTHON -c "import distutils" 2>&1` 549 ac_distutils_result=`$PYTHON -c "import distutils" 2>&1`
@@ -558,7 +569,7 @@ if test &quot;x$has_python&quot; = &quot;xyes&quot;; then @@ -558,7 +569,7 @@ if test &quot;x$has_python&quot; = &quot;xyes&quot;; then
558 fi 569 fi
559 PYTHON_CPPFLAGS=$python_path 570 PYTHON_CPPFLAGS=$python_path
560 CPPFLAGS="${CPPFLAGS} ${python_path}" 571 CPPFLAGS="${CPPFLAGS} ${python_path}"
561 - AC_SUBST([PYTHON_CPPFLAGS]) 572 + AC_SUBST([PYTHON_CPPFLAGS])
562 573
563 # ... otherwise check for includes relative to exectuable (obsolete?) 574 # ... otherwise check for includes relative to exectuable (obsolete?)
564 else 575 else
pyext/setup.py.in
@@ -29,7 +29,7 @@ import sys @@ -29,7 +29,7 @@ import sys
29 is_unit_test = False 29 is_unit_test = False
30 if (len(sys.argv) >= 3): 30 if (len(sys.argv) >= 3):
31 if (sys.argv[2] == '--inplace'): 31 if (sys.argv[2] == '--inplace'):
32 - print "This build is for unit testing." 32 + print@PYTHON_OPEN@"This build is for unit testing."@PYTHON_CLOSE@
33 is_unit_test = True 33 is_unit_test = True
34 34
35 # Darwin MacPorts kluge: Remove -L/opt/local/lib path from LDSHARED as this 35 # Darwin MacPorts kluge: Remove -L/opt/local/lib path from LDSHARED as this
@@ -50,7 +50,7 @@ if sys.platform.lower().startswith(&quot;darwin&quot;): @@ -50,7 +50,7 @@ if sys.platform.lower().startswith(&quot;darwin&quot;):
50 else: 50 else:
51 ldshared_rm += option + ' ' 51 ldshared_rm += option + ' '
52 if (len(ldshared_rm) > 0): 52 if (len(ldshared_rm) > 0):
53 - print 'Removed following option(s) from LDSHARED: '+ldshared_rm 53 + print@PYTHON_OPEN@"Removed following option(s) from LDSHARED: "+ldshared_rm@PYTHON_CLOSE@
54 54
55 # Set LDSHARED 55 # Set LDSHARED
56 cvars['LDSHARED'] = ldshared_new 56 cvars['LDSHARED'] = ldshared_new
@@ -68,7 +68,7 @@ if sys.platform.lower().startswith(&quot;darwin&quot;) and is_unit_test: @@ -68,7 +68,7 @@ if sys.platform.lower().startswith(&quot;darwin&quot;) and is_unit_test:
68 # an already existing link. 68 # an already existing link.
69 try: 69 try:
70 os.remove('../src/.libs/libctools_python.a') 70 os.remove('../src/.libs/libctools_python.a')
71 - print 'Removed ../src/.libs/libctools_python.a' 71 + print@PYTHON_OPEN@"Removed ../src/.libs/libctools_python.a"@PYTHON_CLOSE@
72 except: 72 except:
73 pass 73 pass
74 74
@@ -76,10 +76,10 @@ if sys.platform.lower().startswith(&quot;darwin&quot;) and is_unit_test: @@ -76,10 +76,10 @@ if sys.platform.lower().startswith(&quot;darwin&quot;) and is_unit_test:
76 # symbolic link 76 # symbolic link
77 try: 77 try:
78 os.symlink('libctools.a', '../src/.libs/libctools_python.a') 78 os.symlink('libctools.a', '../src/.libs/libctools_python.a')
79 - print 'Created ../src/.libs/libctools_python.a' 79 + print@PYTHON_OPEN@"Created ../src/.libs/libctools_python.a"@PYTHON_CLOSE@
80 libcta='ctools_python' 80 libcta='ctools_python'
81 except: 81 except:
82 - print 'WARNING: Failed to create symbolic link to static library. Link dynamically.' 82 + print@PYTHON_OPEN@"WARNING: Failed to create symbolic link to static library. Link dynamically."@PYTHON_CLOSE@
83 83
84 # Set default include directories and data files 84 # Set default include directories and data files
85 include_dirs = ['@prefix@/include/gammalib'] 85 include_dirs = ['@prefix@/include/gammalib']