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")