Skip to content

Commit 2b76dc9

Browse files
committed
Add automatic documentation type choosing
1 parent a66b11e commit 2b76dc9

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

readthedocs/projects/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
THEME_HAIKU = 'haiku'
1616

1717
DOCUMENTATION_CHOICES = (
18+
('auto', _('Automatically Choose')),
1819
('sphinx', _('Sphinx Html')),
1920
('mkdocs', _('Mkdocs (Markdown)')),
2021
('sphinx_htmldir', _('Sphinx HtmlDir')),

readthedocs/projects/tasks.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ def update_docs(pk, version_pk=None, build_pk=None, record=True, docker=False,
7878
if vcs_results:
7979
results.update(vcs_results)
8080

81+
if project.documentation_type == 'auto':
82+
update_documentation_type(version, api)
83+
8184
if docker or settings.DOCKER_ENABLE:
8285
record_build(api=api, build=build, record=record, results=results, state='building')
8386
docker = DockerEnvironment(version)
@@ -139,6 +142,28 @@ def ensure_version(api, project, version_pk):
139142
return version
140143

141144

145+
def update_documentation_type(version, api):
146+
"""
147+
Automatically determine the doc type for a user.
148+
"""
149+
150+
checkout_path = version.project.checkout_path(version.slug)
151+
os.chdir(checkout_path)
152+
files = run('find .')[1].split('\n')
153+
markdown = sphinx = 0
154+
for filename in files:
155+
if fnmatch.fnmatch(filename, '*.md') or fnmatch.fnmatch(filename, '*.markdown'):
156+
markdown += 1
157+
elif fnmatch.fnmatch(filename, '*.rst'):
158+
sphinx += 1
159+
ret = 'sphinx'
160+
if markdown > sphinx:
161+
ret = 'mkdocs'
162+
project_data = api.project(version.project.pk).get()
163+
project_data['documentation_type'] = ret
164+
api.project(version.project.pk).put(project_data)
165+
version.project.documentation_type = ret
166+
142167
def docker_build(version, pdf=True, man=True, epub=True, dash=True,
143168
search=True, force=False, intersphinx=True, localmedia=True):
144169
"""

0 commit comments

Comments
 (0)