Skip to content

Commit 4c393e5

Browse files
authored
Merge pull request #39 from AnswerDotAI/builtins
Update nbdev_stdlib symbol index with latest Python stdlib symbols
2 parents 4fa3af7 + 523c6f0 commit 4c393e5

File tree

2 files changed

+477
-359
lines changed

2 files changed

+477
-359
lines changed

mk_index.py

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from urllib.parse import urljoin
77
from collections import defaultdict
88
from pathlib import Path
9-
# from fastcore.utils import urlread,merge
9+
from nbdev.doclinks import create_index
1010
from fastcore.all import *
1111

1212
mappings = dict(
@@ -46,30 +46,18 @@
4646
linux='https://docs.kernel.org/',
4747
)
4848

49-
class SphinxIndex:
50-
def __init__(self, url, pre=None):
51-
if pre is None: pre=url+"/"
52-
invs = urlread(f'{url}/objects.inv', decode=False)
53-
self.idx = InventoryFile.load(stream=BytesIO(invs), uri=pre, joinfunc=urljoin)
54-
typs = 'module','class','method','function'
55-
self.d = {o:self._get(o) for o in typs}
56-
self.syms = defaultdict(dict)
57-
for o in typs:
58-
for k,v in self.d[o].items():
59-
modparts = k.split(".")[:-2 if o=='method' else -1]
60-
if modparts: self.syms['.'.join(modparts)][k] = v
61-
62-
def _get(self, o): return {k:v[2] for k,v in self.idx[f'py:{o}'].items() if k[0]!='_'}
63-
6449
@call_parse
65-
def make_index(nm:Param("Name of library to index")):
50+
def make_index(
51+
nm: str # Name of library to index
52+
):
6653
"Make index for `nm`"
6754
url = mappings.get(nm)
55+
print(nm, url)
6856
if not url: return
69-
idx = SphinxIndex(url)
57+
syms = create_index(url)
7058
lib_path = Path(f"nbdev_{nm}")
7159
lib_path.mkdir(exist_ok=True)
7260
with (lib_path/'_modidx.py').open('w') as f:
7361
f.write("# Autogenerated by get_module_idx.py\n\nd = ")
74-
d = dict(syms=dict(idx.syms), settings={'lib_path':lib_path.name})
62+
d = dict(syms=dict(syms), settings={'lib_path':lib_path.name})
7563
pprint(d, f, width=160, indent=2, compact=True)

0 commit comments

Comments
 (0)