aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/tools/docs
diff options
context:
space:
mode:
authorGravatar Mark Daoust <markdaoust@google.com>2018-09-17 15:27:59 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-09-17 15:31:52 -0700
commit3ec29c57b728f5f3b8f80e84f3189f70f86536ea (patch)
tree84f8f35bdefdef944e403713c08beb9299ea5235 /tensorflow/tools/docs
parent77a1883c9dde50efdf9505528adf636ed991e431 (diff)
Add api_docs_relpath option.
Eliminate error when copying a file to itself. PiperOrigin-RevId: 213349424
Diffstat (limited to 'tensorflow/tools/docs')
-rw-r--r--tensorflow/tools/docs/BUILD3
-rw-r--r--tensorflow/tools/docs/generate_lib.py14
2 files changed, 12 insertions, 5 deletions
diff --git a/tensorflow/tools/docs/BUILD b/tensorflow/tools/docs/BUILD
index 4f7efe193f..b218e900bf 100644
--- a/tensorflow/tools/docs/BUILD
+++ b/tensorflow/tools/docs/BUILD
@@ -91,9 +91,10 @@ py_binary(
":parser",
":pretty_docs",
":py_guide_parser",
- "//tensorflow/contrib/ffmpeg:ffmpeg_ops_py",
+ "//tensorflow/python:util",
"//tensorflow/tools/common:public_api",
"//tensorflow/tools/common:traverse",
+ "@six_archive//:six",
],
)
diff --git a/tensorflow/tools/docs/generate_lib.py b/tensorflow/tools/docs/generate_lib.py
index 1cd9cb7ca9..77a3ca2052 100644
--- a/tensorflow/tools/docs/generate_lib.py
+++ b/tensorflow/tools/docs/generate_lib.py
@@ -453,7 +453,11 @@ def update_id_tags_inplace(src_dir):
EXCLUDED = set(['__init__.py', 'OWNERS', 'README.txt'])
-def replace_refs(src_dir, output_dir, reference_resolver, file_pattern='*.md'):
+def replace_refs(src_dir,
+ output_dir,
+ reference_resolver,
+ file_pattern='*.md',
+ api_docs_relpath='api_docs'):
"""Fix @{} references in all files under `src_dir` matching `file_pattern`.
A matching directory structure, with the modified files is
@@ -472,12 +476,13 @@ def replace_refs(src_dir, output_dir, reference_resolver, file_pattern='*.md'):
reference_resolver: A `parser.ReferenceResolver` to make the replacements.
file_pattern: Only replace references in files matching file_patters,
using fnmatch. Non-matching files are copied unchanged.
+ api_docs_relpath: Relative-path string to the api_docs, from the src_dir.
"""
# Iterate through all the source files and process them.
for dirpath, _, filenames in os.walk(src_dir):
+ depth = os.path.relpath(src_dir, start=dirpath)
# How to get from `dirpath` to api_docs/python/
- relative_path_to_root = os.path.relpath(
- path=os.path.join(src_dir, 'api_docs/python'), start=dirpath)
+ relative_path_to_root = os.path.join(depth, api_docs_relpath, 'python')
# Make the directory under output_dir.
new_dir = os.path.join(output_dir,
@@ -497,7 +502,8 @@ def replace_refs(src_dir, output_dir, reference_resolver, file_pattern='*.md'):
full_out_path = os.path.join(output_dir, suffix)
# Copy files that do not match the file_pattern, unmodified.
if not fnmatch.fnmatch(base_name, file_pattern):
- shutil.copyfile(full_in_path, full_out_path)
+ if full_in_path != full_out_path:
+ shutil.copyfile(full_in_path, full_out_path)
continue
with open(full_in_path, 'rb') as f: