Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
37 changes: 31 additions & 6 deletions quantecon/util/notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/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"
Expand All @@ -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 <https://github.com/QuantEcon/data-lectures>`_
instead.

Parameters
----------
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Comment on lines 127 to 128
status.append(True)
Expand Down
15 changes: 15 additions & 0 deletions quantecon/util/tests/test_notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -17,6 +18,7 @@
FOLDER = "quantecon/util/tests/"


@pytest.mark.filterwarnings("ignore::DeprecationWarning")
class TestNotebookUtils:

def test_fetch_nb_dependencies(self):
Expand All @@ -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")
Loading