Skip to content

Commit 9a9ff92

Browse files
committed
I'm tired and not remembering what I changed but I also don't want to just keep saying 'tweaks'
1 parent af22bb6 commit 9a9ff92

File tree

5 files changed

+49
-27
lines changed

5 files changed

+49
-27
lines changed

app/__main__.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Module for building and build-time QA of the python tutorial website"""
1+
"""Module for building and build-time QA of the python tutorial codeblocks"""
22
import inspect
33
import json
44
from os import makedirs
@@ -13,7 +13,9 @@
1313
first_steps,
1414
first_projects,
1515
variables,
16-
)
16+
)
17+
18+
OUTPUT_DIR = "dist"
1719

1820

1921
def run_build_checks():
@@ -33,13 +35,20 @@ def main():
3335
"""
3436
Perform all of the actions necessary to output the python tutorial codeblocks
3537
"""
38+
print()
3639
run_build_checks()
37-
makedirs('dist', exist_ok=True)
38-
with open('dist/codeblocks.json', 'w', encoding='utf-8') as f:
39-
json.dump(get_func_body, f)
40+
print()
41+
makedirs(OUTPUT_DIR, exist_ok=True)
42+
with open(f'{OUTPUT_DIR}/codeblocks.json', 'w', encoding='utf-8') as f:
43+
codeblock_map = {}
4044
for module in PAGE_MODULES:
41-
for fn_name, fn in inspect.getmembers(module):
42-
print(fn_name, fn)
45+
nonlocals = getattr(module, "NONLOCALS", ())
46+
print(f"extracting from {module.__name__}:")
47+
for member_name, member in inspect.getmembers(module, inspect.isfunction):
48+
if member_name not in nonlocals:
49+
print(" ", member_name)
50+
codeblock_map[member_name] = get_func_body(member)
51+
json.dump(codeblock_map, f)
4352

4453

4554
if __name__ == '__main__':

app/pages/first_projects.py

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
1+
"""11_first_projects.md"""
12
from unittest.mock import patch
23
# pylint: disable=line-too-long
34
# pylint: disable=redefined-builtin
45
# pylint: disable=import-outside-toplevel
56

67

8+
NONLOCALS = ("patch",)
9+
10+
711
def random_numbers():
8-
"""
9-
>>> import random
10-
>>> random.seed(1)
11-
>>> random_numbers()
12-
18
13-
73
14-
98
15-
9
16-
33
17-
16
18-
64
19-
98
20-
58
21-
61
22-
"""
23-
import random
24-
25-
for _ in range(10):
26-
print(random.randint(1, 100))
12+
"""
13+
>>> import random
14+
>>> random.seed(1)
15+
>>> random_numbers()
16+
18
17+
73
18+
98
19+
9
20+
33
21+
16
22+
64
23+
98
24+
58
25+
61
26+
"""
27+
import random
28+
29+
for _ in range(10):
30+
print(random.randint(1, 100))
2731

2832

2933
def guessing_game(mocked_input_se):
@@ -51,6 +55,7 @@ def guessing_game(mocked_input_se):
5155
# END
5256

5357

58+
# pylint: disable=redefined-outer-name
5459
def argv():
5560
"""
5661
>>> import sys
@@ -66,6 +71,7 @@ def argv():
6671
# caution!
6772
# the below line will fail if at least 2 arguments aren't passed in to the program!
6873
print(argv[1], argv[2])
74+
# pylint: enable=redefined-outer-name
6975

7076

7177
def file_io():

app/pages/first_steps.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
"""10_first_steps.md"""
12
from unittest.mock import patch
23
# pylint: disable=line-too-long
34
# pylint: disable=redefined-builtin
45

56

7+
NONLOCALS = ("patch",)
8+
9+
610
def hello_world():
711
"""
812
>>> hello_world()

app/pages/variables.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
# pylint: disable=redefined-builtin
44

55

6+
NONLOCALS = ("patch",)
7+
8+
69
def variables_assignments():
710
"""
811
>>> variables_assignments()

app/qa.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def _test(self):
3131
def test(self, *args, **kwargs):
3232
"""Universal test logic"""
3333
test_result = self._test(*args, **kwargs)
34-
print(f'\nTesting {self.name or self}')
34+
print(f'Testing {self.name or self}')
3535

3636
if not test_result.passed: # only take action on failures
3737
print(' - Fail!')

0 commit comments

Comments
 (0)