-
Notifications
You must be signed in to change notification settings - Fork 617
added initial version of document generator #140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added initial version of document generator #140
Conversation
|
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. ℹ️ Googlers: Go here for more info. |
|
Reopening to fix CLA |
|
A Googler has manually verified that the CLAs look good. (Googler, please make sure the reason for overriding the CLA status is clearly documented in these comments.) ℹ️ Googlers: Go here for more info. |
|
Overrode the CLA status, submitter used wrong email address in error. |
seanpmorgan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @armando-fandango . Generally looks good but some minor things we need to do in order to integrate it with our pipeline
tools/docs/generate2.py
Outdated
|
|
||
| Requires a local installation of: | ||
| Docs Generator - pip install git+https://github.com/tensorflow/docs | ||
| tensorflow_addons |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the reason there needed to be a local install of tensorflow (in the tensorflow/docs/generate2.py) was because the script used an installed package to generate docs (and didn't require a heavy TF rebuild).
Thats a bit hacky imo and we should integrate doc generation with our bazel build / testing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
something like configure.sh? Sean, note that it's tensorflow-doc, rather than tensorflow package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah we could automate the install/generation with a shell script, but we should be able to build the docs using bazel without the need to pip install the package first (which would require a nightly build that we do not have yet).
See the "note" in this section for the reason why they used a pip install instead of just using the source code: https://www.tensorflow.org/community/contribute/documentation#python
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@seanpmorgan @facaiy : Two questions here:
- Should I still rely on doc s generator in tensorflow_docs .. or that is not an option ?
- Should the docs be generated from installed version of addons or from source code version of addons ? if Source code version then I assume it would always be from master branch, Or do we want to keep docs for multiple versions like in TF API docs you can select previous version and see docs generated for previous versions too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To import docs into tensorflow.org, each "subsite" has a config file that specifies the branch for narrative docs and the branch for API docs.
Typically, narrative docs are set to 'master' since it's easier if browsing the GitHub repo looks close to the site (minus changes from last publish date).
For API docs, we typically publish from a release branch (though it could be a tag). That way you can point to older versions of generated docs in GitHub and the Markdown is still readable. The downside is that you need to bump the (internal) config file whenever you make a release and want to publish it. But we can come up with process for that, or just ping me.
tools/docs/generate2.py
Outdated
| """A tool to generate api_docs for TensorFlow Addons. | ||
|
|
||
| ``` | ||
| Run from root folder of source code |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I believe this will fail if we run as a python file from root. Throws a .so file not found error because they are not built in the repo. We'll need to incorporate this into the bazel BUILD so that docs are generated after the files are compiled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There seems at least two solutions:
- build and install tf_addons in local machine, and then run generate.py manually.
- like build_pip_pkg.sh, we create a shell script which runs generate.py, and write a
sh_binarytarget in bazel BUILD.
pros: automatically compile c++ codes
cons: cannot pass argument, say--output_dir,--code_url_prefix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MarkDaoust Hi, Mark, can you introduce how tensorflow team use generate.py file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes a best practice from docs team would be best.
The third option would be:
3. Run the doc generator from a bazel build command. Which is what was insinuated as possible from the note linked above (i think)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- build and install tf_addons in local machine, and then run generate.py manually.
- Run the doc generator from a bazel build command.
I think either of these work, the generator just wants access to the module as a user would see it.
How you set it up is only a question of whether you want to use bazel to generate your docs or not.
If you don't do anything too out of the ordinary, you may be able to do (1) even if you have the bazel BUILD files setup for (3).
Bazel build and then check in the docs into git repo from there. ... then tensorflow core team would be able to pull them into community docs from there.
Yes, that would be the least-friction path for us. It also gives your users somewhere to read the docs independent of what happens with this tensorflow.org integration.
tools/docs/generate2.py
Outdated
| from tensorflow.python.util import tf_inspect | ||
|
|
||
| # Use tensorflow's `tf_inspect`, which is aware of `tf_decorator`. | ||
| parser.tf_inspect = tf_inspect |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we confirm if this is required? I'm not aware of us using tf_decorator, but it can probably be empirically checked. If we don't need to use this that's great because it's leveraging a private API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sean, it seems that tensorflow_docs cannot recognize those imported modules/function, such as keras_utils, absolute_import etc. Not sure whether that's one reason to use tf_export in tensorflow. cc @lamberta
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will be good to find out a way to link them back to the documentation in TF core.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we confirm if this is required? I'm not aware of us using tf_decorator, but it can probably be empirically checked.
Correct, this line only does anything for you if you're using tf_decorator.
it seems that tensorflow_docs cannot recognize those imported modules/function, such as keras_utils, absolute_import etc. Not sure whether that's one reason to use tf_export in tensorflow.
I'm not sure I understand the question here what is the problem, what are we trying to acomplish?.
I should block the generator from ever mentioning "absolute_import", "division", "print_function".
Note that one of the functions of the base_dir argument is to allow it to filter out objects which are imported by your package, but not part of your package. No docs are generated for objects defined in files outside of base_dir.
tools/docs/generate2.py
Outdated
|
|
||
|
|
||
| def build_docs(output_dir, code_url_prefix, search_hints=True): | ||
| """Build api docs for tensorflow v2. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for tensorflow_addons
tools/docs/generate2.py
Outdated
| "https://github.com/tensorflow/addons/tree/master/tensorflow_addons") | ||
|
|
||
| doc_generator = generate_lib.DocGenerator( | ||
| root_title="TensorFlow Addons 2.0 Preview", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just TensorFlow Addons -- no 2.0 preview
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, yes will fix it.
tools/docs/generate2_test.py
Outdated
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # ============================================================================== | ||
| """Tests for addons.tools.docs.generate2.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll need to integrate this with bazel so this test actually gets ran
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just moved it as it is and fixed it, but if we are generating docs through CI pipeline then we can get rid of this test file completely. What do you think ?
tools/docs/generate2_test.py
Outdated
| import shutil | ||
|
|
||
| import tensorflow as tf | ||
| from tensorflow.python.platform import googletest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this is just used for a temp dir? Could we replace this with something that doesn't use a private API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as per above comment, I believe we can eliminate this test file completely.
tools/docs/generate2.py
Outdated
| code_url_prefixes = ( | ||
| code_url_prefix, | ||
| # External packages source repositories | ||
| "https://github.com/tensorflow/addons/tree/master/tensorflow_addons") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should remove the line, and run the script like: python tools/docs/generate2.py --output_dir=do cs/ --code_url_prefix=https://github.com/tensorflow/addons/tree/master/tensorflow_addons
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code URL prefix would be fixed. What would be the benefit of moving it as an arg?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless you're trying to document multiple installed pacakages you likely want a single string for both base_dir and code_url_prefix.
I think what you want is:
base_dir = path.dirname(tfa.__file__)
code_url_prefix = "https://github.com/tensorflow/addons/tree/master/tensorflow_addons"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Mark, Yan, Sean, will update with these changes in this week.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless you're trying to document multiple installed pacakages you likely want a single string for both
base_dirandcode_url_prefix.I think what you want is:
base_dir = path.dirname(tfa.__file__) code_url_prefix = "https://github.com/tensorflow/addons/tree/master/tensorflow_addons"
For 0.1 version, we should redirect link to r0.1 branch, instead of master branch. That's why I think we need code_url_prefix argument. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@facaiy As I also asked above, do we want to make the doc generator such that it generates docs for all tagged versions in the github repo, like in TF API you can view docs for all previous versions too, or do we want to just keep the docs for latest master branch ?
tools/docs/generate2.py
Outdated
|
|
||
| Requires a local installation of: | ||
| Docs Generator - pip install git+https://github.com/tensorflow/docs | ||
| tensorflow_addons |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
something like configure.sh? Sean, note that it's tensorflow-doc, rather than tensorflow package.
tools/docs/generate2.py
Outdated
| search_hints: Bool. Include meta-data search hints at the top of file. | ||
| """ | ||
| try: | ||
| doc_controls.do_not_generate_docs(tfa.tools) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tfa.utils, rather than tfa.tools?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utils we want to generate documentation of.. right? Just not tools package which only has install and doc generator stuff.
And yes we would need to install tensorflow docs from configure.sh as generate2.py relies on code from that repo.
tools/docs/generate2.py
Outdated
| from tensorflow.python.util import tf_inspect | ||
|
|
||
| # Use tensorflow's `tf_inspect`, which is aware of `tf_decorator`. | ||
| parser.tf_inspect = tf_inspect |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sean, it seems that tensorflow_docs cannot recognize those imported modules/function, such as keras_utils, absolute_import etc. Not sure whether that's one reason to use tf_export in tensorflow. cc @lamberta
MarkDaoust
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LMK if you have any questions, need clarifications, or fixes to the docs tools.
tools/docs/generate2.py
Outdated
| """A tool to generate api_docs for TensorFlow Addons. | ||
|
|
||
| ``` | ||
| Run from root folder of source code |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- build and install tf_addons in local machine, and then run generate.py manually.
- Run the doc generator from a bazel build command.
I think either of these work, the generator just wants access to the module as a user would see it.
How you set it up is only a question of whether you want to use bazel to generate your docs or not.
If you don't do anything too out of the ordinary, you may be able to do (1) even if you have the bazel BUILD files setup for (3).
Bazel build and then check in the docs into git repo from there. ... then tensorflow core team would be able to pull them into community docs from there.
Yes, that would be the least-friction path for us. It also gives your users somewhere to read the docs independent of what happens with this tensorflow.org integration.
tools/docs/generate2.py
Outdated
| parser.tf_inspect = tf_inspect | ||
|
|
||
| # So patch `tfa.__all__` to list everything. | ||
| tfa.__all__ = [item_name for item_name, value in tf_inspect.getmembers(tfa)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is likely not necessary.
The doc generator respects a module's __all__ but will document everything if all is not set. I only added this for tensorflow/tensorflow because there was a miss-match between what was in all and what we wanted to document.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks.. will remove it.
tools/docs/generate2.py
Outdated
| from tensorflow.python.util import tf_inspect | ||
|
|
||
| # Use tensorflow's `tf_inspect`, which is aware of `tf_decorator`. | ||
| parser.tf_inspect = tf_inspect |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we confirm if this is required? I'm not aware of us using tf_decorator, but it can probably be empirically checked.
Correct, this line only does anything for you if you're using tf_decorator.
it seems that tensorflow_docs cannot recognize those imported modules/function, such as keras_utils, absolute_import etc. Not sure whether that's one reason to use tf_export in tensorflow.
I'm not sure I understand the question here what is the problem, what are we trying to acomplish?.
I should block the generator from ever mentioning "absolute_import", "division", "print_function".
Note that one of the functions of the base_dir argument is to allow it to filter out objects which are imported by your package, but not part of your package. No docs are generated for objects defined in files outside of base_dir.
tools/docs/generate2.py
Outdated
|
|
||
| FLAGS = flags.FLAGS | ||
|
|
||
| flags.DEFINE_string( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's safe to just hard code the code_url_prefix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I agree, will do that.
tools/docs/generate2.py
Outdated
| code_url_prefixes = ( | ||
| code_url_prefix, | ||
| # External packages source repositories | ||
| "https://github.com/tensorflow/addons/tree/master/tensorflow_addons") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless you're trying to document multiple installed pacakages you likely want a single string for both base_dir and code_url_prefix.
I think what you want is:
base_dir = path.dirname(tfa.__file__)
code_url_prefix = "https://github.com/tensorflow/addons/tree/master/tensorflow_addons"
|
@seanpmorgan Sean, after discussion with @armando-fandango : 1) We plan to address current comments and then make sure doc generator works nicely from command line; 2) and then someone else, who're familiar enough with bazel, can take over from there in a separate PR for bazel integration. What do you think? |
Sounds great. Thanks everyone for the reviews and iteration |
|
FYI, @MarkDaoust added an example Teams typically keep this in their tools/ directory (or wherever you want), and then it outputs to |
|
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. ℹ️ Googlers: Go here for more info. |
|
closing this and creating a fresh pull request as the API generator is changed. |

Uh oh!
There was an error while loading. Please reload this page.