Skip to content

Commit

Permalink
Bring all the configy bits into config module
Browse files Browse the repository at this point in the history
  • Loading branch information
ericholscher committed Dec 21, 2015
1 parent f04d045 commit aaffe6e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 31 deletions.
36 changes: 36 additions & 0 deletions readthedocs/doc_builder/config.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@

from readthedocs_build.config import (ConfigError, BuildConfig,
load as load_config)


class ConfigWrapper(object):

"""
A config object that wraps the Project & YAML based configs.
Gives precidence to YAML, falling back to project if it isn't defined.
We only currently implement a subset of the existing YAML config.
This should be the canonical source for our usage of the YAML files,
never accessing the config object directly.
"""

def __init__(self, version, yaml_config):
Expand Down Expand Up @@ -76,3 +86,29 @@ def requirements_file(self):
# return self._yaml_config['type']
# else:
# return self._project.documentation_type


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)
try:
config = load_config(
path=checkout_path,
env_config={
'output_base': '',
},
)[0]
except ConfigError:
config = BuildConfig(
env_config={},
raw_config={},
source_file='empty',
source_position=0,
)
return ConfigWrapper(version=version, yaml_config=config)
33 changes: 2 additions & 31 deletions readthedocs/projects/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from readthedocs.core.utils import send_email, run_on_app_servers
from readthedocs.cdn.purge import purge
from readthedocs.doc_builder.loader import get_builder_class
from readthedocs.doc_builder.config import ConfigWrapper
from readthedocs.doc_builder.config import ConfigWrapper, load_yaml_config
from readthedocs.doc_builder.environments import (LocalEnvironment,
DockerEnvironment)
from readthedocs.doc_builder.exceptions import BuildEnvironmentError
Expand All @@ -45,8 +45,6 @@
from readthedocs.restapi.client import api as api_v2
from readthedocs.projects.signals import before_vcs, after_vcs, before_build, after_build
from readthedocs.core.resolver import resolve_path
from readthedocs_build.config import (ConfigError, BuildConfig,
load as load_config)


log = logging.getLogger(__name__)
Expand Down Expand Up @@ -99,32 +97,6 @@ def _log(self, msg):
version=self.version.slug,
msg=msg))

def load_yaml_config(self, 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)
try:
config = load_config(
path=checkout_path,
env_config={
'output_base': '',
},
)[0]
except ConfigError:
self._log(msg='No readthedocs.yml file found.')
config = BuildConfig(
env_config={},
raw_config={},
source_file='empty',
source_position=0,
)
return config

def run(self, pk, version_pk=None, build_pk=None, record=True, docker=False,
search=True, force=False, localmedia=True, **kwargs):

Expand All @@ -135,8 +107,7 @@ def run(self, pk, version_pk=None, build_pk=None, record=True, docker=False,
self.build_localmedia = localmedia
self.build_force = force

yaml_config = self.load_yaml_config(version=self.version)
self.config = ConfigWrapper(version=self.version, yaml_config=yaml_config)
self.config = load_yaml_config(version=self.version)

env_cls = LocalEnvironment
if docker or settings.DOCKER_ENABLE:
Expand Down

0 comments on commit aaffe6e

Please sign in to comment.