Skip to content

Commit 587f5ee

Browse files
alexwlchanagjohnson
authored andcommitted
Docstring/PEP 257 fixes for the docs_builder app (#2832)
1 parent a66bd56 commit 587f5ee

File tree

6 files changed

+48
-68
lines changed

6 files changed

+48
-68
lines changed

readthedocs/doc_builder/backends/mkdocs.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@
1717

1818
class BaseMkdocs(BaseBuilder):
1919

20-
"""
21-
Mkdocs builder
22-
"""
20+
"""Mkdocs builder"""
21+
2322
use_theme = True
2423

2524
def __init__(self, *args, **kwargs):
@@ -30,10 +29,7 @@ def __init__(self, *args, **kwargs):
3029
self.root_path = self.version.project.checkout_path(self.version.slug)
3130

3231
def append_conf(self, **kwargs):
33-
"""
34-
Set mkdocs config values
35-
"""
36-
32+
"""Set mkdocs config values"""
3733
# Pull mkdocs config data
3834
try:
3935
user_config = yaml.safe_load(

readthedocs/doc_builder/backends/sphinx.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424

2525
class BaseSphinx(BaseBuilder):
2626

27-
"""
28-
The parent for most sphinx builders.
29-
"""
27+
"""The parent for most sphinx builders."""
3028

3129
def __init__(self, *args, **kwargs):
3230
super(BaseSphinx, self).__init__(*args, **kwargs)
@@ -39,9 +37,7 @@ def __init__(self, *args, **kwargs):
3937
self.old_artifact_path = os.path.join(docs_dir, self.sphinx_build_dir)
4038

4139
def _write_config(self, master_doc='index'):
42-
"""
43-
Create ``conf.py`` if it doesn't exist.
44-
"""
40+
"""Create ``conf.py`` if it doesn't exist."""
4541
docs_dir = self.docs_dir()
4642
conf_template = render_to_string('sphinx/conf.py.conf',
4743
{'project': self.project,
@@ -53,9 +49,7 @@ def _write_config(self, master_doc='index'):
5349
safe_write(conf_file, conf_template)
5450

5551
def append_conf(self, **kwargs):
56-
"""Modify the given ``conf.py`` file from a whitelisted user's project.
57-
"""
58-
52+
"""Modify given ``conf.py`` file from a whitelisted user's project."""
5953
# Pull config data
6054
try:
6155
conf_py_path = self.version.get_conf_py_path()
@@ -242,7 +236,7 @@ def move(self, **kwargs):
242236

243237
class LatexBuildCommand(BuildCommand):
244238

245-
'''Ignore LaTeX exit code if there was file output'''
239+
"""Ignore LaTeX exit code if there was file output"""
246240

247241
def run(self):
248242
super(LatexBuildCommand, self).run()
@@ -254,7 +248,7 @@ def run(self):
254248

255249
class DockerLatexBuildCommand(DockerBuildCommand):
256250

257-
'''Ignore LaTeX exit code if there was file output'''
251+
"""Ignore LaTeX exit code if there was file output"""
258252

259253
def run(self):
260254
super(DockerLatexBuildCommand, self).run()

readthedocs/doc_builder/base.py

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def decorator(*args, **kw):
1919

2020

2121
class BaseBuilder(object):
22+
2223
"""
2324
The Base for all Builders. Defines the API for subclasses.
2425
@@ -41,21 +42,18 @@ def __init__(self, build_env, python_env, force=False):
4142
)
4243

4344
def force(self, **kwargs):
44-
"""
45-
An optional step to force a build even when nothing has changed.
46-
"""
45+
"""An optional step to force a build even when nothing has changed."""
4746
log.info("Forcing a build")
4847
self._force = True
4948

5049
def build(self, id=None, **kwargs):
51-
"""
52-
Do the actual building of the documentation.
53-
"""
50+
"""Do the actual building of the documentation."""
5451
raise NotImplementedError
5552

5653
def move(self, **kwargs):
5754
"""
58-
Move the documentation from it's generated place to its artifact directory.
55+
Move the documentation from where it was generated to
56+
its artifact directory.
5957
"""
6058
if os.path.exists(self.old_artifact_path):
6159
if os.path.exists(self.target):
@@ -66,17 +64,13 @@ def move(self, **kwargs):
6664
log.warning("Not moving docs, because the build dir is unknown.")
6765

6866
def clean(self, **kwargs):
69-
"""
70-
Clean the path where documentation will be built
71-
"""
67+
"""Clean the path where documentation will be built"""
7268
if os.path.exists(self.old_artifact_path):
7369
shutil.rmtree(self.old_artifact_path)
7470
log.info("Removing old artifact path: %s" % self.old_artifact_path)
7571

7672
def docs_dir(self, docs_dir=None, **kwargs):
77-
"""
78-
Handle creating a custom docs_dir if it doesn't exist.
79-
"""
73+
"""Handle creating a custom docs_dir if it doesn't exist."""
8074
checkout_path = self.project.checkout_path(self.version.slug)
8175
if not docs_dir:
8276
for doc_dir_name in ['docs', 'doc', 'Doc', 'book']:
@@ -89,10 +83,7 @@ def docs_dir(self, docs_dir=None, **kwargs):
8983
return docs_dir
9084

9185
def create_index(self, extension='md', **kwargs):
92-
"""
93-
Create an index file if it needs it.
94-
"""
95-
86+
"""Create an index file if it needs it."""
9687
docs_dir = self.docs_dir()
9788

9889
index_filename = os.path.join(docs_dir, 'index.{ext}'.format(ext=extension))
@@ -119,5 +110,5 @@ def create_index(self, extension='md', **kwargs):
119110
return 'index'
120111

121112
def run(self, *args, **kwargs):
122-
'''Proxy run to build environment'''
113+
"""Proxy run to build environment"""
123114
return self.build_env.run(*args, **kwargs)

readthedocs/doc_builder/config.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ def load_yaml_config(version):
126126
This uses the configuration logic from `readthedocs-build`,
127127
which will keep parsing consistent between projects.
128128
"""
129-
130129
checkout_path = version.project.checkout_path(version.slug)
131130
env_config = {}
132131

readthedocs/doc_builder/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
'''Doc build constants'''
1+
"""Doc build constants"""
22

33
import os
44
import re

readthedocs/doc_builder/environments.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
'''
2-
Documentation Builder Environments
3-
'''
1+
"""Documentation Builder Environments"""
42

53
import os
64
import re
@@ -38,7 +36,7 @@
3836

3937
class BuildCommand(BuildCommandResultMixin):
4038

41-
'''Wrap command execution for execution in build environments
39+
"""Wrap command execution for execution in build environments
4240
4341
This wraps subprocess commands with some logic to handle exceptions,
4442
logging, and setting up the env for the build command.
@@ -57,7 +55,7 @@ class BuildCommand(BuildCommandResultMixin):
5755
:param build_env: build environment to use to execute commands
5856
:param bin_path: binary path to add to PATH resolution
5957
:param description: a more grokable description of the command being run
60-
'''
58+
"""
6159

6260
def __init__(self, command, cwd=None, shell=False, environment=None,
6361
combine_output=True, input_data=None, build_env=None,
@@ -94,12 +92,12 @@ def __str__(self):
9492
return '\n'.join([self.get_command(), output])
9593

9694
def run(self):
97-
'''Set up subprocess and execute command
95+
"""Set up subprocess and execute command
9896
9997
:param cmd_input: input to pass to command in STDIN
10098
:type cmd_input: str
10199
:param combine_output: combine STDERR into STDOUT
102-
'''
100+
"""
103101
log.info("Running: '%s' [%s]", self.get_command(), self.cwd)
104102

105103
self.start_time = datetime.utcnow()
@@ -159,14 +157,14 @@ def run(self):
159157
self.end_time = datetime.utcnow()
160158

161159
def get_command(self):
162-
'''Flatten command'''
160+
"""Flatten command"""
163161
if hasattr(self.command, '__iter__') and not isinstance(self.command, str):
164162
return ' '.join(self.command)
165163
else:
166164
return self.command
167165

168166
def save(self):
169-
'''Save this command and result via the API'''
167+
"""Save this command and result via the API"""
170168
data = {
171169
'build': self.build_env.build.get('id'),
172170
'command': self.get_command(),
@@ -181,18 +179,18 @@ def save(self):
181179

182180
class DockerBuildCommand(BuildCommand):
183181

184-
'''Create a docker container and run a command inside the container
182+
"""Create a docker container and run a command inside the container
185183
186184
Build command to execute in docker container
187-
'''
185+
"""
188186

189187
def run(self):
190-
'''Execute command in existing Docker container
188+
"""Execute command in existing Docker container
191189
192190
:param cmd_input: input to pass to command in STDIN
193191
:type cmd_input: str
194192
:param combine_output: combine STDERR into STDOUT
195-
'''
193+
"""
196194
log.info("Running in container %s: '%s' [%s]",
197195
self.build_env.container_id, self.get_command(), self.cwd)
198196

@@ -310,16 +308,16 @@ def handle_exception(self, exc_type, exc_value, _):
310308
return True
311309

312310
def run(self, *cmd, **kwargs):
313-
'''Shortcut to run command from environment'''
311+
"""Shortcut to run command from environment"""
314312
return self.run_command_class(cls=self.command_class, cmd=cmd, **kwargs)
315313

316314
def run_command_class(self, cls, cmd, **kwargs):
317-
'''Run command from this environment
315+
"""Run command from this environment
318316
319317
Use ``cls`` to instantiate a command
320318
321319
:param warn_only: Don't raise an exception on command failure
322-
'''
320+
"""
323321
warn_only = kwargs.pop('warn_only', False)
324322
# Remove PATH from env, and set it to bin_path if it isn't passed in
325323
env_path = self.environment.pop('BIN_PATH', None)
@@ -353,21 +351,21 @@ def run_command_class(self, cls, cmd, **kwargs):
353351

354352
@property
355353
def successful(self):
356-
'''Is build completed, without top level failures or failing commands'''
354+
"""Is build completed, without top level failures or failing commands"""
357355
return (self.done and self.failure is None and
358356
all(cmd.successful for cmd in self.commands))
359357

360358
@property
361359
def failed(self):
362-
'''Is build completed, but has top level failure or failing commands'''
360+
"""Is build completed, but has top level failure or failing commands"""
363361
return (self.done and (
364362
self.failure is not None or
365363
any(cmd.failed for cmd in self.commands)
366364
))
367365

368366
@property
369367
def done(self):
370-
'''Is build in finished state'''
368+
"""Is build in finished state"""
371369
return (self.build is not None and
372370
self.build['state'] == BUILD_STATE_FINISHED)
373371

@@ -429,13 +427,14 @@ def update_build(self, state=None):
429427

430428
class LocalEnvironment(BuildEnvironment):
431429

432-
'''Local execution environment'''
430+
"""Local execution environment"""
431+
433432
command_class = BuildCommand
434433

435434

436435
class DockerEnvironment(BuildEnvironment):
437436

438-
'''
437+
"""
439438
Docker build environment, uses docker to contain builds
440439
441440
If :py:data:`settings.DOCKER_ENABLE` is true, build documentation inside a
@@ -447,7 +446,8 @@ class DockerEnvironment(BuildEnvironment):
447446
data.
448447
449448
:param docker_socket: Override to Docker socket URI
450-
'''
449+
"""
450+
451451
command_class = DockerBuildCommand
452452
container_image = DOCKER_IMAGE
453453
container_mem_limit = DOCKER_LIMITS.get('memory')
@@ -471,7 +471,7 @@ def __init__(self, *args, **kwargs):
471471
self.container_time_limit = self.project.container_time_limit
472472

473473
def __enter__(self):
474-
'''Start of environment context'''
474+
"""Start of environment context"""
475475
log.info('Creating container')
476476
try:
477477
# Test for existing container. We remove any stale containers that
@@ -511,7 +511,7 @@ def __enter__(self):
511511
return self
512512

513513
def __exit__(self, exc_type, exc_value, tb):
514-
'''End of environment context'''
514+
"""End of environment context"""
515515
ret = self.handle_exception(exc_type, exc_value, tb)
516516

517517
# Update buildenv state given any container error states first
@@ -541,7 +541,7 @@ def __exit__(self, exc_type, exc_value, tb):
541541
return ret
542542

543543
def get_client(self):
544-
'''Create Docker client connection'''
544+
"""Create Docker client connection"""
545545
try:
546546
if self.client is None:
547547
self.client = Client(
@@ -561,14 +561,14 @@ def get_client(self):
561561

562562
@property
563563
def container_id(self):
564-
'''Return id of container if it is valid'''
564+
"""Return id of container if it is valid"""
565565
if self.container_name:
566566
return self.container_name
567567
elif self.container:
568568
return self.container.get('Id')
569569

570570
def container_state(self):
571-
'''Get container state'''
571+
"""Get container state"""
572572
client = self.get_client()
573573
try:
574574
info = client.inspect_container(self.container_id)
@@ -577,13 +577,13 @@ def container_state(self):
577577
return None
578578

579579
def update_build_from_container_state(self):
580-
'''Update buildenv state from container state
580+
"""Update buildenv state from container state
581581
582582
In the case of the parent command exiting before the exec commands
583583
finish and the container is destroyed, or in the case of OOM on the
584584
container, set a failure state and error message explaining the failure
585585
on the buildenv.
586-
'''
586+
"""
587587
state = self.container_state()
588588
if state is not None and state.get('Running') is False:
589589
if state.get('ExitCode') == DOCKER_TIMEOUT_EXIT_CODE:
@@ -598,7 +598,7 @@ def update_build_from_container_state(self):
598598
.format(state.get('Error'))))
599599

600600
def create_container(self):
601-
'''Create docker container'''
601+
"""Create docker container"""
602602
client = self.get_client()
603603
image = self.container_image
604604
if self.project.container_image:

0 commit comments

Comments
 (0)