Skip to content

Commit ba7b03f

Browse files
MarkDaousttensorflower-gardener
authored andcommitted
Install codegen in bazel workspace to allow docs tests to run.
PiperOrigin-RevId: 159477794
1 parent 3b41352 commit ba7b03f

File tree

7 files changed

+114
-29
lines changed

7 files changed

+114
-29
lines changed

tensorflow/tools/docs/BUILD

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ py_library(
3737
srcs = ["parser.py"],
3838
srcs_version = "PY2AND3",
3939
visibility = ["//visibility:public"],
40+
deps = ["@com_github_andreif_codegen"],
4041
)
4142

4243
py_test(
4344
name = "parser_test",
4445
size = "small",
4546
srcs = ["parser_test.py"],
4647
srcs_version = "PY2AND3",
47-
tags = ["manual"],
4848
deps = [
4949
":parser",
5050
"//tensorflow/python:platform_test",
@@ -78,13 +78,10 @@ py_test(
7878
size = "small",
7979
srcs = ["generate_lib_test.py"],
8080
srcs_version = "PY2AND3",
81-
tags = ["manual"],
8281
deps = [
8382
":generate_lib",
8483
":parser",
85-
"//tensorflow:tensorflow_py",
8684
"//tensorflow/python:platform_test",
87-
"//tensorflow/python/debug:debug_py",
8885
],
8986
)
9087

@@ -105,7 +102,6 @@ py_test(
105102
srcs = ["build_docs_test.py"],
106103
data = ["//tensorflow:docs_src"],
107104
srcs_version = "PY2AND3",
108-
tags = ["manual"],
109105
deps = [
110106
":generate_lib",
111107
"//tensorflow:tensorflow_py",

tensorflow/tools/docs/build_docs_test.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
from __future__ import print_function
2020

2121
import os
22+
import sys
23+
import textwrap
2224

2325
import tensorflow as tf
2426
from tensorflow.python import debug as tf_debug
@@ -29,19 +31,40 @@
2931

3032
class Flags(object):
3133
resource_root = resource_loader.get_root_dir_with_all_resources()
32-
src_dir = os.path.join(resource_root, 'third_party/tensorflow/docs_src')
33-
base_dir = os.path.join(resource_root, 'third_party/tensorflow/')
34+
src_dir = os.path.join(resource_root, 'tensorflow/docs_src')
35+
base_dir = os.path.join(resource_root, 'tensorflow/')
3436
output_dir = googletest.GetTempDir()
3537

3638

3739
class BuildDocsTest(googletest.TestCase):
3840

3941
def testBuildDocs(self):
42+
if sys.version_info >= (3, 0):
43+
print('Warning: Doc generation is not supported from python3.')
44+
return
45+
4046
doc_generator = generate_lib.DocGenerator()
4147

4248
doc_generator.set_py_modules([('tf', tf), ('tfdbg', tf_debug)])
4349

44-
status = doc_generator.build(Flags())
50+
try:
51+
status = doc_generator.build(Flags())
52+
except RuntimeError as e:
53+
if not e.args[0].startswith('Modules nested too deep'):
54+
raise
55+
56+
msg = textwrap.dedent("""\
57+
%s
58+
59+
****************************************************************
60+
If this test fails here, you have most likely introduced an
61+
unsealed module. Make sure to use `remove_undocumented` or similar
62+
utilities to avoid leaking symbols. See above for more information
63+
on the exact point of failure.
64+
****************************************************************
65+
""" % e.args[0])
66+
67+
raise RuntimeError(msg)
4568

4669
if status:
4770
self.fail('Found %s Errors!' % status)

tensorflow/tools/docs/generate_lib.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import argparse
2222
import os
23+
import sys
2324

2425
import six
2526

@@ -415,6 +416,8 @@ class DocGenerator(object):
415416
"""Main entry point for generating docs."""
416417

417418
def __init__(self):
419+
if sys.version_info >= (3, 0):
420+
print('Warning: Doc generation is not supported from python3.')
418421
self.argument_parser = argparse.ArgumentParser()
419422
self._py_modules = None
420423
self._private_map = _get_default_private_map()

tensorflow/tools/docs/generate_lib_test.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121
import os
2222
import sys
2323

24-
import tensorflow as tf
25-
26-
from tensorflow.python import debug as tf_debug
2724
from tensorflow.python.platform import googletest
2825
from tensorflow.tools.docs import generate_lib
2926
from tensorflow.tools.docs import parser
@@ -54,22 +51,6 @@ def __init__(self, index, duplicate_of):
5451

5552
class GenerateTest(googletest.TestCase):
5653

57-
def test_extraction(self):
58-
py_modules = [('tf', tf), ('tfdbg', tf_debug)]
59-
60-
try:
61-
generate_lib.extract(py_modules,
62-
generate_lib._get_default_private_map(),
63-
generate_lib._get_default_do_not_descend_map())
64-
except RuntimeError:
65-
print('*****************************************************************')
66-
print('If this test fails, you have most likely introduced an unsealed')
67-
print('module. Make sure to use remove_undocumented or similar utilities')
68-
print('to avoid leaking symbols. See below for more information on the')
69-
print('failure.')
70-
print('*****************************************************************')
71-
raise
72-
7354
def test_write(self):
7455
module = sys.modules[__name__]
7556

tensorflow/tools/docs/parser_test.py

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,13 +491,13 @@ def testSaveReferenceResolver(self):
491491

492492
class TestParseFunctionDetails(googletest.TestCase):
493493

494-
def testParseFunctionDetails(self):
494+
def test_parse_function_details(self):
495495
docstring, function_details = parser._parse_function_details(RELU_DOC)
496496

497497
self.assertEqual(len(function_details), 2)
498498
args = function_details[0]
499499
self.assertEqual(args.keyword, 'Args')
500-
self.assertEmpty(args.header)
500+
self.assertEqual(len(args.header), 0)
501501
self.assertEqual(len(args.items), 2)
502502
self.assertEqual(args.items[0][0], 'features')
503503
self.assertEqual(args.items[1][0], 'name')
@@ -515,5 +515,60 @@ def testParseFunctionDetails(self):
515515
docstring + ''.join(str(detail) for detail in function_details))
516516

517517

518+
class TestGenerateSignature(googletest.TestCase):
519+
520+
def test_known_object(self):
521+
if sys.version_info >= (3, 0):
522+
print('Warning: Doc generation is not supported from python3.')
523+
return
524+
525+
known_object = object()
526+
reverse_index = {id(known_object): 'location.of.object.in.api'}
527+
528+
def example_fun(arg=known_object): # pylint: disable=unused-argument
529+
pass
530+
531+
sig = parser._generate_signature(example_fun, reverse_index)
532+
self.assertEqual(sig, ['arg=location.of.object.in.api'])
533+
534+
def test_literals(self):
535+
if sys.version_info >= (3, 0):
536+
print('Warning: Doc generation is not supported from python3.')
537+
return
538+
539+
def example_fun(a=5, b=5.0, c=None, d=True, e='hello', f=(1, (2, 3))): # pylint: disable=g-bad-name, unused-argument
540+
pass
541+
542+
sig = parser._generate_signature(example_fun, reverse_index={})
543+
self.assertEqual(
544+
sig, ['a=5', 'b=5.0', 'c=None', 'd=True', "e='hello'", 'f=(1, (2, 3))'])
545+
546+
def test_dotted_name(self):
547+
if sys.version_info >= (3, 0):
548+
print('Warning: Doc generation is not supported from python3.')
549+
return
550+
551+
# pylint: disable=g-bad-name
552+
class a(object):
553+
554+
class b(object):
555+
556+
class c(object):
557+
558+
class d(object):
559+
560+
def __init__(self, *args):
561+
pass
562+
# pylint: enable=g-bad-name
563+
564+
e = {'f': 1}
565+
566+
def example_fun(arg1=a.b.c.d, arg2=a.b.c.d(1, 2), arg3=e['f']): # pylint: disable=unused-argument
567+
pass
568+
569+
sig = parser._generate_signature(example_fun, reverse_index={})
570+
self.assertEqual(sig, ['arg1=a.b.c.d', 'arg2=a.b.c.d(1, 2)', "arg3=e['f']"])
571+
572+
518573
if __name__ == '__main__':
519574
googletest.main()

tensorflow/workspace.bzl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,17 @@ def tf_workspace(path_prefix="", tf_repo_name=""):
297297
build_file = str(Label("//third_party:backports_weakref.BUILD")),
298298
)
299299

300+
native.new_http_archive(
301+
name = "com_github_andreif_codegen",
302+
urls = [
303+
"http://mirror.bazel.build/github.com/andreif/codegen/archive/1.0.tar.gz",
304+
"https://github.com/andreif/codegen/archive/1.0.tar.gz",
305+
],
306+
sha256 = "2dadd04a2802de27e0fe5a19b76538f6da9d39ff244036afa00c1bba754de5ee",
307+
strip_prefix = "codegen-1.0",
308+
build_file = str(Label("//third_party:codegen.BUILD")),
309+
)
310+
300311
filegroup_external(
301312
name = "org_python_license",
302313
licenses = ["notice"], # Python 2.0

third_party/codegen.BUILD

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# -*- mode: python; -*-
2+
#
3+
# Description:
4+
# Extension to ast that allow ast -> python code generation.
5+
6+
package(default_visibility = ["//visibility:public"])
7+
8+
licenses(["notice"]) # New BSD
9+
10+
exports_files(["LICENSE"])
11+
12+
py_library(
13+
name = "com_github_andreif_codegen",
14+
srcs = glob(["codegen.py"]),
15+
srcs_version = "PY2AND3",
16+
)

0 commit comments

Comments
 (0)