def load_yaml_config(version): """ Load a configuration from `readthedocs.yml` file. This uses the configuration logic from `readthedocs-build`, which will keep parsing consistent between projects. """ checkout_path = version.project.checkout_path(version.slug) project = version.project # Get build image to set up the python version validation. Pass in the # build image python limitations to the loaded config so that the versions # can be rejected at validation img_name = project.container_image or DOCKER_IMAGE python_version = 3 if project.python_interpreter == 'python3' else 2 try: sphinx_configuration = path.join( version.get_conf_py_path(), 'conf.py', ) except ProjectConfigurationError: sphinx_configuration = None env_config = { 'build': { 'image': img_name, }, 'defaults': { 'install_project': project.install_project, 'formats': get_default_formats(project), 'use_system_packages': project.use_system_packages, 'requirements_file': project.requirements_file, 'python_version': python_version, 'sphinx_configuration': sphinx_configuration, 'build_image': project.container_image, 'doctype': project.documentation_type, }, } img_settings = DOCKER_IMAGE_SETTINGS.get(img_name, None) if img_settings: env_config.update(img_settings) try: config = load_config( path=checkout_path, env_config=env_config, ) except InvalidConfig: # This is a subclass of ConfigError, so has to come first raise except ConfigError: config = BuildConfigV1( env_config=env_config, raw_config={}, source_file=checkout_path, ) config.validate() return config
def inner(path=None, env_config=None): env_config_defaults = { 'output_base': '', 'name': '1', } if env_config is not None: env_config_defaults.update(env_config) yaml_config = BuildConfigV1( env_config_defaults, config, source_file='readthedocs.yml', ) yaml_config.validate() return yaml_config