Skip to content

Commit 407b0dc

Browse files
authored
Merge pull request #2629 from ring00/pytorch-version-update
Add PyTorch 2.8 and 2.9 documentation support
2 parents 36224d5 + 190ffb5 commit 407b0dc

File tree

3 files changed

+41
-7
lines changed

3 files changed

+41
-7
lines changed

lib/docs/filters/pytorch/clean_html.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ module Docs
22
class Pytorch
33
class CleanHtmlFilter < Filter
44
def call
5-
@doc = at_css('.pytorch-article')
6-
# Show katex-mathml nodes and remove katex-html nodes
7-
css('.katex-html').remove
5+
if root = at_css('#pytorch-article')
6+
@doc = root
7+
# Show katex-mathml nodes and remove katex-html nodes
8+
css('.katex-html').remove
9+
end
810
doc
911
end
1012
end

lib/docs/filters/pytorch/entries.rb

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,39 @@ module Docs
22
class Pytorch
33
class EntriesFilter < Docs::EntriesFilter
44
def get_breadcrumbs
5-
css('.pytorch-breadcrumbs > li').map {
6-
|node| node.content.delete_suffix(' >').strip
7-
}.reject { |item| item.nil? || item.empty? }
5+
breadcrumbs = if at_css('.pytorch-breadcrumbs')
6+
css('.pytorch-breadcrumbs > li').map { |node|
7+
node.content.delete_suffix(' >').strip
8+
}
9+
else
10+
css('.bd-breadcrumbs > li').map { |node|
11+
text = node.content.strip
12+
text.empty? && node.at_css('.fa-home') ? 'Docs' : text
13+
}
14+
end.reject { |item| item.nil? || item.empty? }
15+
16+
if breadcrumbs.last&.end_with?('.')
17+
resolved_name = at_css('h1').content.delete_suffix('#').strip
18+
breadcrumbs[-1] = resolved_name
19+
end
20+
21+
breadcrumbs
822
end
923

1024
def get_name
1125
get_breadcrumbs[-1]
1226
end
1327

1428
def get_type
15-
get_breadcrumbs[1]
29+
if at_css('.pytorch-breadcrumbs')
30+
get_breadcrumbs[1]
31+
else
32+
get_breadcrumbs.size > 2 ? get_breadcrumbs[2] : get_breadcrumbs[1]
33+
end
34+
end
35+
36+
def include_default_entry?
37+
!get_breadcrumbs.nil? && get_breadcrumbs.size >= 2
1638
end
1739

1840
def additional_entries

lib/docs/scrapers/pytorch.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ class Pytorch < UrlScraper
1919
PyTorch has a BSD-style license, as found in the <a href="https://github.com/pytorch/pytorch/blob/main/LICENSE">LICENSE</a> file.
2020
HTML
2121

22+
version '2.9' do
23+
self.release = '2.9'
24+
self.base_url = "https://docs.pytorch.org/docs/#{release}/"
25+
end
26+
27+
version '2.8' do
28+
self.release = '2.8'
29+
self.base_url = "https://docs.pytorch.org/docs/#{release}/"
30+
end
31+
2232
version '2.7' do
2333
self.release = '2.7'
2434
self.base_url = "https://docs.pytorch.org/docs/#{release}/"

0 commit comments

Comments
 (0)