66from urllib import request
77
88import pandas as pd
9+ from docutils import nodes
10+ from docutils .core import publish_doctree
911from packaging .specifiers import SpecifierSet
1012from packaging .version import Version
1113
@@ -118,7 +120,7 @@ def check_scipy_compatibility(row, min_python, min_numpy):
118120 return python_compatible & numpy_compatible
119121
120122
121- def get_scipy_version_df ():
123+ def get_scipy_version_df_backup ():
122124 """
123125 Retrieve raw SciPy version table as DataFrame
124126 """
@@ -138,6 +140,45 @@ def get_scipy_version_df():
138140 )
139141
140142
143+ def get_scipy_version_df ():
144+ """
145+ Retrieve raw SciPy version table as DataFrame
146+
147+ This function retrieves the table directly from the SciPy Github docs and
148+ replaces `get_scipy_version_df_backup`.
149+ """
150+ url = (
151+ "https://raw.githubusercontent.com/scipy/scipy/"
152+ "refs/heads/main/doc/source/dev/toolchain.rst"
153+ )
154+ rst = request .urlopen (url ).read ()
155+
156+ doctree = publish_doctree (rst , settings_overrides = {"report_level" : 5 })
157+
158+ extracted_table = []
159+ for node in doctree .findall (nodes .literal_block ):
160+ if "Python and NumPy version support per SciPy version" in node .astext ():
161+ idx = - 1
162+ for i , l in enumerate (node .astext ().split ("\n " )):
163+ if l .lstrip ().startswith ("=" ):
164+ idx = i
165+ break
166+ table_str = "\n " .join (node .astext ().split ("\n " )[idx :])
167+ table_node = publish_doctree (table_str )
168+
169+ for row_node in table_node .findall (nodes .row ):
170+ current_row = []
171+ for entry_node in row_node .findall (nodes .entry ):
172+ # Extract text from the cell
173+ current_row .append (entry_node .astext ())
174+ extracted_table .append (current_row )
175+
176+ df = pd .DataFrame (extracted_table [1 :])
177+ df .columns = extracted_table [0 ]
178+
179+ return df .rename (columns = lambda x : x .replace (" " , "_" ))
180+
181+
141182def get_min_scipy_version (min_python , min_numpy ):
142183 """
143184 Determine the SciPy version compatibility
0 commit comments