コード例 #1
0
ファイル: parse_rst.py プロジェクト: susilehtola/mrchem
def parse_cmake_module(s_in, overrides={}):
    import sys
    from collections import Mapping, Iterable, defaultdict
    from autocmake.parse_yaml import parse_yaml

    # 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
    else:
        from StringIO import StringIO

    parsed_config = defaultdict(lambda: None)

    if 'autocmake.yml configuration::' not in s_in:
        return parsed_config

    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(
        'autocmake.yml configuration::')[1]
    autocmake_entry = autocmake_entry.replace('\n  ', '\n')

    buf = StringIO(autocmake_entry)
    config = parse_yaml(buf, overrides)

    for k, v in config.items():
        if isinstance(v, Iterable) and not isinstance(v, str):
            parsed_config[k] = [x for x in config[k]]
        else:
            parsed_config[k] = [config[k]]

    return parsed_config
コード例 #2
0
ファイル: parse_rst.py プロジェクト: MRChemSoft/mrchem
def parse_cmake_module(s_in, overrides={}):
    import sys
    from collections import Mapping, Iterable, defaultdict
    from autocmake.parse_yaml import parse_yaml

    # 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
    else:
        from StringIO import StringIO

    parsed_config = defaultdict(lambda: None)

    if 'autocmake.yml configuration::' not in s_in:
        return parsed_config

    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('autocmake.yml configuration::')[1]
    autocmake_entry = autocmake_entry.replace('\n  ', '\n')

    buf = StringIO(autocmake_entry)
    config = parse_yaml(buf, overrides)

    for k, v in config.items():
        if isinstance(v, Iterable) and not isinstance(v, str):
            parsed_config[k] = [x for x in config[k]]
        else:
            parsed_config[k] = [config[k]]

    return parsed_config
コード例 #3
0
ファイル: update.py プロジェクト: robertodr/autocmake
def process_yaml(argv):
    from autocmake.parse_yaml import parse_yaml
    from autocmake.generate import gen_cmakelists, gen_setup
    from autocmake.extract import extract_list

    project_root = argv[1]
    if not os.path.isdir(project_root):
        sys.stderr.write("ERROR: {0} is not a directory\n".format(project_root))
        sys.exit(-1)

    # read config file
    print('- parsing autocmake.yml')
    with open('autocmake.yml', 'r') as stream:
        config = parse_yaml(stream)

    if 'name' in config:
        project_name = config['name']
    else:
        sys.stderr.write("ERROR: you have to specify the project name in autocmake.yml\n")
        sys.exit(-1)
    if ' ' in project_name.rstrip():
        sys.stderr.write("ERROR: project name contains a space\n")
        sys.exit(-1)

    if 'min_cmake_version' in config:
        min_cmake_version = config['min_cmake_version']
    else:
        sys.stderr.write("ERROR: you have to specify min_cmake_version in autocmake.yml\n")
        sys.exit(-1)

    if 'setup_script' in config:
        setup_script_name = config['setup_script']
    else:
        setup_script_name = 'setup'

    # get relative path from setup script to this directory
    relative_path = os.path.relpath(os.path.abspath('.'), project_root)

    download_directory = 'downloaded'
    if not os.path.exists(download_directory):
        os.makedirs(download_directory)

    # fetch modules from the web or from relative paths
    modules, cleaned_config = fetch_modules(config, relative_path, download_directory)

    # fetch files which are not parsed
    for src in cleaned_config['fetch']:
        dst = os.path.join(download_directory, os.path.basename(src))
        fetch_url(src, dst)

    # print warnings
    for warning in cleaned_config['warning']:
        print('- WARNING: {0}'.format(warning))

    # create CMakeLists.txt
    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('{0}\n'.format('\n'.join(s)))

    # create setup script
    print('- generating setup script')
    s = gen_setup(cleaned_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('{0}\n'.format('\n'.join(s)))
    if sys.platform != 'win32':
        make_executable(file_path)
コード例 #4
0
ファイル: update.py プロジェクト: arnfinn/mrchem
def process_yaml(argv):
    from autocmake.parse_yaml import parse_yaml
    from autocmake.generate import gen_cmakelists, gen_setup
    from autocmake.extract import extract_list

    project_root = argv[1]
    if not os.path.isdir(project_root):
        sys.stderr.write(
            "ERROR: {0} is not a directory\n".format(project_root))
        sys.exit(-1)

    # read config file
    print('- parsing autocmake.yml')
    with open('autocmake.yml', 'r') as stream:
        config = parse_yaml(stream)

    if 'name' in config:
        project_name = config['name']
    else:
        sys.stderr.write(
            "ERROR: you have to specify the project name in autocmake.yml\n")
        sys.exit(-1)
    if ' ' in project_name.rstrip():
        sys.stderr.write("ERROR: project name contains a space\n")
        sys.exit(-1)

    if 'min_cmake_version' in config:
        min_cmake_version = config['min_cmake_version']
    else:
        sys.stderr.write(
            "ERROR: you have to specify min_cmake_version in autocmake.yml\n")
        sys.exit(-1)

    if 'setup_script' in config:
        setup_script_name = config['setup_script']
    else:
        setup_script_name = 'setup'

    # get relative path from setup script to this directory
    relative_path = os.path.relpath(os.path.abspath('.'), project_root)

    download_directory = 'downloaded'
    if not os.path.exists(download_directory):
        os.makedirs(download_directory)

    # fetch modules from the web or from relative paths
    modules, cleaned_config = fetch_modules(config, relative_path,
                                            download_directory)

    # fetch files which are not parsed
    for src in cleaned_config['fetch']:
        dst = os.path.join(download_directory, os.path.basename(src))
        fetch_url(src, dst)

    # print warnings
    for warning in cleaned_config['warning']:
        print('- WARNING: {0}'.format(warning))

    # create CMakeLists.txt
    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('{0}\n'.format('\n'.join(s)))

    # create setup script
    print('- generating setup script')
    s = gen_setup(cleaned_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('{0}\n'.format('\n'.join(s)))
    if sys.platform != 'win32':
        make_executable(file_path)
コード例 #5
0
def process_yaml(argv):
    from autocmake.parse_yaml import parse_yaml
    from autocmake.generate import gen_cmakelists, gen_setup
    from autocmake.extract import extract_list

    project_root = argv[1]
    if not os.path.isdir(project_root):
        sys.stderr.write(
            "ERROR: {0} is not a directory\n".format(project_root))
        sys.exit(-1)

    # read config file
    print('- parsing autocmake.yml')
    with open('autocmake.yml', 'r') as stream:
        config = parse_yaml(stream)

    if 'name' in config:
        project_name = config['name']
    else:
        sys.stderr.write(
            "ERROR: you have to specify the project name in autocmake.yml\n")
        sys.exit(-1)
    if ' ' in project_name.rstrip():
        sys.stderr.write("ERROR: project name contains a space\n")
        sys.exit(-1)

    if 'language' in config:
        project_language = ' '.join(config['language']) if isinstance(
            config['language'], list) else config['language']
    else:
        sys.stderr.write(
            "ERROR: you have to specify the project language(s) in autocmake.yml\n\n"
        )
        sys.stderr.write(
            "# for instance like this (several languages):\nlanguage:\n  - CXX\n  - Fortran\n\n"
        )
        sys.stderr.write(
            "# or like this (one language):\nlanguage: Fortran\n\n")
        sys.exit(-1)

    if 'min_cmake_version' in config:
        min_cmake_version = config['min_cmake_version']
    else:
        sys.stderr.write(
            "ERROR: you have to specify min_cmake_version in autocmake.yml\n")
        sys.exit(-1)

    if 'default_build_type' in config:
        default_build_type = config['default_build_type'].lower()
    else:
        sys.stderr.write(
            "ERROR: you have to specify default_build_type in autocmake.yml\n\n"
        )
        sys.stderr.write(
            "# for instance like this (debug, release, relwithdebinfo, or minsizerel):\ndefault_build_type: release\n\n"
        )
        sys.exit(-1)

    if 'setup_script' in config:
        setup_script_name = config['setup_script']
    else:
        setup_script_name = 'setup'

    # get relative path from setup script to this directory
    relative_path = os.path.relpath(os.path.abspath('.'), project_root)

    download_directory = 'downloaded'
    if not os.path.exists(download_directory):
        os.makedirs(download_directory)

    # fetch modules from the web or from relative paths
    modules, cleaned_config = fetch_modules(config, relative_path,
                                            download_directory)

    # fetch files which are not parsed
    for src in cleaned_config['fetch']:
        dst = os.path.join(download_directory, os.path.basename(src))
        fetch_url(src, dst)

    # print warnings
    for warning in cleaned_config['warning']:
        print('- WARNING: {0}'.format(warning))

    # create CMakeLists.txt
    print('- generating CMakeLists.txt')
    s = gen_cmakelists(project_name, project_language, min_cmake_version,
                       default_build_type, relative_path, modules)
    with open(os.path.join(project_root, 'CMakeLists.txt'), 'w') as f:
        f.write('{0}\n'.format('\n'.join(s)))

    # create setup script unless it is 'None' or 'none'
    if setup_script_name.lower() != 'none':
        print('- generating setup script')
        s = gen_setup(cleaned_config, default_build_type, relative_path,
                      setup_script_name)
        file_path = os.path.join(project_root, setup_script_name)
        with open(file_path, 'w') as f:
            f.write('{0}\n'.format('\n'.join(s)))
        if sys.platform != 'win32':
            make_executable(file_path)
コード例 #6
0
ファイル: update.py プロジェクト: PCMSolver/pcmsolver
def process_yaml(argv):
    from autocmake.parse_yaml import parse_yaml
    from autocmake.generate import gen_cmakelists, gen_setup
    from autocmake.extract import extract_list

    project_root = argv[1]
    if not os.path.isdir(project_root):
        sys.stderr.write("ERROR: {0} is not a directory\n".format(project_root))
        sys.exit(-1)

    # read config file
    print('- parsing autocmake.yml')
    with open('autocmake.yml', 'r') as stream:
        config = parse_yaml(stream)

    if 'name' in config:
        project_name = config['name']
    else:
        sys.stderr.write("ERROR: you have to specify the project name in autocmake.yml\n")
        sys.exit(-1)
    if ' ' in project_name.rstrip():
        sys.stderr.write("ERROR: project name contains a space\n")
        sys.exit(-1)

    if 'language' in config:
        project_language = ' '.join(config['language']) if isinstance(config['language'], list) else config['language']
    else:
        sys.stderr.write("ERROR: you have to specify the project language(s) in autocmake.yml\n\n")
        sys.stderr.write("# for instance like this (several languages):\nlanguage:\n  - CXX\n  - Fortran\n\n")
        sys.stderr.write("# or like this (one language):\nlanguage: Fortran\n\n")
        sys.exit(-1)

    if 'min_cmake_version' in config:
        min_cmake_version = config['min_cmake_version']
    else:
        sys.stderr.write("ERROR: you have to specify min_cmake_version in autocmake.yml\n")
        sys.exit(-1)

    if 'default_build_type' in config:
        default_build_type = config['default_build_type'].lower()
    else:
        sys.stderr.write("ERROR: you have to specify default_build_type in autocmake.yml\n\n")
        sys.stderr.write("# for instance like this (debug, release, relwithdebinfo, or minsizerel):\ndefault_build_type: release\n\n")
        sys.exit(-1)

    if 'setup_script' in config:
        setup_script_name = config['setup_script']
    else:
        setup_script_name = 'setup'

    # get relative path from setup script to this directory
    relative_path = os.path.relpath(os.path.abspath('.'), project_root)

    download_directory = 'downloaded'
    if not os.path.exists(download_directory):
        os.makedirs(download_directory)

    # fetch modules from the web or from relative paths
    modules, cleaned_config = fetch_modules(config, relative_path, download_directory)

    # fetch files which are not parsed
    for src in cleaned_config['fetch']:
        dst = os.path.join(download_directory, os.path.basename(src))
        fetch_url(src, dst)

    # print warnings
    for warning in cleaned_config['warning']:
        print('- WARNING: {0}'.format(warning))

    # create CMakeLists.txt
    print('- generating CMakeLists.txt')
    s = gen_cmakelists(project_name, project_language, min_cmake_version, default_build_type, relative_path, modules)
    with open(os.path.join(project_root, 'CMakeLists.txt'), 'w') as f:
        f.write('{0}\n'.format('\n'.join(s)))

    # create setup script unless it is 'None' or 'none'
    if setup_script_name.lower() != 'none':
        print('- generating setup script')
        s = gen_setup(cleaned_config, default_build_type, relative_path, setup_script_name)
        file_path = os.path.join(project_root, setup_script_name)
        with open(file_path, 'w') as f:
            f.write('{0}\n'.format('\n'.join(s)))
        if sys.platform != 'win32':
            make_executable(file_path)