Merge pull request #1364 from xavieryao/pytorch

Support PyTorch v1.6.0+ doc structure
pull/1366/head
Simon Legner 4 years ago committed by GitHub
commit 35f9c05e42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,15 +1,23 @@
module Docs module Docs
class Pytorch class Pytorch
class EntriesFilter < Docs::EntriesFilter class EntriesFilter < Docs::EntriesFilter
NAME_REPLACEMENTS = {
"Distributed communication package - torch.distributed" => "torch.distributed"
}
def get_breadcrumbs()
css('.pytorch-breadcrumbs > li').map { |node| node.content.delete_suffix(' >') }
end
def get_name def get_name
# The id of the container `div.section` indicates the page type. # The id of the container `div.section` indicates the page type.
# If the id starts with `module-`, then it's an API reference, # If the id starts with `module-`, then it's an API reference,
# otherwise it is a note or design doc. # otherwise it is a note or design doc.
# After the `sphinx/clean_html` filter, that id is assigned to the second element. if at_css('.section')['id'].starts_with? 'module-'
if doc.element_children[1]['id']&.starts_with? 'module-' /\Amodule-(.*)/.match(article_id)[1]
/\Amodule-(.*)/.match(doc.element_children[1]['id'])[1]
else else
at_css('h1').content name = get_breadcrumbs()[1]
NAME_REPLACEMENTS.fetch(name, name)
end end
end end
@ -18,9 +26,8 @@ module Docs
end end
def include_default_entry? def include_default_entry?
# If the page is not an API reference, we only include it in the index when it # Only include API references, and ignore notes or design docs
# contains additional entries. See the doc for `get_name`. !subpath.start_with? 'generated/' and type.start_with? 'torch'
doc.element_children[1]['id']&.starts_with? 'module-'
end end
def additional_entries def additional_entries

@ -9,7 +9,7 @@ module Docs
code: 'https://github.com/pytorch/pytorch' code: 'https://github.com/pytorch/pytorch'
} }
html_filters.push 'pytorch/clean_html', 'sphinx/clean_html', 'pytorch/entries' html_filters.push 'pytorch/entries', 'pytorch/clean_html', 'sphinx/clean_html'
options[:skip] = ['cpp_index.html', 'packages.html', 'py-modindex.html', 'genindex.html'] options[:skip] = ['cpp_index.html', 'packages.html', 'py-modindex.html', 'genindex.html']
options[:skip_patterns] = [/\Acommunity/, /\A_modules/, /\Anotes/, /\Aorg\/pytorch\//] options[:skip_patterns] = [/\Acommunity/, /\A_modules/, /\Anotes/, /\Aorg\/pytorch\//]

Loading…
Cancel
Save