summaryrefslogtreecommitdiff
path: root/sphinx/apidoc.py
diff options
context:
space:
mode:
authorGregory Szorc <gps@mozilla.com>2015-06-02 10:04:02 -0700
committerGregory Szorc <gps@mozilla.com>2015-06-02 10:04:02 -0700
commitad6ba6005946053c2636b2061bfa93e968ecb961 (patch)
tree495759f86400d0f52ae104018cd9bea26349a285 /sphinx/apidoc.py
parentc9aae7210b34289643651e7307c42317d2a22d1e (diff)
downloadsphinx-git-ad6ba6005946053c2636b2061bfa93e968ecb961.tar.gz
Use FileAvoidWrite in apidoc
Previously, sphinx-apidoc would always write files, even if the auto-generated content was identical. This would bump the mtime and cause the file to be re-read and generated on the next build invocation. After this patch, the files are not written unless content has changed. In a contrived example using `sphinx-apidoc` to regenerate documentation for CPython's Lib/ directory, this patch reduced the number of "updated" source files from 257 to 2. Execution time of `sphinx-build` without parallelism decreased from ~12.5s to ~4.5s.
Diffstat (limited to 'sphinx/apidoc.py')
-rw-r--r--sphinx/apidoc.py7
1 files changed, 2 insertions, 5 deletions
diff --git a/sphinx/apidoc.py b/sphinx/apidoc.py
index 10311e6f3..60ec278aa 100644
--- a/sphinx/apidoc.py
+++ b/sphinx/apidoc.py
@@ -21,7 +21,7 @@ import sys
import optparse
from os import path
-from sphinx.util.osutil import walk
+from sphinx.util.osutil import FileAvoidWrite, walk
from sphinx import __display_version__
# automodule options
@@ -61,11 +61,8 @@ def write_file(name, text, opts):
print('File %s already exists, skipping.' % fname)
else:
print('Creating file %s.' % fname)
- f = open(fname, 'w')
- try:
+ with FileAvoidWrite(fname) as f:
f.write(text)
- finally:
- f.close()
def format_heading(level, text):