From: Mo Zhou <lumin@debian.org>
Date: Sun, 12 Oct 2025 01:00:56 +0200
Subject: Prevent downloads during Sphinx documentation build

Forward: not-needed
---
 examples/applications/plot_out_of_core_classification.py | 4 +++-
 examples/applications/plot_stock_market.py               | 3 +++
 sklearn/datasets/_base.py                                | 3 +++
 sklearn/datasets/_openml.py                              | 3 +++
 4 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/examples/applications/plot_out_of_core_classification.py b/examples/applications/plot_out_of_core_classification.py
index ad0ff96..3200cde 100644
--- a/examples/applications/plot_out_of_core_classification.py
+++ b/examples/applications/plot_out_of_core_classification.py
@@ -18,6 +18,7 @@ features (words) may appear in each batch.
 # SPDX-License-Identifier: BSD-3-Clause
 
 import itertools
+import os
 import re
 import sys
 import tarfile
@@ -162,7 +163,8 @@ def stream_reuters_documents(data_path=None):
                 sys.stdout.write("\rdownloaded %s / %s" % (current_sz_mb, total_sz_mb))
 
         archive_path = data_path / ARCHIVE_FILENAME
-
+        if int(os.getenv('DEBIAN_POLICY_SECTION_4_9_NO_NETWORK_ACCESS', '0')) > 0:
+            raise TimeoutError('Debian Policy Section 4.9 prohibits network access during build')
         urlretrieve(DOWNLOAD_URL, filename=archive_path, reporthook=progress)
         if _not_in_sphinx():
             sys.stdout.write("\r")
diff --git a/examples/applications/plot_stock_market.py b/examples/applications/plot_stock_market.py
index 40f778c..80791e2 100644
--- a/examples/applications/plot_stock_market.py
+++ b/examples/applications/plot_stock_market.py
@@ -23,6 +23,7 @@ that are linked tend to fluctuate in relation to each other during a day.
 # `data.nasdaq.com <https://data.nasdaq.com/>`_ and
 # `alphavantage.co <https://www.alphavantage.co/>`_.
 
+import os
 import sys
 
 import numpy as np
@@ -98,6 +99,8 @@ for symbol in symbols:
         "https://raw.githubusercontent.com/scikit-learn/examples-data/"
         "master/financial-data/{}.csv"
     )
+    if int(os.getenv('DEBIAN_POLICY_SECTION_4_9_NO_NETWORK_ACCESS', '0')) > 0:
+        raise TimeoutError('Debian Policy Section 4.9 prohibits network access during build')
     quotes.append(pd.read_csv(url.format(symbol)))
 
 close_prices = np.vstack([q["close"] for q in quotes])
diff --git a/sklearn/datasets/_base.py b/sklearn/datasets/_base.py
index e6e6939..66a322f 100644
--- a/sklearn/datasets/_base.py
+++ b/sklearn/datasets/_base.py
@@ -1488,6 +1488,9 @@ def _fetch_remote(remote, dirname=None, n_retries=3, delay=1):
                 f"re-downloading from {remote.url} ."
             )
 
+    if int(os.getenv('DEBIAN_POLICY_SECTION_4_9_NO_NETWORK_ACCESS', '0')) > 0:
+        raise IOError('Debian Policy Section 4.9 prohibits network access during build')
+
     # We create a temporary file dedicated to this particular download to avoid
     # conflicts with parallel downloads. If the download is successful, the
     # temporary file is atomically renamed to the final file path (with
diff --git a/sklearn/datasets/_openml.py b/sklearn/datasets/_openml.py
index 537f6cd..44cbb20 100644
--- a/sklearn/datasets/_openml.py
+++ b/sklearn/datasets/_openml.py
@@ -994,6 +994,9 @@ def fetch_openml(
     dtypes: category(9), int64(6)
     memory usage: 2.7 MB
     """
+    if int(os.getenv('DEBIAN_POLICY_SECTION_4_9_NO_NETWORK_ACCESS', '0')) > 0:
+        raise TimeoutError('Debian Policy Section 4.9 prohibits network access during build')
+
     if cache is False:
         # no caching will be applied
         data_home = None
