History

Merge pull request #1364 from xavieryao/pytorch

Support PyTorch v1.6.0+ doc structure

Simon Legner committed 5 years ago

Commit 35f9c052 parents d790c7a 5afcd782 files · +15 −8Browse files

Showing the changes to lib/docs (2 of 2 files). Show all

Unified · Split

2 files
  1. lib/docs/filters/pytorch/entries.rb +14 −7
  2. lib/docs/scrapers/pytorch.rb +1 −1
lib/docs/filters/pytorch/entries.rb+14−7
@@ -1,15 +1,23 @@
1module Docs1module Docs
2 class Pytorch2 class Pytorch
3 class EntriesFilter < Docs::EntriesFilter3 class EntriesFilter < Docs::EntriesFilter
4 NAME_REPLACEMENTS = {
5 "Distributed communication package - torch.distributed" => "torch.distributed"
6 }
7
8 def get_breadcrumbs()
9 css('.pytorch-breadcrumbs > li').map { |node| node.content.delete_suffix(' >') }
10 end
11
4 def get_name12 def get_name
5 # The id of the container `div.section` indicates the page type.13 # The id of the container `div.section` indicates the page type.
6 # If the id starts with `module-`, then it's an API reference,14 # If the id starts with `module-`, then it's an API reference,
7 # otherwise it is a note or design doc.15 # otherwise it is a note or design doc.
8 # After the `sphinx/clean_html` filter, that id is assigned to the second element.16 if at_css('.section')['id'].starts_with? 'module-'
9 if doc.element_children[1]['id']&.starts_with? 'module-'17 /\Amodule-(.*)/.match(article_id)[1]
10 /\Amodule-(.*)/.match(doc.element_children[1]['id'])[1]
11 else18 else
12 at_css('h1').content19 name = get_breadcrumbs()[1]
20 NAME_REPLACEMENTS.fetch(name, name)
13 end21 end
14 end22 end
15 23
@@ -18,9 +26,8 @@ module Docs · 2 unmodified lines
18 end26 end
19 27
20 def include_default_entry?28 def include_default_entry?
21 # If the page is not an API reference, we only include it in the index when it29 # Only include API references, and ignore notes or design docs
22 # contains additional entries. See the doc for `get_name`.30 !subpath.start_with? 'generated/' and type.start_with? 'torch'
23 doc.element_children[1]['id']&.starts_with? 'module-'
24 end31 end
25 32
26 def additional_entries33 def additional_entries
lib/docs/scrapers/pytorch.rb+1−1
@@ -9,7 +9,7 @@ module Docs · 8 unmodified lines
9 code: 'https://github.com/pytorch/pytorch'9 code: 'https://github.com/pytorch/pytorch'
10 }10 }
11 11
12 html_filters.push 'pytorch/clean_html', 'sphinx/clean_html', 'pytorch/entries'12 html_filters.push 'pytorch/entries', 'pytorch/clean_html', 'sphinx/clean_html'
13 13
14 options[:skip] = ['cpp_index.html', 'packages.html', 'py-modindex.html', 'genindex.html']14 options[:skip] = ['cpp_index.html', 'packages.html', 'py-modindex.html', 'genindex.html']
15 options[:skip_patterns] = [/\Acommunity/, /\A_modules/, /\Anotes/, /\Aorg\/pytorch\//]15 options[:skip_patterns] = [/\Acommunity/, /\A_modules/, /\Anotes/, /\Aorg\/pytorch\//]