Skip to content

Commit 6008276

Browse files
committed
Merge branch 'master' into improve-detail-view
2 parents 3c4c74d + f128166 commit 6008276

File tree

7 files changed

+65
-17
lines changed

7 files changed

+65
-17
lines changed

readthedocs/api/v2/views/model_views.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
BRANCH,
1515
TAG,
1616
INTERNAL,
17+
BUILD_STATE_TRIGGERED,
1718
BUILD_STATE_FINISHED,
1819
)
1920
from readthedocs.builds.models import Build, BuildCommandResult, Version
@@ -291,7 +292,7 @@ def running(self, request, **kwargs):
291292
queryset = (
292293
self.get_queryset()
293294
.filter(project__slug=project_slug)
294-
.exclude(state__in=[BUILD_STATE_FINISHED])
295+
.exclude(state__in=[BUILD_STATE_TRIGGERED, BUILD_STATE_FINISHED])
295296
)
296297
return Response({'count': queryset.count()})
297298

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 2.2.11 on 2020-04-01 20:07
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('builds', '0015_uploading_build_state'),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name='version',
15+
name='documentation_type',
16+
field=models.CharField(choices=[('sphinx', 'Sphinx Html'), ('mkdocs', 'Mkdocs (Markdown)'), ('sphinx_htmldir', 'Sphinx HtmlDir'), ('sphinx_singlehtml', 'Sphinx Single Page HTML'), ('mkdocs_html', 'Mkdocs Html Pages')], default='sphinx', help_text='Type of documentation the version was built with.', max_length=20, verbose_name='Documentation type'),
17+
),
18+
]

readthedocs/builds/models.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,20 @@
6464
from readthedocs.projects.constants import (
6565
BITBUCKET_COMMIT_URL,
6666
BITBUCKET_URL,
67+
DOCTYPE_CHOICES,
6768
GITHUB_BRAND,
6869
GITHUB_COMMIT_URL,
6970
GITHUB_PULL_REQUEST_COMMIT_URL,
7071
GITHUB_PULL_REQUEST_URL,
7172
GITHUB_URL,
7273
GITLAB_BRAND,
7374
GITLAB_COMMIT_URL,
74-
DOCUMENTATION_CHOICES,
7575
GITLAB_MERGE_REQUEST_COMMIT_URL,
7676
GITLAB_MERGE_REQUEST_URL,
7777
GITLAB_URL,
7878
MEDIA_TYPES,
7979
PRIVACY_CHOICES,
80+
SPHINX,
8081
)
8182
from readthedocs.projects.models import APIProject, Project
8283
from readthedocs.projects.version_handling import determine_stable_version
@@ -145,8 +146,8 @@ class Version(models.Model):
145146
documentation_type = models.CharField(
146147
_('Documentation type'),
147148
max_length=20,
148-
choices=DOCUMENTATION_CHOICES,
149-
default='sphinx',
149+
choices=DOCTYPE_CHOICES,
150+
default=SPHINX,
150151
help_text=_(
151152
'Type of documentation the version was built with.'
152153
),

readthedocs/doc_builder/backends/mkdocs.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import yaml
1212
from django.conf import settings
1313
from django.template import loader as template_loader
14+
from readthedocs.projects.constants import MKDOCS_HTML, MKDOCS
1415

1516
from readthedocs.doc_builder.base import BaseBuilder
1617
from readthedocs.doc_builder.exceptions import MkDocsYAMLParseError
@@ -67,6 +68,17 @@ def __init__(self, *args, **kwargs):
6768
else:
6869
self.DEFAULT_THEME_NAME = 'mkdocs'
6970

71+
def get_final_doctype(self):
72+
"""
73+
Select a doctype based on the ``use_directory_urls`` setting.
74+
75+
https://www.mkdocs.org/user-guide/configuration/#use_directory_urls
76+
"""
77+
with open(self.yaml_file, 'r') as f:
78+
config = yaml.safe_load(f)
79+
use_directory_urls = config.get('use_directory_urls', True)
80+
return MKDOCS if use_directory_urls else MKDOCS_HTML
81+
7082
def get_yaml_config(self):
7183
"""Find the ``mkdocs.yml`` file in the project root."""
7284
mkdocs_path = self.config.mkdocs.configuration

readthedocs/doc_builder/base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ def __init__(self, build_env, python_env, force=False):
5151
type_=self.type,
5252
)
5353

54+
def get_final_doctype(self):
55+
"""Some builders may have a different doctype at build time."""
56+
return self.config.doctype
57+
5458
def force(self, **__):
5559
"""An optional step to force a build even when nothing has changed."""
5660
log.info('Forcing a build')

readthedocs/projects/constants.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
31
"""
42
Project constants.
53
@@ -11,13 +9,20 @@
119

1210
from django.utils.translation import ugettext_lazy as _
1311

14-
12+
SPHINX = 'sphinx'
13+
MKDOCS = 'mkdocs'
14+
SPHINX_HTMLDIR = 'sphinx_htmldir'
15+
SPHINX_SINGLEHTML = 'sphinx_singlehtml'
16+
# This type is defined by the users in their mkdocs.yml file.
17+
MKDOCS_HTML = 'mkdocs_html'
1518
DOCUMENTATION_CHOICES = (
16-
('sphinx', _('Sphinx Html')),
17-
('mkdocs', _('Mkdocs (Markdown)')),
18-
('sphinx_htmldir', _('Sphinx HtmlDir')),
19-
('sphinx_singlehtml', _('Sphinx Single Page HTML')),
19+
(SPHINX, _('Sphinx Html')),
20+
(MKDOCS, _('Mkdocs (Markdown)')),
21+
(SPHINX_HTMLDIR, _('Sphinx HtmlDir')),
22+
(SPHINX_SINGLEHTML, _('Sphinx Single Page HTML')),
2023
)
24+
DOCTYPE_CHOICES = DOCUMENTATION_CHOICES + ((MKDOCS_HTML, _('Mkdocs Html Pages')),)
25+
2126

2227
MEDIA_TYPE_HTML = 'html'
2328
MEDIA_TYPE_PDF = 'pdf'

readthedocs/projects/tasks.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@
3434
BUILD_STATE_FINISHED,
3535
BUILD_STATE_INSTALLING,
3636
BUILD_STATE_UPLOADING,
37-
BUILD_STATUS_SUCCESS,
3837
BUILD_STATUS_FAILURE,
38+
BUILD_STATUS_SUCCESS,
39+
EXTERNAL,
3940
LATEST,
4041
LATEST_VERBOSE_NAME,
4142
STABLE_VERBOSE_NAME,
42-
EXTERNAL,
4343
)
4444
from readthedocs.builds.models import APIVersion, Build, Version
4545
from readthedocs.builds.signals import build_complete
@@ -68,7 +68,7 @@
6868
from readthedocs.doc_builder.python_environments import Conda, Virtualenv
6969
from readthedocs.oauth.models import RemoteRepository
7070
from readthedocs.oauth.notifications import GitBuildStatusFailureNotification
71-
from readthedocs.projects.constants import GITHUB_BRAND, GITLAB_BRAND
71+
from readthedocs.projects.constants import GITHUB_BRAND, GITLAB_BRAND, MKDOCS
7272
from readthedocs.projects.models import APIProject, Feature
7373
from readthedocs.search.utils import index_new_files, remove_indexed_files
7474
from readthedocs.sphinx_domains.models import SphinxDomain
@@ -940,7 +940,7 @@ def store_build_artifacts(
940940
version = api_v2.version(self.version.pk)
941941
version.patch({
942942
'built': True,
943-
'documentation_type': self.config.doctype,
943+
'documentation_type': self.get_final_doctype(),
944944
'has_pdf': pdf,
945945
'has_epub': epub,
946946
'has_htmlzip': localmedia,
@@ -1085,7 +1085,7 @@ def update_app_instances(
10851085
version = api_v2.version(self.version.pk)
10861086
version.patch({
10871087
'built': True,
1088-
'documentation_type': self.config.doctype,
1088+
'documentation_type': self.get_final_doctype(),
10891089
'has_pdf': pdf,
10901090
'has_epub': epub,
10911091
'has_htmlzip': localmedia,
@@ -1206,6 +1206,13 @@ def build_docs_html(self):
12061206

12071207
return success
12081208

1209+
def get_final_doctype(self):
1210+
html_builder = get_builder_class(self.config.doctype)(
1211+
build_env=self.build_env,
1212+
python_env=self.python_env,
1213+
)
1214+
return html_builder.get_final_doctype()
1215+
12091216
def build_docs_search(self):
12101217
"""Build search data."""
12111218
# Search is always run in sphinx using the rtd-sphinx-extension.
@@ -1611,7 +1618,7 @@ def warn(self, msg):
16111618

16121619
invdata = intersphinx.fetch_inventory(MockApp(), '', object_file_url)
16131620
for key, value in sorted(invdata.items() or {}):
1614-
domain, _type = key.split(':')
1621+
domain, _type = key.split(':', 1)
16151622
for name, einfo in sorted(value.items()):
16161623
# project, version, url, display_name
16171624
# ('Sphinx', '1.7.9', 'faq.html#epub-faq', 'Epub info')

0 commit comments

Comments
 (0)