From c0b94262bfda228fa307723c1deecac9a89771ca Mon Sep 17 00:00:00 2001 From: Peiran Yao Date: Sun, 31 May 2020 16:45:44 -0600 Subject: [PATCH] Add PyTorch v1.5.0 documentation --- .../templates/pages/about_tmpl.coffee | 5 ++ lib/docs/filters/pytorch/clean_html.rb | 12 ++++ lib/docs/filters/pytorch/entries.rb | 54 ++++++++++++++++++ lib/docs/scrapers/pytorch.rb | 37 ++++++++++++ public/icons/docs/pytorch/16.png | Bin 0 -> 1526 bytes public/icons/docs/pytorch/16@2x.png | Bin 0 -> 2302 bytes public/icons/docs/pytorch/SOURCE | 1 + 7 files changed, 109 insertions(+) create mode 100644 lib/docs/filters/pytorch/clean_html.rb create mode 100644 lib/docs/filters/pytorch/entries.rb create mode 100644 lib/docs/scrapers/pytorch.rb create mode 100644 public/icons/docs/pytorch/16.png create mode 100644 public/icons/docs/pytorch/16@2x.png create mode 100644 public/icons/docs/pytorch/SOURCE diff --git a/assets/javascripts/templates/pages/about_tmpl.coffee b/assets/javascripts/templates/pages/about_tmpl.coffee index 8ac93ed4..5fda9667 100644 --- a/assets/javascripts/templates/pages/about_tmpl.coffee +++ b/assets/javascripts/templates/pages/about_tmpl.coffee @@ -621,6 +621,11 @@ credits = [ '2001-2020 Python Software Foundation
Python is a trademark of the Python Software Foundation.', 'PSFL', 'https://docs.python.org/3/license.html' + ], [ + 'PyTorch', + '2019 Torch Contributors', + 'BSD', + 'https://raw.githubusercontent.com/pytorch/pytorch/master/LICENSE' ], [ 'Q', '2009-2017 Kristopher Michael Kowal', diff --git a/lib/docs/filters/pytorch/clean_html.rb b/lib/docs/filters/pytorch/clean_html.rb new file mode 100644 index 00000000..dd19c3e0 --- /dev/null +++ b/lib/docs/filters/pytorch/clean_html.rb @@ -0,0 +1,12 @@ +module Docs + class Pytorch + class CleanHtmlFilter < Filter + def call + @doc = at_css('.pytorch-article') + # Show katex-mathml nodes and remove katex-html nodes + css('.katex-html').remove + doc + end + end + end +end diff --git a/lib/docs/filters/pytorch/entries.rb b/lib/docs/filters/pytorch/entries.rb new file mode 100644 index 00000000..f63926b4 --- /dev/null +++ b/lib/docs/filters/pytorch/entries.rb @@ -0,0 +1,54 @@ +module Docs + class Pytorch + class EntriesFilter < Docs::EntriesFilter + def get_name + # The id of the container `div.section` indicates the page type. + # If the id starts with `module-`, then it's an API reference, + # otherwise it is a note or design doc. + # After the `sphinx/clean_html` filter, that id is assigned to the second element. + if doc.element_children[1]['id']&.starts_with? 'module-' + /\Amodule-(.*)/.match(doc.element_children[1]['id'])[1] + else + at_css('h1').content + end + end + + def get_type + name + end + + def include_default_entry? + # If the page is not an API reference, we only include it in the index when it + # contains additional entries. See the doc for `get_name`. + doc.element_children[1]['id']&.starts_with? 'module-' + end + + def additional_entries + return [] if root_page? + + entries = [] + + css('dt').each do |node| + name = node['id'] + if name == self.name or name == nil + next + end + + case node.parent['class'] + when 'method', 'function' + if node.at_css('code').content.starts_with? 'property ' + # this instance method is a property, so treat it as an attribute + entries << [name, node['id']] + else + entries << [name + '()', node['id']] + end + when 'class', 'attribute' + entries << [name, node['id']] + end + end + + entries + end + end + end +end diff --git a/lib/docs/scrapers/pytorch.rb b/lib/docs/scrapers/pytorch.rb new file mode 100644 index 00000000..4245981b --- /dev/null +++ b/lib/docs/scrapers/pytorch.rb @@ -0,0 +1,37 @@ +module Docs + class Pytorch < UrlScraper + self.name = 'PyTorch' + self.slug = 'pytorch' + self.type = 'sphinx' + self.release = '1.5.0' + self.base_url = 'https://pytorch.org/docs/stable/' + self.force_gzip = true + self.links = { + home: 'https://pytorch.org/', + code: 'https://github.com/pytorch/pytorch' + } + + html_filters.push 'pytorch/clean_html', 'sphinx/clean_html', 'pytorch/entries' + + options[:skip] = ['cpp_index.html', 'packages.html', 'py-modindex.html', 'genindex.html'] + options[:skip_patterns] = [/\Acommunity/, /\A_modules/, /\Anotes/, /\Aorg\/pytorch\//] + options[:max_image_size] = 256_000 + + options[:attribution] = <<-HTML + © 2019 Torch Contributors
+ Licensed under the 3-clause BSD License.
+ Read the full license. + HTML + + def get_latest_version(opts) + doc = fetch_doc('https://pytorch.org/docs/versions.html', opts) + doc.css('li.toctree-l1').each do |node| + match = /v(.+?) \(stable release\)/.match(node.content) + if match + return match[1] + end + end + end + end +end + \ No newline at end of file diff --git a/public/icons/docs/pytorch/16.png b/public/icons/docs/pytorch/16.png new file mode 100644 index 0000000000000000000000000000000000000000..a0104d598307f1c7be364e7e38897a4dd9f9a485 GIT binary patch literal 1526 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Ea{HEjtmSN`?>!lvI6-E$sR$z z3=CCj3=9n|3=F@3LJcn%7)lKo7+xhXFj&oCU=S~uvn$XBC{d9b;hE;^%b*2hb1<+n z3NbJPS&Tr)z$nE4G7ZRL@M4sPvx68lplX;H7}_%#SfFa6fHVkzXpkNV&9s0Cu0mh| zGlC6Lx?C?$5=e0tctjQh{dXON8J#p{S1>RzrDcXhltlRYSS9D@>LsS+C#C9DzCHb_`sNdc^+B->Ug!Z$#{Ilm}X!Bo#g&p^qJ zOF==wrYI%ND#*nRsvXF)RmvzSDX`MlFE20GD>v55FG|-pw6wI;H!#vSGSUUA&@Haa zD@m--%_~-h7y>iLCAB!YD6^m>Ge1uOWNu6-)hW1yPnN%GX@eWPMYhhK z?K-uV)q2y|7sxbhNh+(E$L{&+XNOy6d||&>U&q*Su6ALYi!CZBz15x*-(=J1S3OePmE zYIX)PJw2?tT7;^w|GU2rdla|2?|h-i zafL}*W?w~*`u?audqL};@k|ar`&^tnHmR+OmJyriz^<-7V@cmdzWsJF$p?2U{pZo~ zzJ2k+cE1y!XTFWpzNMMPKWmQfS09V}8+Xbu?_QW@o;}UUu4-dY{+(A<*6|1UPT57* zw)eH%>UR2{F!ggqN={zhbcUHnZtTxp{F|YD<%0X>0c$HSJH6S#cI2tUq?QlAtrXwR zKD$g-(@OZ&&C{G4x>JNz?2Dc=KV18@eV5z2t%6k|>1#|QV`C0JF-z>&!M8+nQ76lw(84A*W#sY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c2NYPX^8Ni1wk)u ze=T+Bql)Yzr@gKII$+bm?0FIJMByOD(Aq1!9(F@WdL#I6E|fI%J~9_VjK#iX?8qU! z?@`~zJ^%b-|rHhPIENp#T^Xros^ zZ&`wdNXzM=?wpJ5G#uxeF24FJWe3WQQ|e2eO35=pl0Hy)|B7U8s;0g772o5RW})Nat7?Yc8dSz%)YFO5fYU zr1{Jfz4XlY#GmH@5=FXcZ=;~85S(hgk)e#Ev z20g9{*wv-axvbI8L=hL8GQlmm$*At?rg*inW`PNZiP6pMCg<`Q8Rb~;eAeM`>&)lL zVP|HKiIlS`>wn~}7s@IR-6^Lf{YR@U>;&@3GqIv@s*Pt;*g}`h{oQ$rc&}6v`c~gn qiXm#!nfh6Qvv&_vr-uXU)|c=9$$XYC*fbam&zpo literal 0 HcmV?d00001 diff --git a/public/icons/docs/pytorch/SOURCE b/public/icons/docs/pytorch/SOURCE new file mode 100644 index 00000000..9863ff2e --- /dev/null +++ b/public/icons/docs/pytorch/SOURCE @@ -0,0 +1 @@ +https://pytorch.org/favicon.ico \ No newline at end of file