Skip to content

Commit c2bd89e

Browse files
committed
Misc fixes:
* Improve HTML links * Fix shelp CLI option * Reduce false positives identifying internal imports * Improve line spacing of HTML links in CLI output * Improve layout of links in CLI output * Add comment about cross-platform benefits of pathlib * Fix bug identifying list items when applying layout_comment * Add tests for layout_comment * Bump version
1 parent d9c48f4 commit c2bd89e

File tree

16 files changed

+90
-43
lines changed

16 files changed

+90
-43
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
![Example HTML output](https://github.com/grantps/superhelp/raw/master/superhelp_logo_padded_small.png)
44

5-
version number: 1.0.10
5+
version number: 1.0.11
66
author: Grant Paton-Simpson
77

88
## Overview

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from codecs import open
33
from os import path
44

5-
__version__ = '1.0.10'
5+
__version__ = '1.0.11'
66

77
here = path.abspath(path.dirname(__file__))
88

@@ -50,7 +50,7 @@
5050
python_requires='>=3.6',
5151
entry_points = {
5252
'console_scripts': [
53-
'shelp=superhelp:shelp', ## using argparse to allow arguments
53+
'shelp=superhelp.helper:shelp', ## using argparse to allow arguments
5454
]
5555
},
5656
)

superhelp/conf.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,12 @@
184184
'uu', 'uuid', 'venv', 'warnings', 'wave', 'weakref', 'webbrowser', 'winreg',
185185
'winsound', 'wsgiref', 'xdrlib', 'xml', 'xmlrpc', 'zipapp', 'zipfile',
186186
'zipimport', 'zlib']
187-
POPULAR_LIBS = ['requests', 'flask', 'django', ]
187+
POPULAR_LIBS = ['urllib3', 'six', 'botocore', 'requests', 's3transfer', 'idna',
188+
'certifi', 'python-dateutil', 'docutils', 'chardet', 'pyyaml', 'pip',
189+
'jmespath', 'setuptools', 'boto3', 'rsa', 'pyasn1', 'numpy', 'wheel',
190+
'pytz', 'markupsafe', 'flask', 'django', 'pandas', 'geopandas', 'bs4',
191+
'requests_html', 'pipenv', 'poetry', 'scikit_learn', 'matplotlib',
192+
'openpyxl', 'psycopg2', 'scrapy', 'twisted', ]
188193

189194
SUPERHELP_PROJECT_OUTPUT = 'superhelp_project_output'
190195
SUPERHELP_GEN_OUTPUT = 'superhelp_output'

superhelp/displayers/cli_extras/ansi_printer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ def formatter(el, out, nesting_level=0, prefix='', parent=None):
258258
if links_list:
259259
for i, l in enumerate(links_list, 1):
260260
out.append(cli_colour.colourise_low_vis(
261-
f"{indent}[{i}] {l}"))
261+
f"{indent}[{i}] {l}\n"))
262262

263263
if is_txt_and_inline_markup:
264264
if el.tag == 'li':

superhelp/displayers/cli_extras/cli_utils.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,21 +262,22 @@ def get_text_if_inline_markup(el):
262262
def replace_links(el, html, link_display_type='it'):
263263
"""
264264
Digging through inline "<a href=..."
265+
265266
:return: links_list, and tag
266267
"""
267268
parts = html.split('<a ')
268269
if len(parts) == 1:
269270
links_list = None
270271
return links_list, html
271272
links_list, cur_link = [], 0
272-
links = [l for l in el.getchildren() if "href" in l.keys()]
273+
links = [l for l in el.getchildren() if 'href' in l.keys()]
273274
if not len(parts) == len(links) + 1:
274275
## contains an html element we don't support e.g. blockquote
275276
links_list = None
276277
return links_list, html
277278
cur = ''
278279
while parts:
279-
cur += parts.pop(0).rsplit("</a>")[-1]
280+
cur += parts.pop(0).rsplit('</a>')[-1]
280281
if not parts:
281282
break
282283

@@ -293,7 +294,7 @@ def replace_links(el, html, link_display_type='it'):
293294
cur += cli_colour.colourise_low_vis(f"({link_str})")
294295
elif link_display_type != "h": # inline table (it)
295296
# we build a link list, add the number like ① :
296-
cur += f"{chr(cli_conf.LINK_START_ORD + cur_link)} "
297+
cur += f" {chr(cli_conf.LINK_START_ORD + cur_link)} "
297298
links_list.append(link_str)
298299
else:
299300
pass ## apparently we ignore h

superhelp/gen_utils.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ def convert_to_xml(node, omit_docstrings=False, node_mappings=None):
9797

9898
starting_num_space_pattern = r"""(?x)
9999
^ ## start
100-
\d{1} ## one digit
100+
\d+ ## one or more digits
101+
\.? ## optional dot
101102
\s{1} ## one whitespace
102103
\S+ ## at least one non-whitespace
103104
"""
@@ -511,6 +512,23 @@ def int2first_etc(num):
511512
}
512513
return nice.get(num, num)
513514

515+
def _is_special_line(one_line_paragraph):
516+
"""
517+
Special lines are ones we shouldn't break into sub-lines. Title, list items,
518+
links etc.
519+
520+
:rtype: bool
521+
"""
522+
res = starting_num_space_prog.match(one_line_paragraph)
523+
if res is not None:
524+
return True
525+
if one_line_paragraph.startswith((
526+
'#', ## could be one hash or multiple depending on heading level
527+
'* ' ## trying to detect bulleted (unordered) lists
528+
)):
529+
return True
530+
return False
531+
514532
def layout_comment(raw_comment, *, is_code=False):
515533
"""
516534
Layout comment ready for MD. Handles dedenting and code.
@@ -548,15 +566,7 @@ def layout_comment(raw_comment, *, is_code=False):
548566
len(raw_paragraph) - len(raw_paragraph.rstrip('\n')))
549567
paragraph = raw_paragraph.strip()
550568
one_line_paragraph = paragraph.replace('\n', ' ') ## actually continuations of same line so no need to put on separate lines
551-
special_line = False
552-
res = starting_num_space_prog.match(one_line_paragraph)
553-
if res is not None:
554-
special_line = True
555-
if one_line_paragraph.startswith((
556-
'#', ## could be one hash or multiple depending on heading level
557-
'* ' ## trying to detect bulleted (unordered) lists
558-
)):
559-
special_line = True
569+
special_line = _is_special_line(one_line_paragraph)
560570
if special_line:
561571
wrapped_paragraph_lines = [one_line_paragraph, ]
562572
else:

superhelp/helpers/class_help.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def getters_setters(block_dets, *, repeat=False, **_kwargs):
6060
why_getters_etc = layout(f"""\
6161
6262
A good discussion of getters, setters, and properties can be found at
63-
<https://www.python-course.eu/python3_properties.php>.
63+
[Properties vs. Getters and Setters](https://www.python-course.eu/python3_properties.php)
6464
6565
Getters and setters are usually added in other languages such as Java
6666
because direct attribute access doesn't give the ability to calculate

superhelp/helpers/dict_help.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,10 @@ def dict_overview(block_dets, *, repeat=False, execute_code=True, **_kwargs):
155155
They are also super-efficient and fast. The two presentations to watch
156156
are by the mighty Brandon Rhodes:
157157
158-
1. The Dictionary Even Mightier -
159-
<https://www.youtube.com/watch?v=66P5FMkWoVU>
160-
2. The Mighty Dictionary - <https://www.youtube.com/watch?v=oMyy4Sm0uBs>
158+
1. [The Dictionary Even Mightier](https://www.youtube.com/watch?v=66P5FMkWoVU)
159+
160+
161+
2. [The Mighty Dictionary](https://www.youtube.com/watch?v=oMyy4Sm0uBs)
161162
""")
162163
else:
163164
dict_def = ''

superhelp/helpers/for_help.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ def for_else(block_dets, *, repeat=False, **_kwargs):
247247
extra_msg = layout("""\
248248
#### Interesting discussion on `for`-`else`
249249
250-
<https://nedbatchelder.com/blog/201110/forelse.html>
250+
[For/else](https://nedbatchelder.com/blog/201110/forelse.html)
251251
One comment noted that the construct violates the principle of Least
252252
Astonishment.
253253
""")

superhelp/helpers/import_help.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ def internal_imports(blocks_dets, *, repeat=False, **_kwargs):
122122
Note – other modules you don’t want to run directly can continue to use
123123
relative importing – even if they are imported (absolutely) from modules you
124124
will be running directly as scripts.
125+
126+
[Python Modules and Packages – An Introduction](https://realpython.com/python-modules-packages/)
125127
""")
126128

127129
message = {

0 commit comments

Comments
 (0)