Skip to content

Commit 8fe7687

Browse files
committed
Merge pull request readthedocs#1945 from rtfd/yaml-format-support
Add support for `formats` in the YAML config.
2 parents d3abbac + 18f15a9 commit 8fe7687

File tree

5 files changed

+102
-31
lines changed

5 files changed

+102
-31
lines changed

docs/yaml-config.rst

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,35 @@ must be in the root directory of your project.
1212
Supported Settings
1313
------------------
1414

15+
formats
16+
~~~~~~~
17+
18+
* Default: `['htmlzip', 'pdf', 'epub']`
19+
* Options: htmlzip, pdf, epub
20+
21+
The formats of your documentation you want to be built.
22+
23+
.. note:: We will always build an HTML & JSON version of your documentation.
24+
These are used for web serving & search indexing, respectively.
25+
26+
.. code-block:: yaml
27+
28+
requirements_file: requirements/docs.txt
29+
30+
requirements_file
31+
~~~~~~~~~~~~~~~~~
32+
33+
* Default: `None`
34+
* Type: Path (specified from the root of the project)
35+
36+
The path to your Pip requirements file.
37+
38+
.. code-block:: yaml
39+
40+
requirements_file: requirements/docs.txt
41+
42+
43+
1544
conda
1645
~~~~~
1746

@@ -64,19 +93,6 @@ When true, install your project into the Virtualenv when building documentation.
6493
python:
6594
setup_py_install: true
6695
67-
requirements_file
68-
~~~~~~~~~~~~~~~~~
69-
70-
* Default: `None`
71-
* Type: Path (specified from the root of the project)
72-
73-
The path to your Pip requirements file.
74-
75-
.. code-block:: yaml
76-
77-
requirements_file: requirements/docs.txt
78-
79-
8096
.. To implement..
8197
8298
type

readthedocs/doc_builder/config.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,18 @@ def requirements_file(self):
8080
else:
8181
return self._project.requirements_file
8282

83+
@property
84+
def formats(self):
85+
if 'formats' in self._yaml_config:
86+
return self._yaml_config['formats']
87+
else:
88+
formats = ['htmlzip']
89+
if self._project.enable_epub_build:
90+
formats += ['epub']
91+
if self._project.enable_pdf_build:
92+
formats += ['pdf']
93+
return formats
94+
8395
# Not implemented until we figure out how to keep in sync with the webs.
8496
# Probably needs to be version-specific as well, not project.
8597
# @property

readthedocs/projects/tasks.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ class UpdateDocsTask(Task):
7474
default_retry_delay = (7 * 60)
7575
name = 'update_docs'
7676

77-
def __init__(self, build_env=None, python_env=None, force=False, search=True, localmedia=True,
77+
def __init__(self, build_env=None, python_env=None, config=None,
78+
force=False, search=True, localmedia=True,
7879
build=None, project=None, version=None):
7980
self.build_env = build_env
8081
self.python_env = python_env
@@ -90,6 +91,8 @@ def __init__(self, build_env=None, python_env=None, force=False, search=True, lo
9091
self.project = {}
9192
if project is not None:
9293
self.project = project
94+
if config is not None:
95+
self.config = config
9396

9497
def _log(self, msg):
9598
log.info(LOG_TEMPLATE
@@ -349,24 +352,27 @@ def build_docs_search(self):
349352

350353
def build_docs_localmedia(self):
351354
"""Get local media files with separate build"""
355+
if 'htmlzip' not in self.config.formats:
356+
return False
357+
352358
if self.build_localmedia:
353359
if self.project.is_type_sphinx:
354360
return self.build_docs_class('sphinx_singlehtmllocalmedia')
355361
return False
356362

357363
def build_docs_pdf(self):
358364
"""Build PDF docs"""
359-
if (self.project.slug in HTML_ONLY or
360-
not self.project.is_type_sphinx or
361-
not self.project.enable_pdf_build):
365+
if ('pdf' not in self.config.formats or
366+
self.project.slug in HTML_ONLY or
367+
not self.project.is_type_sphinx):
362368
return False
363369
return self.build_docs_class('sphinx_pdf')
364370

365371
def build_docs_epub(self):
366372
"""Build ePub docs"""
367-
if (self.project.slug in HTML_ONLY or
368-
not self.project.is_type_sphinx or
369-
not self.project.enable_epub_build):
373+
if ('epub' not in self.config.formats or
374+
self.project.slug in HTML_ONLY or
375+
not self.project.is_type_sphinx):
370376
return False
371377
return self.build_docs_class('sphinx_epub')
372378

readthedocs/rtd_tests/tests/test_builds.py

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
import mock
66

77
from readthedocs.projects.models import Project
8+
from readthedocs.doc_builder.config import ConfigWrapper
89
from readthedocs.doc_builder.environments import LocalEnvironment
910
from readthedocs.doc_builder.python_environments import Virtualenv
1011
from readthedocs.doc_builder.loader import get_builder_class
1112
from readthedocs.projects.tasks import UpdateDocsTask
13+
from readthedocs.rtd_tests.tests.test_config_wrapper import get_build_config
1214

1315
from ..mocks.environment import EnvironmentMockGroup
1416

@@ -38,8 +40,10 @@ def test_build(self):
3840

3941
build_env = LocalEnvironment(project=project, version=version, build={})
4042
python_env = Virtualenv(version=version, build_env=build_env)
41-
task = UpdateDocsTask(build_env=build_env, python_env=python_env, version=version,
42-
project=project, search=False, localmedia=False)
43+
yaml_config = get_build_config({})
44+
config = ConfigWrapper(version=version, yaml_config=yaml_config)
45+
task = UpdateDocsTask(build_env=build_env, project=project, python_env=python_env,
46+
version=version, search=False, localmedia=False, config=config)
4347
task.build_docs()
4448

4549
# Get command and check first part of command list is a call to sphinx
@@ -61,8 +65,11 @@ def test_build_respects_pdf_flag(self):
6165

6266
build_env = LocalEnvironment(project=project, version=version, build={})
6367
python_env = Virtualenv(version=version, build_env=build_env)
64-
task = UpdateDocsTask(build_env=build_env, python_env=python_env, version=version,
65-
project=project, search=False, localmedia=False)
68+
yaml_config = get_build_config({})
69+
config = ConfigWrapper(version=version, yaml_config=yaml_config)
70+
task = UpdateDocsTask(build_env=build_env, project=project, python_env=python_env,
71+
version=version, search=False, localmedia=False, config=config)
72+
6673
task.build_docs()
6774

6875
# The HTML and the Epub format were built.
@@ -84,8 +91,35 @@ def test_build_respects_epub_flag(self):
8491

8592
build_env = LocalEnvironment(project=project, version=version, build={})
8693
python_env = Virtualenv(version=version, build_env=build_env)
87-
task = UpdateDocsTask(build_env=build_env, python_env=python_env, version=version,
88-
project=project, search=False, localmedia=False)
94+
yaml_config = get_build_config({})
95+
config = ConfigWrapper(version=version, yaml_config=yaml_config)
96+
task = UpdateDocsTask(build_env=build_env, project=project, python_env=python_env,
97+
version=version, search=False, localmedia=False, config=config)
98+
task.build_docs()
99+
100+
# The HTML and the Epub format were built.
101+
self.mocks.html_build.assert_called_once_with()
102+
self.mocks.epub_build.assert_called_once_with()
103+
# PDF however was disabled and therefore not built.
104+
self.assertFalse(self.mocks.pdf_build.called)
105+
106+
def test_build_respects_yaml(self):
107+
'''Test YAML build options'''
108+
project = get(Project,
109+
slug='project-1',
110+
documentation_type='sphinx',
111+
conf_py_file='test_conf.py',
112+
enable_pdf_build=False,
113+
enable_epub_build=False,
114+
versions=[fixture()])
115+
version = project.versions.all()[0]
116+
117+
build_env = LocalEnvironment(project=project, version=version, build={})
118+
python_env = Virtualenv(version=version, build_env=build_env)
119+
yaml_config = get_build_config({'formats': ['epub']})
120+
config = ConfigWrapper(version=version, yaml_config=yaml_config)
121+
task = UpdateDocsTask(build_env=build_env, project=project, python_env=python_env,
122+
version=version, search=False, localmedia=False, config=config)
89123
task.build_docs()
90124

91125
# The HTML and the Epub format were built.
@@ -137,8 +171,10 @@ def test_build_pdf_latex_failures(self):
137171

138172
build_env = LocalEnvironment(project=project, version=version, build={})
139173
python_env = Virtualenv(version=version, build_env=build_env)
174+
yaml_config = get_build_config({})
175+
config = ConfigWrapper(version=version, yaml_config=yaml_config)
140176
task = UpdateDocsTask(build_env=build_env, project=project, python_env=python_env,
141-
version=version, search=False, localmedia=False)
177+
version=version, search=False, localmedia=False, config=config)
142178

143179
# Mock out the separate calls to Popen using an iterable side_effect
144180
returns = [
@@ -177,8 +213,10 @@ def test_build_pdf_latex_not_failure(self):
177213

178214
build_env = LocalEnvironment(project=project, version=version, build={})
179215
python_env = Virtualenv(version=version, build_env=build_env)
216+
yaml_config = get_build_config({})
217+
config = ConfigWrapper(version=version, yaml_config=yaml_config)
180218
task = UpdateDocsTask(build_env=build_env, project=project, python_env=python_env,
181-
version=version, search=False, localmedia=False)
219+
version=version, search=False, localmedia=False, config=config)
182220

183221
# Mock out the separate calls to Popen using an iterable side_effect
184222
returns = [

requirements/pip.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
## Upgraded packages
1+
# Base packages
22
pip==7.1.0
33
virtualenv==13.1.0
44
docutils==0.11
55
Sphinx==1.3.4
66
Pygments==2.0.2
77
mkdocs==0.14.0
8-
8+
readthedocs-build==2.0.2
99
django==1.8.3
1010

1111
git+https://github.com/django-tastypie/django-tastypie.git@1e1aff3dd4dcd21669e9c68bd7681253b286b856#egg=django-tastypie
@@ -72,4 +72,3 @@ nilsimsa==0.3.7
7272
git+https://github.com/alex/django-filter.git#egg=django-filter
7373
git+https://github.com/ericflo/django-pagination.git@e5f669036c#egg=django_pagination-dev
7474
git+https://github.com/alex/django-taggit.git#egg=django_taggit-dev
75-
git+https://github.com/rtfd/readthedocs-build.git@a751769#egg=readthedocs_build

0 commit comments

Comments
 (0)