|
36 | 36 | "from fastcore.net import urlread\n", |
37 | 37 | "\n", |
38 | 38 | "import ast,builtins,contextlib\n", |
39 | | - "import pkg_resources,importlib\n", |
| 39 | + "import importlib\n", |
40 | 40 | "\n", |
41 | 41 | "from astunparse import unparse\n", |
42 | 42 | "from io import BytesIO\n", |
43 | 43 | "from collections import defaultdict\n", |
44 | 44 | "from pprint import pformat\n", |
45 | 45 | "from urllib.parse import urljoin\n", |
46 | 46 | "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" |
48 | 50 | ] |
49 | 51 | }, |
50 | 52 | { |
|
608 | 610 | "metadata": {}, |
609 | 611 | "outputs": [], |
610 | 612 | "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", |
612 | 623 | "@lru_cache(None)\n", |
613 | 624 | "def _build_lookup_table(strip_libs=None, incl_libs=None, skip_mods=None):\n", |
614 | 625 | " cfg = get_config()\n", |
|
619 | 630 | " strip_libs = L(strip_libs)\n", |
620 | 631 | " if incl_libs is not None: incl_libs = (L(incl_libs)+strip_libs).unique()\n", |
621 | 632 | " 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", |
625 | 638 | " except Exception: pass\n", |
626 | 639 | " py_syms = merge(*L(o['syms'].values() for o in entries.values()).concat())\n", |
627 | 640 | " for m in strip_libs:\n", |
|
659 | 672 | "test_eq(after_second.misses, after_first.misses)" |
660 | 673 | ] |
661 | 674 | }, |
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 | | - }, |
718 | 675 | { |
719 | 676 | "cell_type": "code", |
720 | 677 | "execution_count": null, |
|
784 | 741 | "text/plain": [ |
785 | 742 | "('https://nbdev.fast.ai/api/doclinks.html#nbdevlookup',\n", |
786 | 743 | " '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')" |
788 | 745 | ] |
789 | 746 | }, |
790 | 747 | "execution_count": null, |
|
807 | 764 | "text/markdown": [ |
808 | 765 | "---\n", |
809 | 766 | "\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", |
811 | 768 | "\n", |
812 | 769 | "### NbdevLookup.doc\n", |
813 | 770 | "\n", |
|
818 | 775 | "text/plain": [ |
819 | 776 | "---\n", |
820 | 777 | "\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", |
822 | 779 | "\n", |
823 | 780 | "### NbdevLookup.doc\n", |
824 | 781 | "\n", |
|
836 | 793 | "show_doc(NbdevLookup.doc)" |
837 | 794 | ] |
838 | 795 | }, |
839 | | - { |
840 | | - "cell_type": "markdown", |
841 | | - "metadata": {}, |
842 | | - "source": [ |
843 | | - "Here's a test suite that verifies the error handling behavior:" |
844 | | - ] |
845 | | - }, |
846 | 796 | { |
847 | 797 | "cell_type": "code", |
848 | 798 | "execution_count": null, |
|
909 | 859 | "text/markdown": [ |
910 | 860 | "---\n", |
911 | 861 | "\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", |
913 | 863 | "\n", |
914 | 864 | "### NbdevLookup.code\n", |
915 | 865 | "\n", |
|
920 | 870 | "text/plain": [ |
921 | 871 | "---\n", |
922 | 872 | "\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", |
924 | 874 | "\n", |
925 | 875 | "### NbdevLookup.code\n", |
926 | 876 | "\n", |
|
946 | 896 | { |
947 | 897 | "data": { |
948 | 898 | "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'" |
950 | 900 | ] |
951 | 901 | }, |
952 | 902 | "execution_count": null, |
|
968 | 918 | "text/markdown": [ |
969 | 919 | "---\n", |
970 | 920 | "\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", |
972 | 922 | "\n", |
973 | 923 | "### NbdevLookup.linkify\n", |
974 | 924 | "\n", |
|
977 | 927 | "text/plain": [ |
978 | 928 | "---\n", |
979 | 929 | "\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", |
981 | 931 | "\n", |
982 | 932 | "### NbdevLookup.linkify\n", |
983 | 933 | "\n", |
|
0 commit comments