use {0} instead of {} in format

This commit is contained in:
Radovan Bast 2016-04-14 12:12:41 +02:00
parent aebb3f7e60
commit 8319d41ba7
3 changed files with 36 additions and 36 deletions

View File

@ -23,7 +23,7 @@ def check_cmake_exists(cmake_command):
"""
from subprocess import Popen, PIPE
p = Popen('{} --version'.format(cmake_command),
p = Popen('{0} --version'.format(cmake_command),
shell=True,
stdin=PIPE,
stdout=PIPE)
@ -46,7 +46,7 @@ def setup_build_path(build_path):
fname = os.path.join(build_path, 'CMakeCache.txt')
if os.path.exists(fname):
sys.stderr.write('aborting setup\n')
sys.stderr.write('build directory {} which contains CMakeCache.txt already exists\n'.format(build_path))
sys.stderr.write('build directory {0} which contains CMakeCache.txt already exists\n'.format(build_path))
sys.stderr.write('remove the build directory and then rerun setup\n')
sys.exit(1)
else:
@ -74,7 +74,7 @@ def adapt_cmake_command_to_platform(cmake_command, platform):
"""
if platform == 'win32':
pos = cmake_command.find('cmake')
s = ['set {} &&'.format(e) for e in cmake_command[:pos].split()]
s = ['set {0} &&'.format(e) for e in cmake_command[:pos].split()]
s.append(cmake_command[pos:])
return ' '.join(s)
else:
@ -159,7 +159,7 @@ def configure(root_directory, build_path, cmake_command, only_show):
cmake_command = adapt_cmake_command_to_platform(cmake_command, sys.platform)
print('{}\n'.format(cmake_command))
print('{0}\n'.format(cmake_command))
if only_show:
sys.exit(0)

View File

@ -151,7 +151,7 @@ def test_python_libs():
def test_python_libs_custom():
python_executable = sys.executable
configure_build_and_exe('python_libs_custom', 'python setup --cxx=g++ --python={}'.format(python_executable))
configure_build_and_exe('python_libs_custom', 'python setup --cxx=g++ --python={0}'.format(python_executable))
def test_boost_header_only():

View File

@ -15,7 +15,7 @@ if sys.version_info[0] > 2:
class URLopener(urllib.request.FancyURLopener):
def http_error_default(self, url, fp, errcode, errmsg, headers):
sys.stderr.write("ERROR: could not fetch {}\n".format(url))
sys.stderr.write("ERROR: could not fetch {0}\n".format(url))
sys.exit(-1)
else:
from StringIO import StringIO
@ -24,7 +24,7 @@ else:
class URLopener(urllib.FancyURLopener):
def http_error_default(self, url, fp, errcode, errmsg, headers):
sys.stderr.write("ERROR: could not fetch {}\n".format(url))
sys.stderr.write("ERROR: could not fetch {0}\n".format(url))
sys.exit(-1)
@ -91,7 +91,7 @@ def gen_cmake_command(config):
for section in config.sections():
if config.has_option(section, 'export'):
for env in config.get(section, 'export').split('\n'):
s.append(' command.append({})'.format(env))
s.append(' command.append({0})'.format(env))
s.append(" command.append(arguments['--cmake-executable'])")
@ -99,10 +99,10 @@ def gen_cmake_command(config):
for section in config.sections():
if config.has_option(section, 'define'):
for definition in config.get(section, 'define').split('\n'):
s.append(' command.append({})'.format(definition))
s.append(' command.append({0})'.format(definition))
s.append(" command.append('-DCMAKE_BUILD_TYPE={}'.format(arguments['--type']))")
s.append(" command.append('-G \"{}\"'.format(arguments['--generator']))")
s.append(" command.append('-DCMAKE_BUILD_TYPE={0}'.format(arguments['--type']))")
s.append(" command.append('-G \"{0}\"'.format(arguments['--generator']))")
s.append(" if arguments['--cmake-options'] != \"''\":")
s.append(" command.append(arguments['--cmake-options'])")
s.append(" if arguments['--prefix']:")
@ -117,10 +117,10 @@ def gen_cmake_command(config):
def autogenerated_notice():
current_year = datetime.date.today().year
year_range = '2015-{}'.format(current_year)
year_range = '2015-{0}'.format(current_year)
s = []
s.append('# This file is autogenerated by Autocmake http://autocmake.org')
s.append('# Copyright (c) {} by Radovan Bast and Jonas Juselius'.format(year_range))
s.append('# Copyright (c) {0} by Radovan Bast and Jonas Juselius'.format(year_range))
return '\n'.join(s)
# ------------------------------------------------------------------------------
@ -132,7 +132,7 @@ def gen_setup(config, relative_path, setup_script_name):
"""
s = []
s.append('#!/usr/bin/env python')
s.append('\n{}'.format(autogenerated_notice()))
s.append('\n{0}'.format(autogenerated_notice()))
s.append('\nimport os')
s.append('import sys')
@ -177,7 +177,7 @@ def gen_setup(config, relative_path, setup_script_name):
s.append("try:")
s.append(" arguments = docopt.docopt(options, argv=None)")
s.append("except docopt.DocoptExit:")
s.append(r" sys.stderr.write('ERROR: bad input to {}\n'.format(sys.argv[0]))")
s.append(r" sys.stderr.write('ERROR: bad input to {0}\n'.format(sys.argv[0]))")
s.append(" sys.stderr.write(options)")
s.append(" sys.exit(-1)")
s.append("\n")
@ -210,10 +210,10 @@ def gen_cmakelists(project_name, min_cmake_version, relative_path, modules):
s.append(autogenerated_notice())
s.append('\n# set minimum cmake version')
s.append('cmake_minimum_required(VERSION {} FATAL_ERROR)'.format(min_cmake_version))
s.append('cmake_minimum_required(VERSION {0} FATAL_ERROR)'.format(min_cmake_version))
s.append('\n# project name')
s.append('project({})'.format(project_name))
s.append('project({0})'.format(project_name))
s.append('\n# do not rebuild if rules (compiler flags) change')
s.append('set(CMAKE_SKIP_RULE_DEPENDENCY TRUE)')
@ -234,12 +234,12 @@ def gen_cmakelists(project_name, min_cmake_version, relative_path, modules):
rel_cmake_module_path = os.path.join(relative_path, directory)
# on windows cmake corrects this so we have to make it wrong again
rel_cmake_module_path = rel_cmake_module_path.replace('\\', '/')
s.append('set(CMAKE_MODULE_PATH ${{CMAKE_MODULE_PATH}} ${{PROJECT_SOURCE_DIR}}/{})'.format(rel_cmake_module_path))
s.append('set(CMAKE_MODULE_PATH ${{CMAKE_MODULE_PATH}} ${{PROJECT_SOURCE_DIR}}/{0})'.format(rel_cmake_module_path))
if len(modules) > 0:
s.append('\n# included cmake modules')
for module in modules:
s.append('include({})'.format(os.path.splitext(module.name)[0]))
s.append('include({0})'.format(os.path.splitext(module.name)[0]))
return s
@ -254,7 +254,7 @@ def prepend_or_set(config, section, option, value, defaults):
"""
if value:
if config.has_option(section, option):
value += '\n{}'.format(config.get(section, option, 0, defaults))
value += '\n{0}'.format(config.get(section, option, 0, defaults))
config.set(section, option, value)
return config
@ -289,8 +289,8 @@ def fetch_modules(config, relative_path):
module_name = os.path.basename(src)
if 'http' in src:
path = download_directory
name = 'autocmake_{}'.format(module_name)
dst = os.path.join(download_directory, 'autocmake_{}'.format(module_name))
name = 'autocmake_{0}'.format(module_name)
dst = os.path.join(download_directory, 'autocmake_{0}'.format(module_name))
fetch_url(src, dst)
file_name = dst
fetch_dst_directory = download_directory
@ -301,7 +301,7 @@ def fetch_modules(config, relative_path):
file_name = src
fetch_dst_directory = path
else:
sys.stderr.write("ERROR: {} does not exist\n".format(src))
sys.stderr.write("ERROR: {0} does not exist\n".format(src))
sys.exit(-1)
if config.has_option(section, 'override'):
@ -339,7 +339,7 @@ def fetch_modules(config, relative_path):
print('')
if warnings != []:
print('- {}'.format('\n- '.join(warnings)))
print('- {0}'.format('\n- '.join(warnings)))
return modules
@ -354,11 +354,11 @@ def main(argv):
sys.stderr.write("\nYou can update a project in two steps.\n\n")
sys.stderr.write("Step 1: Update or create infrastructure files\n")
sys.stderr.write(" which will be needed to configure and build the project:\n")
sys.stderr.write(" $ {} --self\n\n".format(argv[0]))
sys.stderr.write(" $ {0} --self\n\n".format(argv[0]))
sys.stderr.write("Step 2: Create CMakeLists.txt and setup script in PROJECT_ROOT:\n")
sys.stderr.write(" $ {} <PROJECT_ROOT>\n".format(argv[0]))
sys.stderr.write(" $ {0} <PROJECT_ROOT>\n".format(argv[0]))
sys.stderr.write(" example:\n")
sys.stderr.write(" $ {} ..\n".format(argv[0]))
sys.stderr.write(" $ {0} ..\n".format(argv[0]))
sys.exit(-1)
if argv[1] in ['-h', '--help']:
@ -373,7 +373,7 @@ def main(argv):
if not os.path.isfile('autocmake.cfg'):
print('- fetching example autocmake.cfg')
fetch_url(
src='{}/raw/master/example/autocmake.cfg'.format(AUTOCMAKE_GITHUB_URL),
src='{0}/raw/master/example/autocmake.cfg'.format(AUTOCMAKE_GITHUB_URL),
dst='autocmake.cfg'
)
if not os.path.isfile('.gitignore'):
@ -382,24 +382,24 @@ def main(argv):
f.write('*.pyc\n')
print('- fetching lib/config.py')
fetch_url(
src='{}/raw/master/lib/config.py'.format(AUTOCMAKE_GITHUB_URL),
src='{0}/raw/master/lib/config.py'.format(AUTOCMAKE_GITHUB_URL),
dst='lib/config.py'
)
print('- fetching lib/docopt/docopt.py')
fetch_url(
src='{}/raw/master/lib/docopt/docopt.py'.format(AUTOCMAKE_GITHUB_URL),
src='{0}/raw/master/lib/docopt/docopt.py'.format(AUTOCMAKE_GITHUB_URL),
dst='lib/docopt/docopt.py'
)
print('- fetching update.py')
fetch_url(
src='{}/raw/master/update.py'.format(AUTOCMAKE_GITHUB_URL),
src='{0}/raw/master/update.py'.format(AUTOCMAKE_GITHUB_URL),
dst='update.py'
)
sys.exit(0)
project_root = argv[1]
if not os.path.isdir(project_root):
sys.stderr.write("ERROR: {} is not a directory\n".format(project_root))
sys.stderr.write("ERROR: {0} is not a directory\n".format(project_root))
sys.exit(-1)
# read config file
@ -437,14 +437,14 @@ def main(argv):
print('- generating CMakeLists.txt')
s = gen_cmakelists(project_name, min_cmake_version, relative_path, modules)
with open(os.path.join(project_root, 'CMakeLists.txt'), 'w') as f:
f.write('{}\n'.format('\n'.join(s)))
f.write('{0}\n'.format('\n'.join(s)))
# create setup script
print('- generating setup script')
s = gen_setup(config, relative_path, setup_script_name)
file_path = os.path.join(project_root, setup_script_name)
with open(file_path, 'w') as f:
f.write('{}\n'.format('\n'.join(s)))
f.write('{0}\n'.format('\n'.join(s)))
if sys.platform != 'win32':
make_executable(file_path)
@ -511,8 +511,8 @@ def test_parse_cmake_module():
#
# docopt: --cxx=<CXX> C++ compiler [default: g++].
# --extra-cxx-flags=<EXTRA_CXXFLAGS> Extra C++ compiler flags [default: ''].
# export: 'CXX={}'.format(arguments['--cxx'])
# define: '-DEXTRA_CXXFLAGS="{}"'.format(arguments['--extra-cxx-flags'])
# export: 'CXX={0}'.format(arguments['--cxx'])
# define: '-DEXTRA_CXXFLAGS="{0}"'.format(arguments['--extra-cxx-flags'])
enable_language(CXX)