prepare for autosource, also test update.py
This commit is contained in:
parent
e36fd4300f
commit
f7238ca4d2
@ -6,5 +6,6 @@ script:
|
|||||||
- pep8 --ignore=E501 update.py
|
- pep8 --ignore=E501 update.py
|
||||||
- pep8 --ignore=E501 test/test.py
|
- pep8 --ignore=E501 test/test.py
|
||||||
- pep8 --ignore=E501 lib/config.py
|
- pep8 --ignore=E501 lib/config.py
|
||||||
|
- py.test -vv update.py
|
||||||
- py.test -vv test/test.py
|
- py.test -vv test/test.py
|
||||||
- py.test -vv lib/config.py
|
- py.test -vv lib/config.py
|
||||||
|
@ -62,4 +62,6 @@ test_script:
|
|||||||
- echo %path%
|
- echo %path%
|
||||||
- py.test --version
|
- py.test --version
|
||||||
# run tests
|
# 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
|
||||||
|
78
update.py
78
update.py
@ -7,6 +7,7 @@ from collections import OrderedDict, namedtuple
|
|||||||
# we do not use the nicer sys.version_info.major
|
# we do not use the nicer sys.version_info.major
|
||||||
# for compatibility with Python < 2.7
|
# for compatibility with Python < 2.7
|
||||||
if sys.version_info[0] > 2:
|
if sys.version_info[0] > 2:
|
||||||
|
from io import StringIO
|
||||||
from configparser import RawConfigParser
|
from configparser import RawConfigParser
|
||||||
import urllib.request
|
import urllib.request
|
||||||
|
|
||||||
@ -15,6 +16,7 @@ if sys.version_info[0] > 2:
|
|||||||
sys.stderr.write("ERROR: could not fetch %s\n" % url)
|
sys.stderr.write("ERROR: could not fetch %s\n" % url)
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
else:
|
else:
|
||||||
|
from StringIO import StringIO
|
||||||
from ConfigParser import RawConfigParser
|
from ConfigParser import RawConfigParser
|
||||||
import urllib
|
import urllib
|
||||||
|
|
||||||
@ -26,6 +28,8 @@ else:
|
|||||||
|
|
||||||
AUTOCMAKE_GITHUB_URL = 'https://github.com/scisoft/autocmake'
|
AUTOCMAKE_GITHUB_URL = 'https://github.com/scisoft/autocmake'
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
def fetch_url(src, dst):
|
def fetch_url(src, dst):
|
||||||
"""
|
"""
|
||||||
@ -39,6 +43,8 @@ def fetch_url(src, dst):
|
|||||||
opener = URLopener()
|
opener = URLopener()
|
||||||
opener.retrieve(src, dst)
|
opener.retrieve(src, dst)
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
def print_progress_bar(text, done, total, width):
|
def print_progress_bar(text, done, total, width):
|
||||||
"""
|
"""
|
||||||
@ -49,6 +55,8 @@ def print_progress_bar(text, done, total, width):
|
|||||||
' ' * (width - n), done, total))
|
' ' * (width - n), done, total))
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
def align_options(options):
|
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]))
|
s.append(' %s%s %s' % (opt[0], ' ' * (l - len(opt[0])), opt[1]))
|
||||||
return '\n'.join(s)
|
return '\n'.join(s)
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
def gen_cmake_command(config):
|
def gen_cmake_command(config):
|
||||||
"""
|
"""
|
||||||
@ -97,6 +107,8 @@ def gen_cmake_command(config):
|
|||||||
|
|
||||||
return '\n'.join(s)
|
return '\n'.join(s)
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
def gen_setup(config, relative_path):
|
def gen_setup(config, relative_path):
|
||||||
"""
|
"""
|
||||||
@ -153,6 +165,8 @@ def gen_setup(config, relative_path):
|
|||||||
|
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
def gen_cmakelists(config, relative_path, modules):
|
def gen_cmakelists(config, relative_path, modules):
|
||||||
"""
|
"""
|
||||||
@ -193,6 +207,8 @@ def gen_cmakelists(config, relative_path, modules):
|
|||||||
|
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
def fetch_modules(config, relative_path):
|
def fetch_modules(config, relative_path):
|
||||||
"""
|
"""
|
||||||
@ -242,6 +258,8 @@ def fetch_modules(config, relative_path):
|
|||||||
|
|
||||||
return modules
|
return modules
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
def main(argv):
|
def main(argv):
|
||||||
"""
|
"""
|
||||||
@ -311,6 +329,66 @@ def main(argv):
|
|||||||
with open(os.path.join(project_root, 'setup.py'), 'w') as f:
|
with open(os.path.join(project_root, 'setup.py'), 'w') as f:
|
||||||
f.write('%s\n' % '\n'.join(s))
|
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__':
|
if __name__ == '__main__':
|
||||||
main(sys.argv)
|
main(sys.argv)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user