Skip to content

remove warning from nbdev as pkg_resources is already deprecated #1522

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
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
16 changes: 11 additions & 5 deletions nbdev/doclinks.py
Original file line number Diff line number Diff line change
@@ -17,7 +17,8 @@
from fastcore.net import urlread

import ast,builtins,contextlib
import pkg_resources,importlib
import importlib.metadata
import importlib.util

from astunparse import unparse
from io import BytesIO
@@ -231,15 +232,19 @@ def _build_lookup_table(strip_libs=None, incl_libs=None, skip_mods=None):
cfg = get_config()
if strip_libs is None:
try: strip_libs = cfg.get('strip_libs', cfg.get('lib_path', 'nbdev').name).split()
except FileNotFoundError: strip_libs = 'nbdev'
except FileNotFoundError: strip_libs = ['nbdev']
skip_mods = setify(skip_mods)
strip_libs = L(strip_libs)
if incl_libs is not None: incl_libs = (L(incl_libs)+strip_libs).unique()

entries = {}
for o in pkg_resources.iter_entry_points(group='nbdev'):
if incl_libs is not None and o.dist.key not in incl_libs: continue
try: entries[o.name] = _qual_syms(o.resolve())
eps = importlib.metadata.entry_points()
nbdev_eps = eps.select(group='nbdev') if hasattr(eps, 'select') else eps.get('nbdev', [])
for o in nbdev_eps:
if incl_libs is not None and o.dist.name not in incl_libs: continue
try: entries[o.name] = _qual_syms(o.load())
except Exception: pass

py_syms = merge(*L(o['syms'].values() for o in entries.values()).concat())
for m in strip_libs:
if m in entries:
@@ -251,6 +256,7 @@ def _build_lookup_table(strip_libs=None, incl_libs=None, skip_mods=None):
k = remove_prefix(k,f"{mod}.")
if k not in stripped: stripped[k] = v
py_syms = merge(stripped, py_syms)

return entries,py_syms

# %% ../nbs/api/05_doclinks.ipynb
58 changes: 39 additions & 19 deletions nbs/api/05_doclinks.ipynb
Original file line number Diff line number Diff line change
@@ -36,7 +36,8 @@
"from fastcore.net import urlread\n",
"\n",
"import ast,builtins,contextlib\n",
"import pkg_resources,importlib\n",
"import importlib.metadata\n",
"import importlib.util\n",
"\n",
"from astunparse import unparse\n",
"from io import BytesIO\n",
@@ -614,15 +615,19 @@
" cfg = get_config()\n",
" if strip_libs is None:\n",
" try: strip_libs = cfg.get('strip_libs', cfg.get('lib_path', 'nbdev').name).split()\n",
" except FileNotFoundError: strip_libs = 'nbdev'\n",
" except FileNotFoundError: strip_libs = ['nbdev']\n",
" skip_mods = setify(skip_mods)\n",
" strip_libs = L(strip_libs)\n",
" if incl_libs is not None: incl_libs = (L(incl_libs)+strip_libs).unique()\n",
" \n",
" entries = {}\n",
" for o in pkg_resources.iter_entry_points(group='nbdev'):\n",
" if incl_libs is not None and o.dist.key not in incl_libs: continue\n",
" try: entries[o.name] = _qual_syms(o.resolve())\n",
" eps = importlib.metadata.entry_points()\n",
" nbdev_eps = eps.select(group='nbdev') if hasattr(eps, 'select') else eps.get('nbdev', [])\n",
" for o in nbdev_eps:\n",
" if incl_libs is not None and o.dist.name not in incl_libs: continue\n",
" try: entries[o.name] = _qual_syms(o.load())\n",
" except Exception: pass\n",
"\n",
" py_syms = merge(*L(o['syms'].values() for o in entries.values()).concat())\n",
" for m in strip_libs:\n",
" if m in entries:\n",
@@ -634,6 +639,7 @@
" k = remove_prefix(k,f\"{mod}.\")\n",
" if k not in stripped: stripped[k] = v\n",
" py_syms = merge(stripped, py_syms)\n",
" \n",
" return entries,py_syms"
]
},
@@ -675,13 +681,13 @@
"# Create mock entry points\n",
"class BadEntryPoint:\n",
" name = 'bad_entry'\n",
" dist = type('Dist', (), {'key': 'bad_lib'})()\n",
" def resolve(self): raise AttributeError(\"Simulated error\")\n",
" dist = type('Dist', (), {'name': 'bad_lib'})()\n",
" def load(self): raise AttributeError(\"Simulated error\")\n",
"\n",
"class GoodEntryPoint:\n",
" name = 'good_entry'\n",
" dist = type('Dist', (), {'key': 'good_lib'})()\n",
" def resolve(self): return {'syms': {}, 'settings': {}}"
" dist = type('Dist', (), {'name': 'good_lib'})()\n",
" def load(self): return {'syms': {}, 'settings': {}}"
]
},
{
@@ -704,8 +710,22 @@
"# Clear the cache before testing\n",
"_build_lookup_table.cache_clear()\n",
"\n",
"# Patch iter_entry_points\n",
"with xpatch('pkg_resources.iter_entry_points', return_value=[BadEntryPoint(), GoodEntryPoint()]):\n",
"# Create a mock entry points object that supports both access patterns\n",
"class MockEntryPoints:\n",
" def __init__(self, entries):\n",
" self.entries = entries\n",
" \n",
" def select(self, group):\n",
" return self.entries if group == 'nbdev' else []\n",
" \n",
" def get(self, group, default=None):\n",
" return self.entries if group == 'nbdev' else (default or [])\n",
"\n",
"# Create mock entry points\n",
"mock_eps = MockEntryPoints([BadEntryPoint(), GoodEntryPoint()])\n",
"\n",
"# Patch importlib.metadata.entry_points\n",
"with xpatch('importlib.metadata.entry_points', return_value=mock_eps):\n",
" entries, py_syms = _build_lookup_table()\n",
" \n",
" # Should only contain the good entry\n",
@@ -784,7 +804,7 @@
"text/plain": [
"('https://nbdev.fast.ai/api/doclinks.html#nbdevlookup',\n",
" 'nbdev/doclinks.py',\n",
" 'https://github.com/AnswerDotAI/nbdev/blob/master/nbdev/doclinks.py')"
" 'https://github.com/AnswerDotAI/nbdev/blob/main/nbdev/doclinks.py')"
]
},
"execution_count": null,
@@ -807,7 +827,7 @@
"text/markdown": [
"---\n",
"\n",
"[source](https://github.com/AnswerDotAI/nbdev/blob/master/nbdev/doclinks.py#L269){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
"[source](https://github.com/AnswerDotAI/nbdev/blob/main/nbdev/doclinks.py#L276){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
"\n",
"### NbdevLookup.doc\n",
"\n",
@@ -818,7 +838,7 @@
"text/plain": [
"---\n",
"\n",
"[source](https://github.com/AnswerDotAI/nbdev/blob/master/nbdev/doclinks.py#L269){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
"[source](https://github.com/AnswerDotAI/nbdev/blob/main/nbdev/doclinks.py#L276){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
"\n",
"### NbdevLookup.doc\n",
"\n",
@@ -909,7 +929,7 @@
"text/markdown": [
"---\n",
"\n",
"[source](https://github.com/AnswerDotAI/nbdev/blob/master/nbdev/doclinks.py#L274){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
"[source](https://github.com/AnswerDotAI/nbdev/blob/main/nbdev/doclinks.py#L281){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
"\n",
"### NbdevLookup.code\n",
"\n",
@@ -920,7 +940,7 @@
"text/plain": [
"---\n",
"\n",
"[source](https://github.com/AnswerDotAI/nbdev/blob/master/nbdev/doclinks.py#L274){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
"[source](https://github.com/AnswerDotAI/nbdev/blob/main/nbdev/doclinks.py#L281){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
"\n",
"### NbdevLookup.code\n",
"\n",
@@ -946,7 +966,7 @@
{
"data": {
"text/plain": [
"'https://github.com/AnswerDotAI/fastcore/blob/master/fastcore/net.py#LNone'"
"'https://github.com/AnswerDotAI/fastcore/blob/main/fastcore/net.py#LNone'"
]
},
"execution_count": null,
@@ -968,7 +988,7 @@
"text/markdown": [
"---\n",
"\n",
"[source](https://github.com/AnswerDotAI/nbdev/blob/master/nbdev/doclinks.py#L292){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
"[source](https://github.com/AnswerDotAI/nbdev/blob/main/nbdev/doclinks.py#L299){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
"\n",
"### NbdevLookup.linkify\n",
"\n",
@@ -977,7 +997,7 @@
"text/plain": [
"---\n",
"\n",
"[source](https://github.com/AnswerDotAI/nbdev/blob/master/nbdev/doclinks.py#L292){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
"[source](https://github.com/AnswerDotAI/nbdev/blob/main/nbdev/doclinks.py#L299){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
"\n",
"### NbdevLookup.linkify\n",
"\n",