History

Add PyTorch v1.5.0 documentation

Peiran Yao committed 6 years ago

Commit c0b94261 parent 4eb4bfe7 files · +107 −-2Browse files

Unified · Split

7 files
  1. assets/javascripts/templates/pages/about_tmpl.coffee +5 −0
  2. lib/docs/filters/pytorch/clean_html.rb +12 −0
  3. lib/docs/filters/pytorch/entries.rb +54 −0
  4. lib/docs/scrapers/pytorch.rb +37 −0
  5. public/icons/docs/pytorch/16.png +0 −0
  6. public/icons/docs/pytorch/16@2x.png +0 −0
  7. public/icons/docs/pytorch/SOURCE +1 −0
assets/javascripts/templates/pages/about_tmpl.coffee+5−0
@@ -621,6 +621,11 @@ credits = [ · 620 unmodified lines
621621 '2001-2020 Python Software Foundation<br>Python is a trademark of the Python Software Foundation.',
622622 'PSFL',
623623 'https://docs.python.org/3/license.html'
624+ ], [
625+ 'PyTorch',
626+ '2019 Torch Contributors',
627+ 'BSD',
628+ 'https://raw.githubusercontent.com/pytorch/pytorch/master/LICENSE'
624629 ], [
625630 'Q',
626631 '2009-2017 Kristopher Michael Kowal',
lib/docs/filters/pytorch/clean_html.rb+12−0
@@ -0,0 +1,12 @@
1+module Docs
2+ class Pytorch
3+ class CleanHtmlFilter < Filter
4+ def call
5+ @doc = at_css('.pytorch-article')
6+ # Show katex-mathml nodes and remove katex-html nodes
7+ css('.katex-html').remove
8+ doc
9+ end
10+ end
11+ end
12+end
lib/docs/filters/pytorch/entries.rb+54−0
@@ -0,0 +1,54 @@
1+module Docs
2+ class Pytorch
3+ class EntriesFilter < Docs::EntriesFilter
4+ def get_name
5+ # The id of the container `div.section` indicates the page type.
6+ # If the id starts with `module-`, then it's an API reference,
7+ # 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]
11+ else
12+ at_css('h1').content
13+ end
14+ end
15+
16+ def get_type
17+ name
18+ end
19+
20+ 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-'
24+ end
25+
26+ def additional_entries
27+ return [] if root_page?
28+
29+ entries = []
30+
31+ css('dt').each do |node|
32+ name = node['id']
33+ if name == self.name or name == nil
34+ next
35+ end
36+
37+ case node.parent['class']
38+ when 'method', 'function'
39+ if node.at_css('code').content.starts_with? 'property '
40+ # this instance method is a property, so treat it as an attribute
41+ entries << [name, node['id']]
42+ else
43+ entries << [name + '()', node['id']]
44+ end
45+ when 'class', 'attribute'
46+ entries << [name, node['id']]
47+ end
48+ end
49+
50+ entries
51+ end
52+ end
53+ end
54+end
lib/docs/scrapers/pytorch.rb+37−0
@@ -0,0 +1,37 @@
1+module Docs
2+ class Pytorch < UrlScraper
3+ self.name = 'PyTorch'
4+ self.slug = 'pytorch'
5+ self.type = 'sphinx'
6+ self.release = '1.5.0'
7+ self.base_url = 'https://pytorch.org/docs/stable/'
8+ self.force_gzip = true
9+ self.links = {
10+ home: 'https://pytorch.org/',
11+ code: 'https://github.com/pytorch/pytorch'
12+ }
13+
14+ html_filters.push 'pytorch/clean_html', 'sphinx/clean_html', 'pytorch/entries'
15+
16+ options[:skip] = ['cpp_index.html', 'packages.html', 'py-modindex.html', 'genindex.html']
17+ options[:skip_patterns] = [/\Acommunity/, /\A_modules/, /\Anotes/, /\Aorg\/pytorch\//]
18+ options[:max_image_size] = 256_000
19+
20+ options[:attribution] = <<-HTML
21+ &copy; 2019 Torch Contributors<br>
22+ Licensed under the 3-clause BSD License.<br>
23+ <a href="https://raw.githubusercontent.com/pytorch/pytorch/master/LICENSE" class="_attribution-link">Read the full license.</a>
24+ HTML
25+
26+ def get_latest_version(opts)
27+ doc = fetch_doc('https://pytorch.org/docs/versions.html', opts)
28+ doc.css('li.toctree-l1').each do |node|
29+ match = /v(.+?) \(stable release\)/.match(node.content)
30+ if match
31+ return match[1]
32+ end
33+ end
34+ end
35+ end
36+end
37+
public/icons/docs/pytorch/16.png+0−0

Binary file not shown.

public/icons/docs/pytorch/16@2x.png+0−0

Binary file not shown.

public/icons/docs/pytorch/SOURCE+1−0
@@ -0,0 +1 @@
1+https://pytorch.org/favicon.ico