Skip to content

Commit bd24f51

Browse files
MarkDaoustcopybara-github
authored andcommitted
Remove old replace-refs code.
PiperOrigin-RevId: 411038136
1 parent 4e3f0f7 commit bd24f51

File tree

2 files changed

+0
-122
lines changed

2 files changed

+0
-122
lines changed

tools/tensorflow_docs/api_generator/generate_lib.py

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"""Generate tensorflow.org style API Reference docs for a Python module."""
1717

1818
import collections
19-
import fnmatch
2019
import importlib
2120
import inspect
2221
import os
@@ -707,65 +706,6 @@ def extract(py_modules,
707706
EXCLUDED = set(['__init__.py', 'OWNERS', 'README.txt'])
708707

709708

710-
def replace_refs(
711-
src_dir: str,
712-
output_dir: str,
713-
reference_resolvers: List[parser.ReferenceResolver],
714-
file_pattern: str = '*.md',
715-
):
716-
"""Link `tf.symbol` references found in files matching `file_pattern`.
717-
718-
A matching directory structure, with the modified files is
719-
written to `output_dir`.
720-
721-
`{"__init__.py","OWNERS","README.txt"}` are skipped.
722-
723-
Files not matching `file_pattern` (using `fnmatch`) are copied with no change.
724-
725-
Also, files in the `api_guides/python` directory get explicit ids set on all
726-
heading-2s to ensure back-links work.
727-
728-
Args:
729-
src_dir: The directory to convert files from.
730-
output_dir: The root directory to write the resulting files to.
731-
reference_resolvers: A list of `parser.ReferenceResolver` to make the
732-
replacements.
733-
file_pattern: Only replace references in files matching file_patters, using
734-
`fnmatch`. Non-matching files are copied unchanged.
735-
"""
736-
737-
# Iterate through all the source files and process them.
738-
for dirpath, _, filenames in os.walk(src_dir):
739-
# Make the directory under output_dir.
740-
new_dir = os.path.join(output_dir,
741-
os.path.relpath(path=dirpath, start=src_dir))
742-
if not os.path.exists(new_dir):
743-
os.makedirs(new_dir)
744-
745-
for base_name in filenames:
746-
if base_name in EXCLUDED:
747-
continue
748-
full_in_path = os.path.join(dirpath, base_name)
749-
750-
suffix = os.path.relpath(path=full_in_path, start=src_dir)
751-
full_out_path = os.path.join(output_dir, suffix)
752-
# Copy files that do not match the file_pattern, unmodified.
753-
if not fnmatch.fnmatch(base_name, file_pattern):
754-
if full_in_path != full_out_path:
755-
shutil.copyfile(full_in_path, full_out_path)
756-
continue
757-
758-
with open(full_in_path, 'rb') as f:
759-
content = f.read().decode('utf-8')
760-
761-
for resolver in reference_resolvers:
762-
# If `rel_path` is an absolute path, `depth` is just discarded.
763-
content = resolver.replace_references(content)
764-
765-
with open(full_out_path, 'wb') as f:
766-
f.write((content + '\n').encode('utf-8'))
767-
768-
769709
class DocGenerator:
770710
"""Main entry point for generating docs."""
771711

tools/tensorflow_docs/api_generator/generate_lib_test.py

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -184,68 +184,6 @@ def test_write(self):
184184
# Make sure that duplicates are not written
185185
self.assertTrue((output_dir / 'tf/TestModule/test_function.md').exists())
186186

187-
def test_replace_refes(self):
188-
test_dir = self.workdir
189-
test_in_dir = os.path.join(test_dir, 'in')
190-
test_in_dir_a = os.path.join(test_dir, 'in/a')
191-
test_in_dir_b = os.path.join(test_dir, 'in/b')
192-
os.makedirs(test_in_dir)
193-
os.makedirs(test_in_dir_a)
194-
os.makedirs(test_in_dir_b)
195-
196-
test_out_dir = os.path.join(test_dir, 'out')
197-
os.makedirs(test_out_dir)
198-
199-
test_path1 = os.path.join(test_in_dir_a, 'file1.md')
200-
test_path2 = os.path.join(test_in_dir_b, 'file2.md')
201-
test_path3 = os.path.join(test_in_dir_b, 'file3.notmd')
202-
test_path4 = os.path.join(test_in_dir_b, 'OWNERS')
203-
204-
with open(test_path1, 'w') as f:
205-
f.write('Use `tf.test_function` to test things.')
206-
207-
with open(test_path2, 'w') as f:
208-
f.write('Use `tf.TestModule.TestClass.ChildClass` to test things.\n'
209-
"`tf.whatever` doesn't exist")
210-
211-
with open(test_path3, 'w') as f:
212-
file3_content = (
213-
'Not a .md file. Should be copied unchanged:'
214-
'`tf.TestModule.TestClass.ChildClass`, `tf.test_function`')
215-
f.write(file3_content)
216-
217-
with open(test_path4, 'w') as f:
218-
f.write('')
219-
220-
reference_resolver, _ = self.get_test_objects()
221-
generate_lib.replace_refs(test_in_dir, test_out_dir, [reference_resolver],
222-
'*.md')
223-
224-
with open(os.path.join(test_out_dir, 'a/file1.md')) as f:
225-
content = f.read()
226-
self.assertEqual(
227-
content,
228-
'Use <a href="api_docs/python/tf/TestModule/test_function.md">'
229-
'<code>tf.test_function</code></a> to test things.\n')
230-
231-
with open(os.path.join(test_out_dir, 'b/file2.md')) as f:
232-
content = f.read()
233-
self.assertEqual(
234-
content, 'Use '
235-
'<a href="api_docs/python/tf/TestModule/TestClass/ChildClass.md">'
236-
'<code>tf.TestModule.TestClass.ChildClass</code></a> '
237-
'to test things.\n'
238-
'`tf.whatever` doesn\'t exist\n')
239-
240-
with open(os.path.join(test_out_dir, 'b/file3.notmd')) as f:
241-
content = f.read()
242-
self.assertEqual(content, file3_content)
243-
244-
with self.assertRaises(IOError):
245-
# This should fail. The OWNERS file should not be copied
246-
with open(os.path.join(test_out_dir, 'b/OWNERS')) as f:
247-
content = f.read()
248-
249187
def _get_test_page_info(self):
250188
page_info = parser.FunctionPageInfo(
251189
full_name='abc', py_object=test_function)

0 commit comments

Comments
 (0)