From 15c7333101cbe2028be656915ca4145724922356 Mon Sep 17 00:00:00 2001 From: Matt McKay Date: Wed, 9 Sep 2026 16:01:07 +1000 Subject: [PATCH] DEPR: deprecate fetch_nb_dependencies and demote requests Deprecates `quantecon.util.notebooks` in 0.12.0 for removal in v1.0, and moves `requests` out of the mandatory dependency set into a `notebooks` extra that is removed with the module. `requests` served exactly one call site in the package. The function has no remaining constituency: no usage across lecture-python.myst, lecture-python-advanced.myst, lecture-python-intro or lecture-python-programming.myst, and the callers that exist are dormant notebooks descending from two 2017-era demos. Its default remote, QuantEcon/QuantEcon.notebooks, was last pushed 2023-07-15. Data still needed moves to QuantEcon/data-lectures. Calling the function emits a DeprecationWarning attributed to the caller's frame. Where `requests` is absent the lazy import raises an ImportError naming the extra. The stale 2016 TODO block, which no longer described the code, is replaced by the deprecation directive. Adds `r.raise_for_status()` as harm reduction for the module's final release: #870 reported that a missing remote path saved GitHub's 404 HTML page under the requested filename and reported success. Verified against the reported reproducer, which now raises HTTPError and writes no file. The other three defects in #870 are left unfixed, the function being scheduled for removal. Part of #880. Supersedes #870, #904 and #905, all closed. Co-Authored-By: Claude Opus 5 (1M context) --- pyproject.toml | 6 ++++- quantecon/util/notebooks.py | 37 +++++++++++++++++++++----- quantecon/util/tests/test_notebooks.py | 15 +++++++++++ 3 files changed, 51 insertions(+), 7 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 13db6f237..e9e54664c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,11 +25,15 @@ requires-python = ">=3.7" dependencies = [ 'numba>=0.56.0', 'numpy>=1.17.0', - 'requests', 'scipy>=1.5.0', ] [project.optional-dependencies] +# Supports the deprecated quantecon.util.notebooks helpers; removed in v1.0 +# together with the module itself. +notebooks = [ + "requests", +] testing = [ "pytest", "coverage", diff --git a/quantecon/util/notebooks.py b/quantecon/util/notebooks.py index 5f73a654b..7b2a4ef15 100644 --- a/quantecon/util/notebooks.py +++ b/quantecon/util/notebooks.py @@ -11,15 +11,18 @@ "https://github.com/QuantEcon/QuantEcon.notebooks/raw/master/dependencies/mpi/something.py" --> ./something.py -TODO ----- -1. Write Style guide for QuantEcon.notebook contributions -2. Write an interface for Dat Server -3. Platform Agnostic (replace wget usage) +.. deprecated:: 0.12.0 + ``fetch_nb_dependencies`` is deprecated and will be removed in v1.0, along + with this module. It has no remaining callers in the QuantEcon lecture + series, and ``requests`` is no longer a mandatory dependency of + QuantEcon.py. Datasets referenced by the lectures live in + `QuantEcon/data-lectures `_ and + should be fetched by stable URL with the tool of your choice. """ import os +import warnings #-Remote Structure-# REPO = "https://github.com/QuantEcon/QuantEcon.notebooks" @@ -32,6 +35,11 @@ def fetch_nb_dependencies(files, repo=REPO, raw=RAW, branch=BRANCH, folder=FOLDER, overwrite=False, verbose=True): """ Retrieve raw files from QuantEcon.notebooks or other Github repo + + .. deprecated:: 0.12.0 + Deprecated and will be removed in v1.0. Fetch data by stable URL from + `QuantEcon/data-lectures `_ + instead. Parameters ---------- @@ -71,7 +79,22 @@ def fetch_nb_dependencies(files, repo=REPO, raw=RAW, branch=BRANCH, folder=FOLDE by setting ``overwrite=True``. """ - import requests + warnings.warn( + "`fetch_nb_dependencies` is deprecated and will be removed in v1.0. " + "Fetch data by stable URL from QuantEcon/data-lectures instead.", + DeprecationWarning, + stacklevel=2, + ) + + try: + import requests + except ImportError: # pragma: no cover + raise ImportError( + "`fetch_nb_dependencies` requires `requests`, which is no longer a " + "mandatory dependency of QuantEcon.py. Install it with " + "`pip install 'quantecon[notebooks]'`. This function is deprecated " + "and will be removed in v1.0." + ) #-Generate Common Data Structure-# if type(files) == list: @@ -99,6 +122,8 @@ def fetch_nb_dependencies(files, repo=REPO, raw=RAW, branch=BRANCH, folder=FOLDE #-Get file in OS agnostic way using requests-# url = "/".join([repo, raw, branch, folder, fl]) r = requests.get(url) + #-Do not write an error page to disk under the requested name (#870)-# + r.raise_for_status() with open(fl, "wb") as fl: fl.write(r.content) status.append(True) diff --git a/quantecon/util/tests/test_notebooks.py b/quantecon/util/tests/test_notebooks.py index 56d0b195e..9955a4629 100644 --- a/quantecon/util/tests/test_notebooks.py +++ b/quantecon/util/tests/test_notebooks.py @@ -9,6 +9,7 @@ from quantecon.util import fetch_nb_dependencies import os +import pytest FILES = ['test_file.md'] REPO = "https://github.com/QuantEcon/QuantEcon.py" @@ -17,6 +18,7 @@ FOLDER = "quantecon/util/tests/" +@pytest.mark.filterwarnings("ignore::DeprecationWarning") class TestNotebookUtils: def test_fetch_nb_dependencies(self): @@ -39,3 +41,16 @@ def test_fetch_nb_dependencies_overwrite(self): def teardown_method(self): os.remove("test_file.md") + + +class TestNotebookUtilsDeprecation: + """`fetch_nb_dependencies` is deprecated in 0.12.0 and removed in v1.0.""" + + def test_fetch_nb_dependencies_warns(self): + with pytest.warns(DeprecationWarning, match="removed in v1.0"): + fetch_nb_dependencies( + files=FILES, repo=REPO, raw=RAW, branch=BRANCH, folder=FOLDER) + + def teardown_method(self): + if os.path.isfile("test_file.md"): + os.remove("test_file.md")