Skip to content

Commit 3de48a0

Browse files
authored
Merge pull request #3447 from stsewd/better-autogen-index
Better autogenerated index file
2 parents fe79c92 + 1783311 commit 3de48a0

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

readthedocs/doc_builder/base.py

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
# -*- coding: utf-8 -*-
12
"""Base classes for Builders."""
23

3-
from __future__ import absolute_import
4-
from builtins import object
5-
from functools import wraps
6-
import os
4+
from __future__ import (
5+
absolute_import, division, print_function, unicode_literals)
6+
77
import logging
8+
import os
89
import shutil
10+
from builtins import object
11+
from functools import wraps
912

1013
log = logging.getLogger(__name__)
1114

@@ -19,6 +22,7 @@ def decorator(*args, **kw):
1922
return fn(*args, **kw)
2023
finally:
2124
os.chdir(path)
25+
2226
return decorator
2327

2428

@@ -27,11 +31,12 @@ class BaseBuilder(object):
2731
"""
2832
The Base for all Builders. Defines the API for subclasses.
2933
30-
Expects subclasses to define ``old_artifact_path``,
31-
which points at the directory where artifacts should be copied from.
34+
Expects subclasses to define ``old_artifact_path``, which points at the
35+
directory where artifacts should be copied from.
3236
"""
3337

3438
_force = False
39+
3540
# old_artifact_path = ..
3641

3742
def __init__(self, build_env, python_env, force=False):
@@ -41,13 +46,11 @@ def __init__(self, build_env, python_env, force=False):
4146
self.project = build_env.project
4247
self._force = force
4348
self.target = self.project.artifact_path(
44-
version=self.version.slug,
45-
type_=self.type
46-
)
49+
version=self.version.slug, type_=self.type)
4750

4851
def force(self, **__):
4952
"""An optional step to force a build even when nothing has changed."""
50-
log.info("Forcing a build")
53+
log.info('Forcing a build')
5154
self._force = True
5255

5356
def build(self):
@@ -59,16 +62,16 @@ def move(self, **__):
5962
if os.path.exists(self.old_artifact_path):
6063
if os.path.exists(self.target):
6164
shutil.rmtree(self.target)
62-
log.info("Copying %s on the local filesystem", self.type)
65+
log.info('Copying %s on the local filesystem', self.type)
6366
shutil.copytree(self.old_artifact_path, self.target)
6467
else:
65-
log.warning("Not moving docs, because the build dir is unknown.")
68+
log.warning('Not moving docs, because the build dir is unknown.')
6669

6770
def clean(self, **__):
68-
"""Clean the path where documentation will be built"""
71+
"""Clean the path where documentation will be built."""
6972
if os.path.exists(self.old_artifact_path):
7073
shutil.rmtree(self.old_artifact_path)
71-
log.info("Removing old artifact path: %s", self.old_artifact_path)
74+
log.info('Removing old artifact path: %s', self.old_artifact_path)
7275

7376
def docs_dir(self, docs_dir=None, **__):
7477
"""Handle creating a custom docs_dir if it doesn't exist."""
@@ -87,9 +90,11 @@ def create_index(self, extension='md', **__):
8790
"""Create an index file if it needs it."""
8891
docs_dir = self.docs_dir()
8992

90-
index_filename = os.path.join(docs_dir, 'index.{ext}'.format(ext=extension))
93+
index_filename = os.path.join(
94+
docs_dir, 'index.{ext}'.format(ext=extension))
9195
if not os.path.exists(index_filename):
92-
readme_filename = os.path.join(docs_dir, 'README.{ext}'.format(ext=extension))
96+
readme_filename = os.path.join(
97+
docs_dir, 'README.{ext}'.format(ext=extension))
9398
if os.path.exists(readme_filename):
9499
return 'README'
95100
else:
@@ -101,15 +106,19 @@ def create_index(self, extension='md', **__):
101106
102107
This is an autogenerated index file.
103108
104-
Please create a ``{dir}/index.{ext}`` or ``{dir}/README.{ext}`` file with your own content.
109+
Please create an ``index.{ext}`` or ``README.{ext}`` file with your own content
110+
under the root (or ``/docs``) directory in your repository.
105111
106112
If you want to use another markup, choose a different builder in your settings.
113+
Check out our `Getting Started Guide
114+
<https://docs.readthedocs.io/en/latest/getting_started.html>`_ to become more
115+
familiar with Read the Docs.
107116
"""
108117

109118
index_file.write(index_text.format(dir=docs_dir, ext=extension))
110119
index_file.close()
111120
return 'index'
112121

113122
def run(self, *args, **kwargs):
114-
"""Proxy run to build environment"""
123+
"""Proxy run to build environment."""
115124
return self.build_env.run(*args, **kwargs)

0 commit comments

Comments
 (0)