Replace print statment with print function

In PY3, print should used as a function instead of a statement.
This is PY27 compatible as well.

For example, instances of the first case were replaced by the
second case:

>>> print 'help'
  File "<stdin>", line 1
    print 'help'
               ^
SyntaxError: Missing parentheses in call to 'print'

>>> print('help')
help

Partially implements: blueprint trove-python3
Change-Id: I21de65bc874d0fcfb51714857f8eaa97acb2f51d
Closes-bug: #1594741
This commit is contained in:
bhagyashris 2016-06-21 17:18:17 +05:30
parent 6ea1a92aba
commit fa08854a6d
1 changed files with 13 additions and 11 deletions

View File

@ -22,6 +22,8 @@
Installation script for Trove's development virtualenv Installation script for Trove's development virtualenv
""" """
from __future__ import print_function
import os import os
import subprocess import subprocess
import sys import sys
@ -35,7 +37,7 @@ PY_VERSION = "python%s.%s" % (sys.version_info[0], sys.version_info[1])
def die(message, *args): def die(message, *args):
print >> sys.stderr, message % args print(message % args, file=sys.stderr)
sys.exit(1) sys.exit(1)
@ -71,34 +73,34 @@ def check_dependencies():
"""Make sure virtualenv is in the path.""" """Make sure virtualenv is in the path."""
if not HAS_VIRTUALENV: if not HAS_VIRTUALENV:
print 'not found.' print('not found.')
# Try installing it via easy_install... # Try installing it via easy_install...
if HAS_EASY_INSTALL: if HAS_EASY_INSTALL:
print 'Installing virtualenv via easy_install...', print('Installing virtualenv via easy_install...'),
if not (run_command(['which', 'easy_install']) and if not (run_command(['which', 'easy_install']) and
run_command(['easy_install', 'virtualenv'])): run_command(['easy_install', 'virtualenv'])):
die('ERROR: virtualenv not found.\n\Trove development' die('ERROR: virtualenv not found.\n\Trove development'
' requires virtualenv, please install it using your' ' requires virtualenv, please install it using your'
' favorite package management tool') ' favorite package management tool')
print 'done.' print('done.')
print 'done.' print('done.')
def create_virtualenv(venv=VENV): def create_virtualenv(venv=VENV):
"""Creates the virtual environment and installs PIP only into the """Creates the virtual environment and installs PIP only into the
virtual environment virtual environment
""" """
print 'Creating venv...', print('Creating venv...'),
run_command(['virtualenv', '-q', '--no-site-packages', VENV]) run_command(['virtualenv', '-q', '--no-site-packages', VENV])
print 'done.' print('done.')
print 'Installing pip in virtualenv...', print('Installing pip in virtualenv...'),
if not run_command(['tools/with_venv.sh', 'easy_install', 'pip']).strip(): if not run_command(['tools/with_venv.sh', 'easy_install', 'pip']).strip():
die("Failed to install pip.") die("Failed to install pip.")
print 'done.' print('done.')
def install_dependencies(venv=VENV): def install_dependencies(venv=VENV):
print 'Installing dependencies with pip (this can take a while)...' print('Installing dependencies with pip (this can take a while)...')
# Install greenlet by hand - just listing it in the requires file does not # Install greenlet by hand - just listing it in the requires file does not
# get it in stalled in the right order # get it in stalled in the right order
run_command(['tools/with_venv.sh', '-E', venv, 'pip', 'install', run_command(['tools/with_venv.sh', '-E', venv, 'pip', 'install',
@ -133,7 +135,7 @@ def print_help():
Also, make test will automatically use the virtualenv. Also, make test will automatically use the virtualenv.
""" """
print help print(help)
def main(argv): def main(argv):