@@ -11,7 +11,7 @@ when you can access a nicely formatted version of the full thing, still free
11
11
and under CC license. And you'll also be able to buy an ebook or print version
12
12
if you feel like it.*
13
13
14
- These sources are being made available for the purposes of curiosity
14
+ These sources are being made available for the purposes of curiosity
15
15
(although if you're curious about the way the listings are tested,
16
16
i would definitely recommend https://github.com/cosmicpython/book instead)
17
17
and collaboration (typo-fixes by pull request are very much encouraged!).
@@ -27,17 +27,19 @@ and collaboration (typo-fixes by pull request are very much encouraged!).
27
27
# Running the tests
28
28
29
29
* Pre-requisites for the test suite:
30
- ``` console
31
- $ pip install .
32
- $ git submodule update --init
30
+
31
+ ``` console
32
+ make install
33
33
```
34
34
35
- * Full test suite:
35
+ * Full test suite (probably, don't use this, it would take ages.)
36
+
36
37
``` console
37
38
$ make test
38
39
```
39
40
40
41
* To test an individual chapter, eg:
42
+
41
43
``` console
42
44
$ make test_chapter_06_explicit_waits_1
43
45
```
@@ -58,3 +60,92 @@ $ ./run_test_tests.sh
58
60
# Windows / WSL notes
59
61
60
62
* ` vagrant plugin install virtualbox_WSL2 ` is required
63
+
64
+
65
+ # Making changes to the book's code examples
66
+
67
+ Brief explanation: each chapter's code examples are reflected in a branch of the example code repository,
68
+ https://github.com/hjwp/book-example
69
+ in branches named after the chapter, so eg chapter_02_unittest.asciidoc has a branch called chapter_02_unittest.
70
+
71
+ These branches are actually checked out, one by one, as submodules in source/<chapter-name >/superlists.
72
+ Each branch starts at the end of the previous chapter's branch.
73
+
74
+ Code listings _ mostly_ map 1 to 1 with commits in the repo,
75
+ and they are sometimes marked with little tags, eg ch03l007,
76
+ meaning theoretically, the 7th listing in chapter 3, but that's not always accurate.
77
+
78
+ When the tests run, they start by creating a new folder in /tmp
79
+ checked out with the code from the end of the last chapter.
80
+
81
+ Then they go through the code listings in the book one by one,
82
+ and simulate typing them into to an editor.
83
+ If the code listing has one of those little tags,
84
+ the tests check the commit in the repo to see if the listing matches the commit exactly.
85
+ (if there's no tag, there's some fiddly code based on string manipulation
86
+ that tries to figure out how to insert the code listing into the existing file contents at the right place)
87
+
88
+ When the tests come across a command, eg "ls",
89
+ they actually run "ls" in the temp directory,
90
+ to check whether the output that's printed in the book matches what would actually happen.
91
+
92
+ One of the most common commands is to run the tests, obviously,
93
+ so much so that if there is some console output in the book with no explicit command,
94
+ the tests assume it's a test run, so they run "./manage.py test" or equivalent.
95
+
96
+ In any case, back to our code listings - the point is that,
97
+ if we want to change one of our code listings, we also need to change the commit in the branch / submodule...
98
+
99
+ ...and all of the commits that come after it.
100
+
101
+ ...for that chapter and every subsequent chapter.
102
+
103
+
104
+ This is called "feeding through the changes"
105
+
106
+
107
+ ## Changing a code listing
108
+
109
+ 1 . change the listing in the book, eg in in _ chapter_03_unit_test_first_view.asciidoc_
110
+ 2 . open up ./source/chapter_03_unit_test_first_view/superlists in a terminal
111
+ 3 . do a ` git rebase --interactive $previous-chapter-name `
112
+ 4 . identify the commit that matches the listing that you've changed, and mark it for ` edit `
113
+ 5 . edit the file when prompted, make it match the book
114
+ 6 . continue the rebase, and deal with an merge conflicts as you go, woo.
115
+ 7 . ` git push local ` once you're happy.
116
+
117
+ ## feeding thru the changes
118
+
119
+ Because we don't want to push WIP to github every time we change a chapter,
120
+ we use a local bare repository to push and pull chapters
121
+
122
+
123
+ ``` console
124
+ make ../book-example.git
125
+ ```
126
+
127
+ will create it for you.
128
+
129
+ TODO: helper to do ` git remote add local ` to each chapter/submodule
130
+
131
+ Now you can attempt to feed thru the latest changes to this branch/chapter with
132
+
133
+ ``` console
134
+ cd source
135
+ ./feed_thru.sh chapter_03_unit_test_first_view chapter_04_philosophy_and_refactoring
136
+ # chapter/branch names will tab complete, helpfully.
137
+ ```
138
+
139
+ if all goes well, you can then run
140
+
141
+ ``` console
142
+ ./push-back.sh chapter_04_philosophy_and_refactoring
143
+ ```
144
+
145
+ and move on to the next chapter. woo!
146
+
147
+
148
+ This may all seem a bit OTT,
149
+ but the point is that if we change a variable early on in the book,
150
+ git (along with the tests) will help us to make sure that it changes
151
+ all the way through all the subsequent chapters.
0 commit comments