History

Merge pull request #1241 from xavieryao/master

Add PyTorch v1.7.0 documentation

Simon Legner committed 5 years ago

Commit 41ab1022 parents b216b4d cc41db87 files · +102 −-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 +32 −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
@@ -626,6 +626,11 @@ credits = [ · 625 unmodified lines
626626 '2001-2020 Python Software Foundation<br>Python is a trademark of the Python Software Foundation.',
627627 'PSFL',
628628 'https://docs.python.org/3/license.html'
629+ ], [
630+ 'PyTorch',
631+ '2019 Torch Contributors',
632+ 'BSD',
633+ 'https://raw.githubusercontent.com/pytorch/pytorch/master/LICENSE'
629634 ], [
630635 'Q',
631636 '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+32−0
@@ -0,0 +1,32 @@
1+module Docs
2+ class Pytorch < UrlScraper
3+ self.name = 'PyTorch'
4+ self.slug = 'pytorch'
5+ self.type = 'sphinx'
6+ self.force_gzip = true
7+ self.links = {
8+ home: 'https://pytorch.org/',
9+ code: 'https://github.com/pytorch/pytorch'
10+ }
11+
12+ html_filters.push 'pytorch/clean_html', 'sphinx/clean_html', 'pytorch/entries'
13+
14+ options[:skip] = ['cpp_index.html', 'packages.html', 'py-modindex.html', 'genindex.html']
15+ options[:skip_patterns] = [/\Acommunity/, /\A_modules/, /\Anotes/, /\Aorg\/pytorch\//]
16+ options[:max_image_size] = 256_000
17+
18+ options[:attribution] = <<-HTML
19+ &copy; 2019 Torch Contributors<br>
20+ Licensed under the 3-clause BSD License.
21+ HTML
22+
23+ version do
24+ self.release = '1.7.0'
25+ self.base_url = "https://pytorch.org/docs/#{release}/"
26+ end
27+
28+ def get_latest_version(opts)
29+ get_latest_github_release('pytorch', 'pytorch', opts)
30+ end
31+ end
32+end
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