|
6 | 6 | from urllib.parse import urljoin
|
7 | 7 | from collections import defaultdict
|
8 | 8 | from pathlib import Path
|
9 |
| -# from fastcore.utils import urlread,merge |
| 9 | +from nbdev.doclinks import create_index |
10 | 10 | from fastcore.all import *
|
11 | 11 |
|
12 | 12 | mappings = dict(
|
|
46 | 46 | linux='https://docs.kernel.org/',
|
47 | 47 | )
|
48 | 48 |
|
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 |
| - |
64 | 49 | @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 | +): |
66 | 53 | "Make index for `nm`"
|
67 | 54 | url = mappings.get(nm)
|
| 55 | + print(nm, url) |
68 | 56 | if not url: return
|
69 |
| - idx = SphinxIndex(url) |
| 57 | + syms = create_index(url) |
70 | 58 | lib_path = Path(f"nbdev_{nm}")
|
71 | 59 | lib_path.mkdir(exist_ok=True)
|
72 | 60 | with (lib_path/'_modidx.py').open('w') as f:
|
73 | 61 | 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}) |
75 | 63 | pprint(d, f, width=160, indent=2, compact=True)
|
0 commit comments