Commit e0891e8ecdcd66b3537095d5b26a846cf90af47d
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.
Showing
2 changed files
with
17 additions
and
6 deletions
configure.ac
| ... | ... | @@ -533,6 +533,17 @@ AM_PATH_PYTHON([2.2], |
| 533 | 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 | 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 | 547 | # Do we have distutils? |
| 537 | 548 | AC_MSG_CHECKING([for the distutils Python package]) |
| 538 | 549 | ac_distutils_result=`$PYTHON -c "import distutils" 2>&1` |
| ... | ... | @@ -558,7 +569,7 @@ if test "x$has_python" = "xyes"; then |
| 558 | 569 | fi |
| 559 | 570 | PYTHON_CPPFLAGS=$python_path |
| 560 | 571 | CPPFLAGS="${CPPFLAGS} ${python_path}" |
| 561 | - AC_SUBST([PYTHON_CPPFLAGS]) | |
| 572 | + AC_SUBST([PYTHON_CPPFLAGS]) | |
| 562 | 573 | |
| 563 | 574 | # ... otherwise check for includes relative to exectuable (obsolete?) |
| 564 | 575 | else | ... | ... |
pyext/setup.py.in
| ... | ... | @@ -29,7 +29,7 @@ import sys |
| 29 | 29 | is_unit_test = False |
| 30 | 30 | if (len(sys.argv) >= 3): |
| 31 | 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 | 33 | is_unit_test = True |
| 34 | 34 | |
| 35 | 35 | # Darwin MacPorts kluge: Remove -L/opt/local/lib path from LDSHARED as this |
| ... | ... | @@ -50,7 +50,7 @@ if sys.platform.lower().startswith("darwin"): |
| 50 | 50 | else: |
| 51 | 51 | ldshared_rm += option + ' ' |
| 52 | 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 | 55 | # Set LDSHARED |
| 56 | 56 | cvars['LDSHARED'] = ldshared_new |
| ... | ... | @@ -68,7 +68,7 @@ if sys.platform.lower().startswith("darwin") and is_unit_test: |
| 68 | 68 | # an already existing link. |
| 69 | 69 | try: |
| 70 | 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 | 72 | except: |
| 73 | 73 | pass |
| 74 | 74 | |
| ... | ... | @@ -76,10 +76,10 @@ if sys.platform.lower().startswith("darwin") and is_unit_test: |
| 76 | 76 | # symbolic link |
| 77 | 77 | try: |
| 78 | 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 | 80 | libcta='ctools_python' |
| 81 | 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 | 84 | # Set default include directories and data files |
| 85 | 85 | include_dirs = ['@prefix@/include/gammalib'] | ... | ... |