Skip to content

Commit e4b5c71

Browse files
committed
fixes #448
1 parent 50aab92 commit e4b5c71

File tree

3 files changed

+89
-60
lines changed

3 files changed

+89
-60
lines changed

fastcore/_modidx.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
'status': '4',
2424
'title': 'fastcore',
2525
'user': 'fastai',
26-
'version': '1.5.12'},
26+
'version': '1.5.14'},
2727
'syms': { 'fastcore.all': {},
2828
'fastcore.basics': { 'fastcore.basics.AttrDict': 'https://fastcore.fast.ai/basics.html#attrdict',
2929
'fastcore.basics.Float': 'https://fastcore.fast.ai/basics.html#float',
@@ -413,6 +413,7 @@
413413
'fastcore.xtras.ReindexCollection.shuffle': 'https://fastcore.fast.ai/xtras.html#reindexcollection.shuffle',
414414
'fastcore.xtras.autostart': 'https://fastcore.fast.ai/xtras.html#autostart',
415415
'fastcore.xtras.bunzip': 'https://fastcore.fast.ai/xtras.html#bunzip',
416+
'fastcore.xtras.console_help': 'https://fastcore.fast.ai/xtras.html#console_help',
416417
'fastcore.xtras.dict2obj': 'https://fastcore.fast.ai/xtras.html#dict2obj',
417418
'fastcore.xtras.dumps': 'https://fastcore.fast.ai/xtras.html#dumps',
418419
'fastcore.xtras.get_source_link': 'https://fastcore.fast.ai/xtras.html#get_source_link',

fastcore/xtras.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
'repr_dict', 'is_listy', 'mapped', 'IterLen', 'ReindexCollection', 'get_source_link', 'truncstr',
1010
'sparkline', 'modify_exception', 'round_multiple', 'set_num_threads', 'join_path_file', 'autostart',
1111
'EventTimer', 'stringfmt_names', 'PartialFormatter', 'partial_format', 'utc2local', 'local2utc', 'trace',
12-
'modified_env', 'ContextManagers', 'shufflish']
12+
'modified_env', 'ContextManagers', 'shufflish', 'console_help']
1313

1414
# %% ../nbs/03_xtras.ipynb 3
1515
from .imports import *
@@ -539,3 +539,13 @@ def shufflish(x, pct=0.04):
539539
n = len(x)
540540
import random
541541
return L(x[i] for i in sorted(range_of(x), key=lambda o: o+n*(1+random.random()*pct)))
542+
543+
# %% ../nbs/03_xtras.ipynb 156
544+
def console_help(
545+
libname:str): # name of library for console script listing
546+
"Show help for all console scripts from `libname`"
547+
from pkg_resources import iter_entry_points as ep
548+
for e in ep('console_scripts'):
549+
if e.module_name.startswith(libname+'.'):
550+
nm = f'\033[1m\033[94m{e.name}\033[0m'
551+
print(f'{nm:45}{e.load().__doc__}')

nbs/03_xtras.ipynb

Lines changed: 76 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@
633633
{
634634
"data": {
635635
"text/plain": [
636-
"'pip 21.2.4 from /Users/hamel/opt/anaconda3/lib/python3.9/site-packages/pip (python 3.9)'"
636+
"'pip 22.2 from /Users/jhoward/mambaforge/lib/python3.9/site-packages/pip (python 3.9)'"
637637
]
638638
},
639639
"execution_count": null,
@@ -1024,7 +1024,7 @@
10241024
{
10251025
"data": {
10261026
"text/plain": [
1027-
"Path('/home/jhoward/git/fastcore/fastcore')"
1027+
"Path('/Users/jhoward/git/fastcore/fastcore')"
10281028
]
10291029
},
10301030
"execution_count": null,
@@ -1091,7 +1091,7 @@
10911091
{
10921092
"data": {
10931093
"text/plain": [
1094-
"Path('05_transform.ipynb')"
1094+
"Path('parallel_test.py')"
10951095
]
10961096
},
10971097
"execution_count": null,
@@ -1125,7 +1125,7 @@
11251125
{
11261126
"data": {
11271127
"text/plain": [
1128-
"(Path('../fastcore/all.py'), Path('05_transform.ipynb'))"
1128+
"(Path('../fastcore/shutil.py'), Path('_parallel_win.ipynb'))"
11291129
]
11301130
},
11311131
"execution_count": null,
@@ -1268,18 +1268,22 @@
12681268
{
12691269
"data": {
12701270
"text/markdown": [
1271-
"<h4 id=\"ReindexCollection\" class=\"doc_header\"><code>class</code> <code>ReindexCollection</code><a href=\"\" class=\"source_link\" style=\"float:right\">[source]</a></h4>\n",
1271+
"---\n",
12721272
"\n",
1273-
"> <code>ReindexCollection</code>(**`coll`**, **`idxs`**=*`None`*, **`cache`**=*`None`*, **`tfm`**=*`noop`*) :: [`GetAttr`](/basics.html#GetAttr)\n",
1273+
"### ReindexCollection\n",
1274+
"\n",
1275+
"> ReindexCollection (coll, idxs=None, cache=None,\n",
1276+
"> tfm=<functionnoopat0x106121940>)\n",
12741277
"\n",
12751278
"Reindexes collection `coll` with indices `idxs` and optional LRU cache of size `cache`"
12761279
],
12771280
"text/plain": [
1278-
"<IPython.core.display.Markdown object>"
1281+
"<nbdev.showdoc.BasicMarkdownRenderer>"
12791282
]
12801283
},
1284+
"execution_count": null,
12811285
"metadata": {},
1282-
"output_type": "display_data"
1286+
"output_type": "execute_result"
12831287
}
12841288
],
12851289
"source": [
@@ -1338,18 +1342,21 @@
13381342
{
13391343
"data": {
13401344
"text/markdown": [
1341-
"<h6 id=\"ReindexCollection.reindex\" class=\"doc_header\"><code>ReindexCollection.reindex</code><a href=\"__main__.py#L14\" class=\"source_link\" style=\"float:right\">[source]</a></h6>\n",
1345+
"---\n",
13421346
"\n",
1343-
"> <code>ReindexCollection.reindex</code>(**`idxs`**)\n",
1347+
"#### ReindexCollection.reindex\n",
1348+
"\n",
1349+
"> ReindexCollection.reindex (idxs)\n",
13441350
"\n",
13451351
"Replace `self.idxs` with idxs"
13461352
],
13471353
"text/plain": [
1348-
"<IPython.core.display.Markdown object>"
1354+
"<nbdev.showdoc.BasicMarkdownRenderer>"
13491355
]
13501356
},
1357+
"execution_count": null,
13511358
"metadata": {},
1352-
"output_type": "display_data"
1359+
"output_type": "execute_result"
13531360
}
13541361
],
13551362
"source": [
@@ -1425,18 +1432,21 @@
14251432
{
14261433
"data": {
14271434
"text/markdown": [
1428-
"<h5 id=\"ReindexCollection.cache_clear\" class=\"doc_header\"><code>ReindexCollection.cache_clear</code><a href=\"__main__.py#L18\" class=\"source_link\" style=\"float:right\">[source]</a></h5>\n",
1435+
"---\n",
1436+
"\n",
1437+
"#### ReindexCollection.cache_clear\n",
14291438
"\n",
1430-
"> <code>ReindexCollection.cache_clear</code>()\n",
1439+
"> ReindexCollection.cache_clear ()\n",
14311440
"\n",
14321441
"Clear LRU cache"
14331442
],
14341443
"text/plain": [
1435-
"<IPython.core.display.Markdown object>"
1444+
"<nbdev.showdoc.BasicMarkdownRenderer>"
14361445
]
14371446
},
1447+
"execution_count": null,
14381448
"metadata": {},
1439-
"output_type": "display_data"
1449+
"output_type": "execute_result"
14401450
}
14411451
],
14421452
"source": [
@@ -1477,18 +1487,21 @@
14771487
{
14781488
"data": {
14791489
"text/markdown": [
1480-
"<h5 id=\"ReindexCollection.shuffle\" class=\"doc_header\"><code>ReindexCollection.shuffle</code><a href=\"__main__.py#L15\" class=\"source_link\" style=\"float:right\">[source]</a></h5>\n",
1490+
"---\n",
1491+
"\n",
1492+
"#### ReindexCollection.shuffle\n",
14811493
"\n",
1482-
"> <code>ReindexCollection.shuffle</code>()\n",
1494+
"> ReindexCollection.shuffle ()\n",
14831495
"\n",
14841496
"Randomly shuffle indices"
14851497
],
14861498
"text/plain": [
1487-
"<IPython.core.display.Markdown object>"
1499+
"<nbdev.showdoc.BasicMarkdownRenderer>"
14881500
]
14891501
},
1502+
"execution_count": null,
14901503
"metadata": {},
1491-
"output_type": "display_data"
1504+
"output_type": "execute_result"
14921505
}
14931506
],
14941507
"source": [
@@ -1510,7 +1523,7 @@
15101523
{
15111524
"data": {
15121525
"text/plain": [
1513-
"['h', 'b', 'e', 'g', 'a', 'd', 'f', 'c']"
1526+
"['f', 'g', 'c', 'd', 'h', 'b', 'e', 'a']"
15141527
]
15151528
},
15161529
"execution_count": null,
@@ -1614,7 +1627,7 @@
16141627
{
16151628
"data": {
16161629
"text/plain": [
1617-
"'https://github.com/fastai/fastcore/tree/master/fastcore/test.py#L34'"
1630+
"'https://github.com/fastai/fastcore/tree/master/fastcore/test.py#L35'"
16181631
]
16191632
},
16201633
"execution_count": null,
@@ -1923,18 +1936,21 @@
19231936
{
19241937
"data": {
19251938
"text/markdown": [
1926-
"<h4 id=\"EventTimer\" class=\"doc_header\"><code>class</code> <code>EventTimer</code><a href=\"\" class=\"source_link\" style=\"float:right\">[source]</a></h4>\n",
1939+
"---\n",
1940+
"\n",
1941+
"### EventTimer\n",
19271942
"\n",
1928-
"> <code>EventTimer</code>(**`store`**=*`5`*, **`span`**=*`60`*)\n",
1943+
"> EventTimer (store=5, span=60)\n",
19291944
"\n",
19301945
"An event timer with history of `store` items of time `span`"
19311946
],
19321947
"text/plain": [
1933-
"<IPython.core.display.Markdown object>"
1948+
"<nbdev.showdoc.BasicMarkdownRenderer>"
19341949
]
19351950
},
1951+
"execution_count": null,
19361952
"metadata": {},
1937-
"output_type": "display_data"
1953+
"output_type": "execute_result"
19381954
}
19391955
],
19401956
"source": [
@@ -1957,8 +1973,8 @@
19571973
"name": "stdout",
19581974
"output_type": "stream",
19591975
"text": [
1960-
"Num Events: 7, Freq/sec: 315.8\n",
1961-
"Most recent: ▇▁▁▂▅ 423.6 331.5 332.6 361.3 399.7\n"
1976+
"Num Events: 5, Freq/sec: 262.4\n",
1977+
"Most recent: ▇▃▁▃▆ 378.3 298.9 195.8 278.2 346.5\n"
19621978
]
19631979
}
19641980
],
@@ -2035,18 +2051,21 @@
20352051
{
20362052
"data": {
20372053
"text/markdown": [
2038-
"<h4 id=\"PartialFormatter\" class=\"doc_header\"><code>class</code> <code>PartialFormatter</code><a href=\"\" class=\"source_link\" style=\"float:right\">[source]</a></h4>\n",
2054+
"---\n",
20392055
"\n",
2040-
"> <code>PartialFormatter</code>() :: `Formatter`\n",
2056+
"### PartialFormatter\n",
2057+
"\n",
2058+
"> PartialFormatter ()\n",
20412059
"\n",
20422060
"A `string.Formatter` that doesn't error on missing fields, and tracks missing fields and unused args"
20432061
],
20442062
"text/plain": [
2045-
"<IPython.core.display.Markdown object>"
2063+
"<nbdev.showdoc.BasicMarkdownRenderer>"
20462064
]
20472065
},
2066+
"execution_count": null,
20482067
"metadata": {},
2049-
"output_type": "display_data"
2068+
"output_type": "execute_result"
20502069
}
20512070
],
20522071
"source": [
@@ -2238,18 +2257,21 @@
22382257
{
22392258
"data": {
22402259
"text/markdown": [
2241-
"<h4 id=\"ContextManagers\" class=\"doc_header\"><code>class</code> <code>ContextManagers</code><a href=\"\" class=\"source_link\" style=\"float:right\">[source]</a></h4>\n",
2260+
"---\n",
22422261
"\n",
2243-
"> <code>ContextManagers</code>(**`mgrs`**) :: [`GetAttr`](/basics.html#GetAttr)\n",
2262+
"### ContextManagers\n",
2263+
"\n",
2264+
"> ContextManagers (mgrs)\n",
22442265
"\n",
22452266
"Wrapper for `contextlib.ExitStack` which enters a collection of context managers"
22462267
],
22472268
"text/plain": [
2248-
"<IPython.core.display.Markdown object>"
2269+
"<nbdev.showdoc.BasicMarkdownRenderer>"
22492270
]
22502271
},
2272+
"execution_count": null,
22512273
"metadata": {},
2252-
"output_type": "display_data"
2274+
"output_type": "execute_result"
22532275
}
22542276
],
22552277
"source": [
@@ -2270,6 +2292,23 @@
22702292
" return L(x[i] for i in sorted(range_of(x), key=lambda o: o+n*(1+random.random()*pct)))"
22712293
]
22722294
},
2295+
{
2296+
"cell_type": "code",
2297+
"execution_count": null,
2298+
"metadata": {},
2299+
"outputs": [],
2300+
"source": [
2301+
"#|export\n",
2302+
"def console_help(\n",
2303+
" libname:str): # name of library for console script listing\n",
2304+
" \"Show help for all console scripts from `libname`\"\n",
2305+
" from pkg_resources import iter_entry_points as ep\n",
2306+
" for e in ep('console_scripts'): \n",
2307+
" if e.module_name.startswith(libname+'.'): \n",
2308+
" nm = f'\\033[1m\\033[94m{e.name}\\033[0m'\n",
2309+
" print(f'{nm:45}{e.load().__doc__}')"
2310+
]
2311+
},
22732312
{
22742313
"cell_type": "markdown",
22752314
"metadata": {},
@@ -2281,30 +2320,9 @@
22812320
"cell_type": "code",
22822321
"execution_count": null,
22832322
"metadata": {},
2284-
"outputs": [
2285-
{
2286-
"name": "stdout",
2287-
"output_type": "stream",
2288-
"text": [
2289-
"Converted 00_test.ipynb.\n",
2290-
"Converted 01_basics.ipynb.\n",
2291-
"Converted 02_foundation.ipynb.\n",
2292-
"Converted 03_xtras.ipynb.\n",
2293-
"Converted 03a_parallel.ipynb.\n",
2294-
"Converted 03b_net.ipynb.\n",
2295-
"Converted 04_dispatch.ipynb.\n",
2296-
"Converted 05_transform.ipynb.\n",
2297-
"Converted 06_docments.ipynb.\n",
2298-
"Converted 07_meta.ipynb.\n",
2299-
"Converted 08_script.ipynb.\n",
2300-
"Converted index.ipynb.\n",
2301-
"Converted parallel_win.ipynb.\n"
2302-
]
2303-
}
2304-
],
2323+
"outputs": [],
23052324
"source": [
23062325
"#|hide\n",
2307-
"#|eval: false\n",
23082326
"from nbdev import nbdev_export\n",
23092327
"nbdev_export()"
23102328
]

0 commit comments

Comments
 (0)