From 49e2dda540aaebbb5ea4744418c986c94540830e Mon Sep 17 00:00:00 2001 From: Radovan Bast Date: Mon, 11 Apr 2016 13:05:00 +0200 Subject: [PATCH 1/4] pep8 --- update.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/update.py b/update.py index fc26890..70c6bb5 100644 --- a/update.py +++ b/update.py @@ -53,8 +53,7 @@ def print_progress_bar(text, done, total, width): Print progress bar. """ n = int(float(width) * float(done) / float(total)) - sys.stdout.write("\r{0} [{1}{2}] ({3}/{4})".format(text, '#' * n, - ' ' * (width - n), done, total)) + sys.stdout.write("\r{0} [{1}{2}] ({3}/{4})".format(text, '#' * n, ' ' * (width - n), done, total)) sys.stdout.flush() # ------------------------------------------------------------------------------ From aebb3f7e6013e86dcc82ddab267aa0d9d7cd2994 Mon Sep 17 00:00:00 2001 From: Radovan Bast Date: Mon, 11 Apr 2016 13:06:59 +0200 Subject: [PATCH 2/4] module for saving compiler flags to cache --- modules/save_flags.cmake | 43 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 modules/save_flags.cmake diff --git a/modules/save_flags.cmake b/modules/save_flags.cmake new file mode 100644 index 0000000..d3dd677 --- /dev/null +++ b/modules/save_flags.cmake @@ -0,0 +1,43 @@ +#.rst: +# +# Take care of updating the cache for fresh configurations. +# +# Variables modified (provided the corresponding language is enabled):: +# +# DEFAULT_Fortran_FLAGS_SET +# DEFAULT_C_FLAGS_SET +# DEFAULT_CXX_FLAGS_SET + +macro(save_compiler_flags lang) + if (NOT DEFINED DEFAULT_${lang}_FLAGS_SET) + mark_as_advanced(DEFAULT_${lang}_FLAGS_SET) + + set (DEFAULT_${lang}_FLAGS_SET ON + CACHE INTERNAL + "Flag that the default ${lang} compiler flags have been set.") + + set(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS}" + CACHE STRING + "Flags used by the compiler during all builds." FORCE) + + set(CMAKE_${lang}_FLAGS_DEBUG "${CMAKE_${lang}_FLAGS_DEBUG}" + CACHE STRING + "Flags used by the compiler during debug builds." FORCE) + + set(CMAKE_${lang}_FLAGS_RELEASE "${CMAKE_${lang}_FLAGS_RELEASE}" + CACHE STRING + "Flags used by the compiler during release builds." FORCE) + endif() +endmacro() + +if(DEFINED CMAKE_Fortran_COMPILER_ID) + save_compiler_flags(Fortran) +endif() + +if(DEFINED CMAKE_C_COMPILER_ID) + save_compiler_flags(C) +endif() + +if(DEFINED CMAKE_CXX_COMPILER_ID) + save_compiler_flags(CXX) +endif() From 8319d41ba782910acbedb3267f2ded5fe8435bb3 Mon Sep 17 00:00:00 2001 From: Radovan Bast Date: Thu, 14 Apr 2016 12:12:41 +0200 Subject: [PATCH 3/4] use {0} instead of {} in format --- lib/config.py | 8 +++---- test/test.py | 2 +- update.py | 62 +++++++++++++++++++++++++-------------------------- 3 files changed, 36 insertions(+), 36 deletions(-) diff --git a/lib/config.py b/lib/config.py index 71de04e..399f9c3 100644 --- a/lib/config.py +++ b/lib/config.py @@ -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) diff --git a/test/test.py b/test/test.py index 77e0981..dd703f9 100644 --- a/test/test.py +++ b/test/test.py @@ -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(): diff --git a/update.py b/update.py index 70c6bb5..85cebcb 100644 --- a/update.py +++ b/update.py @@ -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(" $ {} \n".format(argv[0])) + sys.stderr.write(" $ {0} \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= C++ compiler [default: g++]. # --extra-cxx-flags= 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) From d6f552ce3e85fbfba90a75162fcfc0752d16d7ed Mon Sep 17 00:00:00 2001 From: Radovan Bast Date: Thu, 14 Apr 2016 12:13:28 +0200 Subject: [PATCH 4/4] setup script runs with python 2.6 --- doc/general/requirements.rst | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/doc/general/requirements.rst b/doc/general/requirements.rst index 5c81f63..6143cb4 100644 --- a/doc/general/requirements.rst +++ b/doc/general/requirements.rst @@ -7,9 +7,5 @@ Autocmake update and test scripts require Python 2.7 or higher. We try to also support Python 3 (tested with Python 3.4). If the script fails with Python 3, consider this a bug and please file an issue. -The generated setup script runs with Python >= 2.7 (also tested with Python +The generated setup script runs with Python >= 2.6 (also tested with Python 3.4; probably also lower). - -.. todo:: - - Figure out lower Python version bound for setup.