|
1 | 1 | module Docs |
2 | | - # Requires downloading the documents to local disk first. |
3 | | - # Go to https://numpy.org/doc/, click "HTML+zip" to download |
4 | | - # (example url: https://numpy.org/doc/2.4/numpy-html.zip), |
5 | | - # then extract into "docs/numpy~#{version}/" |
6 | 2 | class Numpy < FileScraper |
7 | 3 | self.name = 'NumPy' |
8 | 4 | self.type = 'sphinx' |
@@ -137,5 +133,36 @@ class Numpy < FileScraper |
137 | 133 | def get_latest_version(opts) |
138 | 134 | get_latest_github_release('numpy', 'numpy', opts) |
139 | 135 | end |
| 136 | + |
| 137 | + private |
| 138 | + |
| 139 | + # The documents predating 1.18 were published on docs.scipy.org instead. |
| 140 | + def archive_url |
| 141 | + @archive_url ||= [ |
| 142 | + "https://numpy.org/doc/#{self.class.version}/numpy-html.zip", |
| 143 | + "https://docs.scipy.org/doc/numpy-#{self.class.release}/numpy-html-#{self.class.release}.zip" |
| 144 | + ].find { |url| Request.run(url, method: :head).success? } |
| 145 | + end |
| 146 | + |
| 147 | + def download_source |
| 148 | + require 'unix_utils' |
| 149 | + |
| 150 | + raise SetupError, "No documentation archive found for NumPy #{self.class.release}." if archive_url.nil? |
| 151 | + |
| 152 | + instrument 'info.doc', msg: %(Downloading #{archive_url}...) |
| 153 | + archive = UnixUtils.curl(archive_url) |
| 154 | + |
| 155 | + instrument 'info.doc', msg: %(Extracting the documentation files to "#{source_directory}"...) |
| 156 | + directory = UnixUtils.unzip(archive) |
| 157 | + |
| 158 | + FileUtils.mkpath(File.dirname(source_directory)) |
| 159 | + # The archive holds the whole documentation, of which the older versions |
| 160 | + # are scraped from the "reference" subdirectory alone. |
| 161 | + root = base_url.path.end_with?('/reference/') ? File.join(directory, 'reference') : directory |
| 162 | + FileUtils.mv(root, source_directory) |
| 163 | + ensure |
| 164 | + FileUtils.rm_f(archive) if archive |
| 165 | + FileUtils.rm_rf(directory) if directory |
| 166 | + end |
140 | 167 | end |
141 | 168 | end |
0 commit comments