Add some missing docs to torch.rst, new unittest to enforce torch.rst no longer miss anything#16039
Add some missing docs to torch.rst, new unittest to enforce torch.rst no longer miss anything#16039zasdfgbnm wants to merge 9 commits intopytorch:masterfrom
Conversation
|
Hi @zasdfgbnm, I was getting ready to merge your patch, but I realized there might be a better and more way to pull out the list of documented identifiers. Basically, instead of groveling through |
|
@ezyang I just did some experiment, but I still think including only import torch
import ast
import _ast
import re
import matplotlib.pyplot as plt
from matplotlib_venn import venn3
# copied from PR
r1 = re.compile(r'\.\. autofunction:: (\w*)')
everything = set()
filename = '/home/gaoxiang/pytorch/docs/source/torch.rst'
with open(filename, 'r') as f:
lines = f.readlines()
for l in lines:
l = l.strip()
name = r1.findall(l)
if name:
everything.add(name[0])
pypath = '/home/gaoxiang/pytorch/torch/_torch_docs.py'
everything2 = set()
with open(pypath, 'r') as f:
body = ast.parse(f.read()).body
for i in body:
if not isinstance(i, _ast.Expr):
continue
i = i.value
if not isinstance(i, _ast.Call):
continue
if i.func.id != 'add_docstr':
continue
i = i.args[0]
if i.value.id != 'torch':
continue
i = i.attr
everything2.add(i)
for p in dir(torch.functional):
if not p.startswith('_') and p[0].islower():
everything2.add(p)
# all attr in torch with nonempty docstring
alltorch = set(a for a in dir(torch) if getattr(torch, a).__doc__ and not a.startswith('_'))
fig = plt.figure(figsize=(20, 20))
v = venn3(
[alltorch, everything, everything2],
set_labels = ('torch.*', 'torch.rst', '_torch_docs and functional'),
set_colors=('r', 'g', 'b'),
alpha=0.8)
plt.show()
print(len(alltorch))
print(len(everything))
print(len(everything2))
print()
print(alltorch - everything2)The Venn diagram is below, read is The print is: we can see things in torch but not in _torch_docs and functional are mainly internal functions, things documented somewhere else, imported modules and those ops that should be in |
|
I guess the question is what the motivation of this test is.
Still, doing (1) seems like a good step on the way to (2), so we can take this as is. |
…rce-doc-coverage
…nto enforce-doc-coverage
|
@ezyang I just updated the whitelist to add a new symbol |
facebook-github-bot
left a comment
There was a problem hiding this comment.
@ezyang is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
facebook-github-bot
left a comment
There was a problem hiding this comment.
@ezyang has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
… to enforce tensors.rst no longer miss anything (#16057) Summary: This depend on #16039 This prevent people (reviewer, PR author) from forgetting adding things to `tensors.rst`. When something new is added to `_tensor_doc.py` or `tensor.py` but intentionally not in `tensors.rst`, people should manually whitelist it in `test_docs_coverage.py`. Pull Request resolved: #16057 Differential Revision: D14619550 Pulled By: ezyang fbshipit-source-id: e1c6dd6761142e2e48ec499e118df399e3949fcc
… no longer miss anything (pytorch#16039) Summary: This prevent people (reviewer, PR author) from forgetting adding things to `torch.rst`. When something new is added to `_torch_doc.py` or `functional.py` but intentionally not in `torch.rst`, people should manually whitelist it in `test_docs_coverage.py`. Pull Request resolved: pytorch#16039 Differential Revision: D14070903 Pulled By: ezyang fbshipit-source-id: 60f2a42eb5efe81be073ed64e54525d143eb643e
… to enforce tensors.rst no longer miss anything (pytorch#16057) Summary: This depend on pytorch#16039 This prevent people (reviewer, PR author) from forgetting adding things to `tensors.rst`. When something new is added to `_tensor_doc.py` or `tensor.py` but intentionally not in `tensors.rst`, people should manually whitelist it in `test_docs_coverage.py`. Pull Request resolved: pytorch#16057 Differential Revision: D14619550 Pulled By: ezyang fbshipit-source-id: e1c6dd6761142e2e48ec499e118df399e3949fcc

This prevent people (reviewer, PR author) from forgetting adding things to
torch.rst.When something new is added to
_torch_doc.pyorfunctional.pybut intentionally not intorch.rst, people should manually whitelist it intest_docs_coverage.py.