Skip to content

Commit 0ec96a6

Browse files
facaiyseanpmorgan
authored andcommitted
add bazel command to generate API docs (#206)
* ENH: integrate with bazel * DOC: how to install dependencies * FIX: tf.function and __version__ * DOC: use tfa as short name * DOC: add tutorial in details
1 parent 377edb7 commit 0ec96a6

File tree

7 files changed

+79
-16
lines changed

7 files changed

+79
-16
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,8 @@ wheels/
3535
# Build
3636
/.bazelrc
3737
/bazel-*
38-
/artifacts
38+
/artifacts
39+
40+
# Addons
41+
.*
42+
/docs/

BUILD

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,5 @@ sh_binary(
66
"MANIFEST.in",
77
"setup.py",
88
"//tensorflow_addons",
9-
"//tensorflow_addons/activations",
10-
"//tensorflow_addons/image",
11-
"//tensorflow_addons/layers",
12-
"//tensorflow_addons/losses",
13-
"//tensorflow_addons/optimizers",
14-
"//tensorflow_addons/rnn",
15-
"//tensorflow_addons/seq2seq",
16-
"//tensorflow_addons/text",
179
],
1810
)

tensorflow_addons/BUILD

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,14 @@ py_library(
88
"__init__.py",
99
"version.py",
1010
],
11+
deps = [
12+
"//tensorflow_addons/activations",
13+
"//tensorflow_addons/image",
14+
"//tensorflow_addons/layers",
15+
"//tensorflow_addons/losses",
16+
"//tensorflow_addons/optimizers",
17+
"//tensorflow_addons/rnn",
18+
"//tensorflow_addons/seq2seq",
19+
"//tensorflow_addons/text",
20+
],
1121
)

tools/docs/BUILD

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Description:
2+
# Doc generator
3+
4+
licenses(["notice"]) # Apache 2.0
5+
6+
exports_files(["LICENSE"])
7+
8+
package(
9+
default_visibility = ["//tensorflow_addons:__subpackages__"],
10+
)
11+
12+
py_binary(
13+
name = "build_docs",
14+
srcs = ["build_docs.py"],
15+
srcs_version = "PY2AND3",
16+
deps = [
17+
"//tensorflow_addons",
18+
],
19+
)

tools/docs/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Generate API documents
2+
3+
```bash
4+
# Install dependencies:
5+
pip install -r doc_requirements.txt
6+
7+
# Build tool:
8+
bazel build tools/docs:build_docs
9+
10+
# Generate API doc:
11+
# Use current branch
12+
bazel-bin/tools/docs/build_docs --git_branch=$(git rev-parse --abbrev-ref HEAD)
13+
# or specified explicitly
14+
bazel-bin/tools/docs/build_docs --git_branch=master --output_dir=docs/api_docs/python/
15+
16+
# Release API doc:
17+
git add -f doc/
18+
git commit -m "DOC: xxxxx"
19+
git push
20+
```

tools/docs/build_docs.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
# ==============================================================================
15-
""" Modified from the tfdocs example api reference docs generation script.
15+
"""Modified from the tfdocs example api reference docs generation script.
1616
1717
This script generates API reference docs.
1818
@@ -31,31 +31,47 @@
3131
from absl import app
3232
from absl import flags
3333

34-
import tensorflow_addons
34+
import tensorflow_addons as tfa
35+
3536
from tensorflow_docs.api_generator import generate_lib
37+
from tensorflow_docs.api_generator import parser
3638
from tensorflow_docs.api_generator import public_api
3739

38-
PROJECT_SHORT_NAME = 'tfaddons'
40+
from tensorflow.python.util import tf_inspect
41+
42+
# Use tensorflow's `tf_inspect`, which is aware of `tf_decorator`.
43+
parser.tf_inspect = tf_inspect
44+
45+
PROJECT_SHORT_NAME = 'tfa'
3946
PROJECT_FULL_NAME = 'TensorFlow Addons'
40-
CODE_URL_PREFIX = 'https://github.com/tensorflow/addons/tree/master/tensorflow_addons'
4147

4248
FLAGS = flags.FLAGS
4349

50+
flags.DEFINE_string(
51+
'git_branch',
52+
default='master',
53+
help='The name of the corresponding branch on github.')
54+
4455
flags.DEFINE_string(
4556
'output_dir',
46-
default='/addons/docs/api_docs/python/',
57+
default='docs/api_docs/python/',
4758
help='Where to write the resulting docs to.')
4859

4960

5061
def main(argv):
5162
if argv[1:]:
5263
raise ValueError('Unrecognized arguments: {}'.format(argv[1:]))
5364

65+
code_url_prefix = ('https://github.com/tensorflow/addons/tree/'
66+
'{git_branch}/tensorflow_addons'.format(
67+
git_branch=FLAGS.git_branch))
68+
5469
doc_generator = generate_lib.DocGenerator(
5570
root_title=PROJECT_FULL_NAME,
5671
# Replace `tensorflow_docs` with your module, here.
57-
py_modules=[(PROJECT_SHORT_NAME, tensorflow_addons)],
58-
code_url_prefix=CODE_URL_PREFIX,
72+
py_modules=[(PROJECT_SHORT_NAME, tfa)],
73+
code_url_prefix=code_url_prefix,
74+
private_map={'tfa': ['__version__', 'utils', 'version']},
5975
# This callback cleans up a lot of aliases caused by internal imports.
6076
callbacks=[public_api.local_definitions_filter])
6177

tools/docs/doc_requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
git+https://github.com/tensorflow/docs
2+
pathlib

0 commit comments

Comments
 (0)