Skip to content

Commit 0f9f375

Browse files
committed
improving docs html
1 parent d4903d5 commit 0f9f375

13 files changed

Lines changed: 69 additions & 60 deletions

File tree

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ install:
1818
script:
1919
- make lint
2020
- make test
21+
- make docs
2122
- ./tests/check_tag.py
2223

2324
after_success:

HISTORY.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ v0.3.0 (2017-10-11)
77
...................
88
* allow ``async/await`` arguments
99
* fix subscript
10-
* fix weird named tuples eg ``mock > call_args``
10+
* fix weird named tuples eg. ``mock > call_args``
1111

1212
v0.2.0 (2017-09-14)
1313
...................

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,6 @@ docs:
5858
.PHONY: publish
5959
publish: docs
6060
cd docs/_build/ && cp -r html site && zip -r site.zip site
61-
@curl -H "Content-Type: application/zip" -H "Authorization: Bearer ${NETLIFY}" \
61+
@curl -i -H "Content-Type: application/zip" -H "Authorization: Bearer ${NETLIFY}" \
6262
--data-binary "@docs/_build/site.zip" https://api.netlify.com/api/v1/sites/python-devtools.netlify.com/deploys
63+
@echo " "

devtools/debug.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,12 @@
99
from typing import Generator, List, Optional, Tuple, Type
1010

1111
from .ansi import isatty, sformat
12-
from .prettier import PrettyFormat
12+
from .prettier import PrettyFormat, env_true
1313

1414
__all__ = ['Debug', 'debug']
1515
CWD = Path('.').resolve()
1616

1717

18-
def env_true(var_name, alt=None):
19-
env = os.getenv(var_name, None)
20-
if env:
21-
return env.upper() in {'1', 'TRUE'}
22-
else:
23-
return alt
24-
25-
2618
pformat = PrettyFormat(
2719
indent_step=int(os.getenv('PY_DEVTOOLS_INDENT', 4)),
2820
simple_cutoff=int(os.getenv('PY_DEVTOOLS_SIMPLE_CUTOFF', 10)),

devtools/prettier.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import collections
22
import io
3+
import os
34
import textwrap
45
from typing import Any, Generator, Union
56

@@ -22,6 +23,14 @@
2223
__all__ = ['PrettyFormat', 'pformat', 'pprint']
2324

2425

26+
def env_true(var_name, alt=None):
27+
env = os.getenv(var_name, None)
28+
if env:
29+
return env.upper() in {'1', 'TRUE'}
30+
else:
31+
return alt
32+
33+
2534
class PrettyFormat:
2635
def __init__(self,
2736
indent_step=4,
@@ -168,7 +177,9 @@ def _format_raw(self, value: Any, value_repr: str, indent_current: int, indent_n
168177

169178

170179
pformat = PrettyFormat()
180+
force_highlight = env_true('PY_DEVTOOLS_HIGHLIGHT', None)
171181

172182

173183
def pprint(s, file=None):
174-
print(pformat(s, highlight=isatty(file)), file=file, flush=True)
184+
highlight = isatty(file) if force_highlight is None else force_highlight
185+
print(pformat(s, highlight=highlight), file=file, flush=True)

docs/Makefile

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,7 @@ clean:
1515

1616
.PHONY: doc-examples
1717
doc-examples:
18-
@( echo '<pre class="ansi2html-content">'; \
19-
PY_DEVTOOLS_HIGHLIGHT=true python examples/1_input.py | ansi2html -p; \
20-
echo '</pre>' ) > examples/1_output.html
21-
@( echo '<pre class="ansi2html-content">'; \
22-
PY_DEVTOOLS_HIGHLIGHT=true python examples/2_input.py | ansi2html -p; \
23-
echo '</pre>' ) > examples/2_output.html
18+
./gen_html.py
2419

2520
.PHONY: html
2621
html: clean doc-examples

docs/_templates/layout.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22

33
{% block extrahead %}
44
<style>
5+
.divider {
6+
text-align: center;
7+
font-weight: bold;
8+
margin: -12px;
9+
}
510
.ansi2html-content {
611
white-space: pre-wrap;
712
word-wrap: break-word;
813
line-height: normal;
914
background-color: #300a24;
1015
padding: 20px 30px;
16+
color: white;
1117
}
1218
.body_foreground { color: #AAAAAA; }
1319
.body_background { background-color: #000000; }

docs/examples/prettier.py

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,12 @@
66
'generator': (i * 2 for i in [1, 2, 3]),
77
}
88

9+
# pretty print of v
910
pprint(v)
10-
# > with colours:
11-
"""
12-
{
13-
'foo': {
14-
'whatever': [3, 2, 1],
15-
},
16-
'sentence': (
17-
'hello\n'
18-
'world'
19-
),
20-
'generator': (
21-
2,
22-
4,
23-
6,
24-
),
25-
}
26-
"""
2711

12+
# as above without colours, the generator will also be empty as it's already been evaluated
2813
s = pformat(v, highlight=False)
2914
print(s)
30-
# > as above without colours, the generator will also be empty as it's already been evaluated
3115

3216
pp = PrettyFormat(
3317
indent_step=2, # default: 4
@@ -38,18 +22,4 @@
3822
yield_from_generators=False # default: True (whether to evaluate generators)
3923
)
4024

41-
print(pp(v))
42-
# >
43-
"""
44-
{
45-
__'foo': {
46-
____'whatever': [
47-
______'apple',
48-
______123,
49-
______45.67,
50-
____],
51-
__},
52-
__'sentence': 'hello\nworld',
53-
__'generator': <generator object <genexpr> at 0x7f448b7cebf8>,
54-
}
55-
"""
25+
print(pp(v, highlight=True))

0 commit comments

Comments
 (0)