Skip to content

Commit c3da98b

Browse files
committed
fixes #1525
1 parent dde07ab commit c3da98b

File tree

3 files changed

+35
-84
lines changed

3 files changed

+35
-84
lines changed

nbdev/doclinks.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from fastcore.net import urlread
1818

1919
import ast,builtins,contextlib
20-
import pkg_resources,importlib
20+
import importlib
2121

2222
from astunparse import unparse
2323
from io import BytesIO
@@ -27,6 +27,8 @@
2727
from functools import lru_cache
2828
from types import ModuleType
2929

30+
from importlib.metadata import entry_points
31+
3032
# %% ../nbs/api/05_doclinks.ipynb
3133
def _sym_nm(klas, sym): return f'{unparse(klas).strip()}.{sym.name}'
3234

@@ -236,9 +238,11 @@ def _build_lookup_table(strip_libs=None, incl_libs=None, skip_mods=None):
236238
strip_libs = L(strip_libs)
237239
if incl_libs is not None: incl_libs = (L(incl_libs)+strip_libs).unique()
238240
entries = {}
239-
for o in pkg_resources.iter_entry_points(group='nbdev'):
240-
if incl_libs is not None and o.dist.key not in incl_libs: continue
241-
try: entries[o.name] = _qual_syms(o.resolve())
241+
# TODO: use new group param once 3.10 in min python
242+
eps = [o for o in entry_points() if o.group=='nbdev']
243+
for o in eps:
244+
if incl_libs is not None and o.dist.name not in incl_libs: continue
245+
try: entries[o.name] = _qual_syms(o.load())
242246
except Exception: pass
243247
py_syms = merge(*L(o['syms'].values() for o in entries.values()).concat())
244248
for m in strip_libs:

nbs/api/05_doclinks.ipynb

Lines changed: 27 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,17 @@
3636
"from fastcore.net import urlread\n",
3737
"\n",
3838
"import ast,builtins,contextlib\n",
39-
"import pkg_resources,importlib\n",
39+
"import importlib\n",
4040
"\n",
4141
"from astunparse import unparse\n",
4242
"from io import BytesIO\n",
4343
"from collections import defaultdict\n",
4444
"from pprint import pformat\n",
4545
"from urllib.parse import urljoin\n",
4646
"from functools import lru_cache\n",
47-
"from types import ModuleType"
47+
"from types import ModuleType\n",
48+
"\n",
49+
"from importlib.metadata import entry_points"
4850
]
4951
},
5052
{
@@ -608,7 +610,16 @@
608610
"metadata": {},
609611
"outputs": [],
610612
"source": [
611-
"#| export\n",
613+
"eps = entry_points()['nbdev']"
614+
]
615+
},
616+
{
617+
"cell_type": "code",
618+
"execution_count": null,
619+
"metadata": {},
620+
"outputs": [],
621+
"source": [
622+
"#|export\n",
612623
"@lru_cache(None)\n",
613624
"def _build_lookup_table(strip_libs=None, incl_libs=None, skip_mods=None):\n",
614625
" cfg = get_config()\n",
@@ -619,9 +630,11 @@
619630
" strip_libs = L(strip_libs)\n",
620631
" if incl_libs is not None: incl_libs = (L(incl_libs)+strip_libs).unique()\n",
621632
" entries = {}\n",
622-
" for o in pkg_resources.iter_entry_points(group='nbdev'):\n",
623-
" if incl_libs is not None and o.dist.key not in incl_libs: continue\n",
624-
" try: entries[o.name] = _qual_syms(o.resolve())\n",
633+
" # TODO: use new group param once 3.10 in min python\n",
634+
" eps = [o for o in entry_points() if o.group=='nbdev']\n",
635+
" for o in eps:\n",
636+
" if incl_libs is not None and o.dist.name not in incl_libs: continue\n",
637+
" try: entries[o.name] = _qual_syms(o.load())\n",
625638
" except Exception: pass\n",
626639
" py_syms = merge(*L(o['syms'].values() for o in entries.values()).concat())\n",
627640
" for m in strip_libs:\n",
@@ -659,62 +672,6 @@
659672
"test_eq(after_second.misses, after_first.misses)"
660673
]
661674
},
662-
{
663-
"cell_type": "markdown",
664-
"metadata": {},
665-
"source": [
666-
"Let's test out our error handling when one of the entry points throws an error:"
667-
]
668-
},
669-
{
670-
"cell_type": "code",
671-
"execution_count": null,
672-
"metadata": {},
673-
"outputs": [],
674-
"source": [
675-
"# Create mock entry points\n",
676-
"class BadEntryPoint:\n",
677-
" name = 'bad_entry'\n",
678-
" dist = type('Dist', (), {'key': 'bad_lib'})()\n",
679-
" def resolve(self): raise AttributeError(\"Simulated error\")\n",
680-
"\n",
681-
"class GoodEntryPoint:\n",
682-
" name = 'good_entry'\n",
683-
" dist = type('Dist', (), {'key': 'good_lib'})()\n",
684-
" def resolve(self): return {'syms': {}, 'settings': {}}"
685-
]
686-
},
687-
{
688-
"cell_type": "code",
689-
"execution_count": null,
690-
"metadata": {},
691-
"outputs": [
692-
{
693-
"data": {
694-
"text/plain": [
695-
"{'good_entry': {'syms': {}, 'settings': {}}}"
696-
]
697-
},
698-
"execution_count": null,
699-
"metadata": {},
700-
"output_type": "execute_result"
701-
}
702-
],
703-
"source": [
704-
"# Clear the cache before testing\n",
705-
"_build_lookup_table.cache_clear()\n",
706-
"\n",
707-
"# Patch iter_entry_points\n",
708-
"with xpatch('pkg_resources.iter_entry_points', return_value=[BadEntryPoint(), GoodEntryPoint()]):\n",
709-
" entries, py_syms = _build_lookup_table()\n",
710-
" \n",
711-
" # Should only contain the good entry\n",
712-
" assert 'bad_entry' not in entries\n",
713-
" assert 'good_entry' in entries\n",
714-
" assert len(entries) == 1\n",
715-
"entries"
716-
]
717-
},
718675
{
719676
"cell_type": "code",
720677
"execution_count": null,
@@ -784,7 +741,7 @@
784741
"text/plain": [
785742
"('https://nbdev.fast.ai/api/doclinks.html#nbdevlookup',\n",
786743
" 'nbdev/doclinks.py',\n",
787-
" 'https://github.com/AnswerDotAI/nbdev/blob/master/nbdev/doclinks.py')"
744+
" 'https://github.com/AnswerDotAI/nbdev/blob/main/nbdev/doclinks.py')"
788745
]
789746
},
790747
"execution_count": null,
@@ -807,7 +764,7 @@
807764
"text/markdown": [
808765
"---\n",
809766
"\n",
810-
"[source](https://github.com/AnswerDotAI/nbdev/blob/master/nbdev/doclinks.py#L269){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
767+
"[source](https://github.com/AnswerDotAI/nbdev/blob/main/nbdev/doclinks.py#L269){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
811768
"\n",
812769
"### NbdevLookup.doc\n",
813770
"\n",
@@ -818,7 +775,7 @@
818775
"text/plain": [
819776
"---\n",
820777
"\n",
821-
"[source](https://github.com/AnswerDotAI/nbdev/blob/master/nbdev/doclinks.py#L269){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
778+
"[source](https://github.com/AnswerDotAI/nbdev/blob/main/nbdev/doclinks.py#L269){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
822779
"\n",
823780
"### NbdevLookup.doc\n",
824781
"\n",
@@ -836,13 +793,6 @@
836793
"show_doc(NbdevLookup.doc)"
837794
]
838795
},
839-
{
840-
"cell_type": "markdown",
841-
"metadata": {},
842-
"source": [
843-
"Here's a test suite that verifies the error handling behavior:"
844-
]
845-
},
846796
{
847797
"cell_type": "code",
848798
"execution_count": null,
@@ -909,7 +859,7 @@
909859
"text/markdown": [
910860
"---\n",
911861
"\n",
912-
"[source](https://github.com/AnswerDotAI/nbdev/blob/master/nbdev/doclinks.py#L274){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
862+
"[source](https://github.com/AnswerDotAI/nbdev/blob/main/nbdev/doclinks.py#L274){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
913863
"\n",
914864
"### NbdevLookup.code\n",
915865
"\n",
@@ -920,7 +870,7 @@
920870
"text/plain": [
921871
"---\n",
922872
"\n",
923-
"[source](https://github.com/AnswerDotAI/nbdev/blob/master/nbdev/doclinks.py#L274){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
873+
"[source](https://github.com/AnswerDotAI/nbdev/blob/main/nbdev/doclinks.py#L274){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
924874
"\n",
925875
"### NbdevLookup.code\n",
926876
"\n",
@@ -946,7 +896,7 @@
946896
{
947897
"data": {
948898
"text/plain": [
949-
"'https://github.com/AnswerDotAI/fastcore/blob/master/fastcore/net.py#LNone'"
899+
"'https://github.com/AnswerDotAI/fastcore/blob/main/fastcore/net.py#LNone'"
950900
]
951901
},
952902
"execution_count": null,
@@ -968,7 +918,7 @@
968918
"text/markdown": [
969919
"---\n",
970920
"\n",
971-
"[source](https://github.com/AnswerDotAI/nbdev/blob/master/nbdev/doclinks.py#L292){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
921+
"[source](https://github.com/AnswerDotAI/nbdev/blob/main/nbdev/doclinks.py#L292){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
972922
"\n",
973923
"### NbdevLookup.linkify\n",
974924
"\n",
@@ -977,7 +927,7 @@
977927
"text/plain": [
978928
"---\n",
979929
"\n",
980-
"[source](https://github.com/AnswerDotAI/nbdev/blob/master/nbdev/doclinks.py#L292){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
930+
"[source](https://github.com/AnswerDotAI/nbdev/blob/main/nbdev/doclinks.py#L292){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
981931
"\n",
982932
"### NbdevLookup.linkify\n",
983933
"\n",

setup.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
from configparser import ConfigParser
33

44
import setuptools
5-
from pkg_resources import parse_version
6-
7-
assert parse_version(setuptools.__version__)>=parse_version('36.2')
85

96
# note: all settings are in settings.ini; edit there, not here
107
config = ConfigParser(delimiters=['='])

0 commit comments

Comments
 (0)