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 @@
11 module Docs
22 class Pytorch
33 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+
412 def get_name
513 # The id of the container `div.section` indicates the page type.
614 # If the id starts with `module-`, then it's an API reference,
715 # otherwise it is a note or design doc.
8− # After the `sphinx/clean_html` filter, that id is assigned to the second element.
9− if doc.element_children[1]['id']&.starts_with? 'module-'
10− /\Amodule-(.*)/.match(doc.element_children[1]['id'])[1]
16+ if at_css('.section')['id'].starts_with? 'module-'
17+ /\Amodule-(.*)/.match(article_id)[1]
1118 else
12− at_css('h1').content
19+ name = get_breadcrumbs()[1]
20+ NAME_REPLACEMENTS.fetch(name, name)
1321 end
1422 end
1523
@@ -18,9 +26,8 @@ module Docs · 2 unmodified lines
1826 end
1927
2028 def include_default_entry?
21− # If the page is not an API reference, we only include it in the index when it
22− # contains additional entries. See the doc for `get_name`.
23− doc.element_children[1]['id']&.starts_with? 'module-'
29+ # Only include API references, and ignore notes or design docs
30+ !subpath.start_with? 'generated/' and type.start_with? 'torch'
2431 end
2532
2633 def additional_entries
lib/docs/scrapers/pytorch.rb+1−1
@@ -9,7 +9,7 @@ module Docs · 8 unmodified lines
99 code: 'https://github.com/pytorch/pytorch'
1010 }
1111
12− html_filters.push 'pytorch/clean_html', 'sphinx/clean_html', 'pytorch/entries'
12+ html_filters.push 'pytorch/entries', 'pytorch/clean_html', 'sphinx/clean_html'
1313
1414 options[:skip] = ['cpp_index.html', 'packages.html', 'py-modindex.html', 'genindex.html']
1515 options[:skip_patterns] = [/\Acommunity/, /\A_modules/, /\Anotes/, /\Aorg\/pytorch\//]