prepare for autosource, also test update.py

This commit is contained in:
Radovan Bast 2015-07-17 14:52:07 +02:00
parent e36fd4300f
commit f7238ca4d2
3 changed files with 82 additions and 1 deletions

View File

@ -6,5 +6,6 @@ script:
- pep8 --ignore=E501 update.py
- pep8 --ignore=E501 test/test.py
- pep8 --ignore=E501 lib/config.py
- py.test -vv update.py
- py.test -vv test/test.py
- py.test -vv lib/config.py

View File

@ -62,4 +62,6 @@ test_script:
- echo %path%
- py.test --version
# run tests
- py.test -v test/test.py
- py.test -vv update.py
- py.test -vv test/test.py
- py.test -vv lib/config.py

View File

@ -7,6 +7,7 @@ from collections import OrderedDict, namedtuple
# we do not use the nicer sys.version_info.major
# for compatibility with Python < 2.7
if sys.version_info[0] > 2:
from io import StringIO
from configparser import RawConfigParser
import urllib.request
@ -15,6 +16,7 @@ if sys.version_info[0] > 2:
sys.stderr.write("ERROR: could not fetch %s\n" % url)
sys.exit(-1)
else:
from StringIO import StringIO
from ConfigParser import RawConfigParser
import urllib
@ -26,6 +28,8 @@ else:
AUTOCMAKE_GITHUB_URL = 'https://github.com/scisoft/autocmake'
# ------------------------------------------------------------------------------
def fetch_url(src, dst):
"""
@ -39,6 +43,8 @@ def fetch_url(src, dst):
opener = URLopener()
opener.retrieve(src, dst)
# ------------------------------------------------------------------------------
def print_progress_bar(text, done, total, width):
"""
@ -49,6 +55,8 @@ def print_progress_bar(text, done, total, width):
' ' * (width - n), done, total))
sys.stdout.flush()
# ------------------------------------------------------------------------------
def align_options(options):
"""
@ -63,6 +71,8 @@ def align_options(options):
s.append(' %s%s %s' % (opt[0], ' ' * (l - len(opt[0])), opt[1]))
return '\n'.join(s)
# ------------------------------------------------------------------------------
def gen_cmake_command(config):
"""
@ -97,6 +107,8 @@ def gen_cmake_command(config):
return '\n'.join(s)
# ------------------------------------------------------------------------------
def gen_setup(config, relative_path):
"""
@ -153,6 +165,8 @@ def gen_setup(config, relative_path):
return s
# ------------------------------------------------------------------------------
def gen_cmakelists(config, relative_path, modules):
"""
@ -193,6 +207,8 @@ def gen_cmakelists(config, relative_path, modules):
return s
# ------------------------------------------------------------------------------
def fetch_modules(config, relative_path):
"""
@ -242,6 +258,8 @@ def fetch_modules(config, relative_path):
return modules
# ------------------------------------------------------------------------------
def main(argv):
"""
@ -311,6 +329,66 @@ def main(argv):
with open(os.path.join(project_root, 'setup.py'), 'w') as f:
f.write('%s\n' % '\n'.join(s))
# ------------------------------------------------------------------------------
def parse_cmake_module(s_in):
s_out = []
is_rst_line = False
for line in s_in.split('\n'):
if is_rst_line:
if len(line) > 0:
if line[0] != '#':
is_rst_line = False
else:
is_rst_line = False
if is_rst_line:
s_out.append(line[2:])
if '#.rst:' in line:
is_rst_line = True
autocmake_entry = '\n'.join(s_out).split('Example autocmake.cfg entry::')[1]
autocmake_entry = autocmake_entry.replace('\n ', '\n')
buf = StringIO(autocmake_entry)
config = RawConfigParser(dict_type=OrderedDict)
config.readfp(buf)
return config
# ------------------------------------------------------------------------------
def test_parse_cmake_module():
s = '''#.rst:
#
# Foo ...
#
# Example autocmake.cfg entry::
#
# [cxx]
# source: https://github.com/scisoft/autocmake/raw/master/modules/cxx.cmake
# docopt: --cxx=<CXX> C++ compiler [default: g++].
# --extra-cxx-flags=<EXTRA_CXXFLAGS> Extra C++ compiler flags [default: ''].
# export: 'CXX=%s' % arguments['--cxx']
# define: '-DEXTRA_CXXFLAGS="%s"' % arguments['--extra-cxx-flags']
enable_language(CXX)
if(NOT DEFINED CMAKE_C_COMPILER_ID)
message(FATAL_ERROR "CMAKE_C_COMPILER_ID variable is not defined!")
endif()'''
config = parse_cmake_module(s)
assert config.sections() == ['cxx']
assert config.get('cxx', 'source') == 'https://github.com/scisoft/autocmake/raw/master/modules/cxx.cmake'
assert config.get('cxx', 'docopt').split('\n') == ["--cxx=<CXX> C++ compiler [default: g++].", "--extra-cxx-flags=<EXTRA_CXXFLAGS> Extra C++ compiler flags [default: '']."]
# ------------------------------------------------------------------------------
if __name__ == '__main__':
main(sys.argv)