Skip to content

Commit 5809080

Browse files
committed
makefile updates, better comments in feed-thru-cherry-picks.sh
1 parent 998caf8 commit 5809080

File tree

4 files changed

+130
-80
lines changed

4 files changed

+130
-80
lines changed

Makefile

Lines changed: 89 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -26,132 +26,151 @@ part%.forbook.asciidoc: part%.asciidoc
2626
> $@
2727

2828

29+
30+
.PHONY: oreilly.%.asciidoc
31+
oreilly.%.asciidoc: %.asciidoc
32+
$(RUN_OREILLY_FLAVOURED_ASCIIDOCTOR) $(subst oreilly.,,$@)
33+
2934
book.html: part1.forbook.asciidoc
3035
book.html: part2.forbook.asciidoc
3136
book.html: part3.forbook.asciidoc
3237
book.html: $(SOURCES)
3338

39+
40+
%.html: %.asciidoc # build an individual chapter's html page
41+
$(RUN_ASCIIDOCTOR) $<
42+
3443
.PHONY: build
3544
build: $(HTML_PAGES) $(TMPDIR)
3645

46+
47+
MKVENV := $(shell which uv && "uv venv" || "python3 -m venv")
48+
MKVENV := $(shell which uv && "uv venv" || "python3 -m venv")
49+
50+
.venv/bin:
51+
which uv && uv venv .venv || python -m venv .venv
52+
which uv && uv pip install -e . || .venv/bin/pip install -e .
53+
54+
.PHONY: install
55+
install: .venv/bin
56+
57+
.PHONY: update-submodules
58+
update-submodules:
59+
git submodule update --init --recursive
60+
.venv/bin/python tests/update_source_repo.py
61+
62+
# this is to allow for a git remote called "local" for eg ./source/feed-thru-cherry-pick.sh
63+
../book-example.git:
64+
mkdir -p ../book-example.git
65+
git init --bare ../book-example.git
66+
3767
.PHONY: test
38-
test: build
39-
git submodule init
40-
python tests/update_source_repo.py
41-
pytest --tb=short --color=yes tests/
68+
test: build update-submodules .venv/bin
69+
.venv/bin/pytest --tb=short --color=yes tests/
4270

4371
.PHONY: testall
4472
testall: build
45-
pytest --tb=short --color=yes --numprocesses=auto tests/test_chapter_*
73+
.venv/bin/pytest --tb=short --color=yes --numprocesses=auto tests/test_chapter_*
4674

4775
.PHONY: testall4
4876
testall4: build
49-
pytest --tb=short --color=yes --numprocesses=4 tests/test_chapter_*
50-
51-
%.html: %.asciidoc
52-
$(RUN_ASCIIDOCTOR) $<
53-
54-
.PHONY: oreilly.%.asciidoc
55-
oreilly.%.asciidoc: %.asciidoc
56-
$(RUN_OREILLY_FLAVOURED_ASCIIDOCTOR) $(subst oreilly.,,$@)
77+
.venv/bin/pytest --tb=short --color=yes --numprocesses=4 tests/test_chapter_*
5778

5879

5980
.PHONY: test_%
6081
test_%: %.html $(TMPDIR)
61-
pytest -s --tb=short ./tests/$@.py
82+
.venv/bin/pytest -s --tb=short ./tests/$@.py
6283

6384
# exhaustively list for nice tab-completion
6485
#
6586
.PHONY: test_chapter_01
66-
test_chapter_01: chapter_01.html $(TMPDIR)
67-
pytest -s --tb=short ./tests/test_chapter_01.py
87+
test_chapter_01: chapter_01.html $(TMPDIR) .venv/bin
88+
.venv/bin/pytest -s --tb=short ./tests/test_chapter_01.py
6889
.PHONY: test_chapter_02_unittest
69-
test_chapter_02_unittest: chapter_02_unittest.html $(TMPDIR)
70-
pytest -s --tb=short ./tests/test_chapter_02_unittest.py
90+
test_chapter_02_unittest: chapter_02_unittest.html $(TMPDIR) .venv/bin
91+
.venv/bin/pytest -s --tb=short ./tests/test_chapter_02_unittest.py
7192
.PHONY: test_chapter_03_unit_test_first_view
72-
test_chapter_03_unit_test_first_view: chapter_03_unit_test_first_view.html $(TMPDIR)
73-
pytest -s --tb=short ./tests/test_chapter_03_unit_test_first_view.py
93+
test_chapter_03_unit_test_first_view: chapter_03_unit_test_first_view.html $(TMPDIR) .venv/bin
94+
.venv/bin/pytest -s --tb=short ./tests/test_chapter_03_unit_test_first_view.py
7495
.PHONY: test_chapter_04_philosophy_and_refactoring
75-
test_chapter_04_philosophy_and_refactoring: chapter_04_philosophy_and_refactoring.html $(TMPDIR)
76-
pytest -s --tb=short ./tests/test_chapter_04_philosophy_and_refactoring.py
96+
test_chapter_04_philosophy_and_refactoring: chapter_04_philosophy_and_refactoring.html $(TMPDIR) .venv/bin
97+
.venv/bin/pytest -s --tb=short ./tests/test_chapter_04_philosophy_and_refactoring.py
7798
.PHONY: test_chapter_05_post_and_database
78-
test_chapter_05_post_and_database: chapter_05_post_and_database.html $(TMPDIR)
79-
pytest -s --tb=short ./tests/test_chapter_05_post_and_database.py
99+
test_chapter_05_post_and_database: chapter_05_post_and_database.html $(TMPDIR) .venv/bin
100+
.venv/bin/pytest -s --tb=short ./tests/test_chapter_05_post_and_database.py
80101
.PHONY: test_chapter_06_explicit_waits_1
81-
test_chapter_06_explicit_waits_1: chapter_06_explicit_waits_1.html $(TMPDIR)
82-
pytest -s --tb=short ./tests/test_chapter_06_explicit_waits_1.py
102+
test_chapter_06_explicit_waits_1: chapter_06_explicit_waits_1.html $(TMPDIR) .venv/bin
103+
.venv/bin/pytest -s --tb=short ./tests/test_chapter_06_explicit_waits_1.py
83104
.PHONY: test_chapter_07_working_incrementally
84-
test_chapter_07_working_incrementally: chapter_07_working_incrementally.html $(TMPDIR)
85-
pytest -s --tb=short ./tests/test_chapter_07_working_incrementally.py
105+
test_chapter_07_working_incrementally: chapter_07_working_incrementally.html $(TMPDIR) .venv/bin
106+
.venv/bin/pytest -s --tb=short ./tests/test_chapter_07_working_incrementally.py
86107
.PHONY: test_chapter_08_prettification
87-
test_chapter_08_prettification: chapter_08_prettification.html $(TMPDIR)
88-
pytest -s --tb=short ./tests/test_chapter_08_prettification.py
108+
test_chapter_08_prettification: chapter_08_prettification.html $(TMPDIR) .venv/bin
109+
.venv/bin/pytest -s --tb=short ./tests/test_chapter_08_prettification.py
89110
.PHONY: test_chapter_09_docker
90-
test_chapter_09_docker: chapter_09_docker.html $(TMPDIR)
91-
pytest -s --tb=short ./tests/test_chapter_09_docker.py
111+
test_chapter_09_docker: chapter_09_docker.html $(TMPDIR) .venv/bin
112+
.venv/bin/pytest -s --tb=short ./tests/test_chapter_09_docker.py
92113
.PHONY: test_chapter_10_production_readiness
93-
test_chapter_10_production_readiness: chapter_10_production_readiness.html $(TMPDIR)
94-
pytest -s --tb=short ./tests/test_chapter_10_production_readiness.py
114+
test_chapter_10_production_readiness: chapter_10_production_readiness.html $(TMPDIR) .venv/bin
115+
.venv/bin/pytest -s --tb=short ./tests/test_chapter_10_production_readiness.py
95116
.PHONY: test_chapter_11_ansible
96-
test_chapter_11_ansible: chapter_11_ansible.html $(TMPDIR)
97-
pytest -s --tb=short ./tests/test_chapter_11_ansible.py
117+
test_chapter_11_ansible: chapter_11_ansible.html $(TMPDIR) .venv/bin
118+
.venv/bin/pytest -s --tb=short ./tests/test_chapter_11_ansible.py
98119
.PHONY: test_chapter_12_organising_test_files
99-
test_chapter_12_organising_test_files: chapter_12_organising_test_files.html $(TMPDIR)
100-
pytest -s --tb=short ./tests/test_chapter_12_organising_test_files.py
120+
test_chapter_12_organising_test_files: chapter_12_organising_test_files.html $(TMPDIR) .venv/bin
121+
.venv/bin/pytest -s --tb=short ./tests/test_chapter_12_organising_test_files.py
101122
.PHONY: test_chapter_13_database_layer_validation
102-
test_chapter_13_database_layer_validation: chapter_13_database_layer_validation.html $(TMPDIR)
103-
pytest -s --tb=short ./tests/test_chapter_13_database_layer_validation.py
123+
test_chapter_13_database_layer_validation: chapter_13_database_layer_validation.html $(TMPDIR) .venv/bin
124+
.venv/bin/pytest -s --tb=short ./tests/test_chapter_13_database_layer_validation.py
104125
.PHONY: test_chapter_14_simple_form
105-
test_chapter_14_simple_form: chapter_14_simple_form.html $(TMPDIR)
106-
pytest -s --tb=short ./tests/test_chapter_14_simple_form.py
126+
test_chapter_14_simple_form: chapter_14_simple_form.html $(TMPDIR) .venv/bin
127+
.venv/bin/pytest -s --tb=short ./tests/test_chapter_14_simple_form.py
107128
.PHONY: test_chapter_15_advanced_forms
108-
test_chapter_15_advanced_forms: chapter_15_advanced_forms.html $(TMPDIR)
109-
pytest -s --tb=short ./tests/test_chapter_15_advanced_forms.py
129+
test_chapter_15_advanced_forms: chapter_15_advanced_forms.html $(TMPDIR) .venv/bin
130+
.venv/bin/pytest -s --tb=short ./tests/test_chapter_15_advanced_forms.py
110131
.PHONY: test_chapter_javascript
111-
test_chapter_javascript: chapter_javascript.html $(TMPDIR)
112-
pytest -s --tb=short ./tests/test_chapter_javascript.py
132+
test_chapter_javascript: chapter_javascript.html $(TMPDIR) .venv/bin
133+
.venv/bin/pytest -s --tb=short ./tests/test_chapter_javascript.py
113134
.PHONY: test_chapter_deploying_validation
114-
test_chapter_deploying_validation: chapter_deploying_validation.html $(TMPDIR)
115-
pytest -s --tb=short ./tests/test_chapter_deploying_validation.py
135+
test_chapter_deploying_validation: chapter_deploying_validation.html $(TMPDIR) .venv/bin
136+
.venv/bin/pytest -s --tb=short ./tests/test_chapter_deploying_validation.py
116137
.PHONY: test_chapter_spiking_custom_auth
117-
test_chapter_spiking_custom_auth: chapter_spiking_custom_auth.html $(TMPDIR)
118-
pytest -s --tb=short ./tests/test_chapter_spiking_custom_auth.py
138+
test_chapter_spiking_custom_auth: chapter_spiking_custom_auth.html $(TMPDIR) .venv/bin
139+
.venv/bin/pytest -s --tb=short ./tests/test_chapter_spiking_custom_auth.py
119140
.PHONY: test_chapter_mocking
120-
test_chapter_mocking: chapter_mocking.html $(TMPDIR)
121-
pytest -s --tb=short ./tests/test_chapter_mocking.py
141+
test_chapter_mocking: chapter_mocking.html $(TMPDIR) .venv/bin
142+
.venv/bin/pytest -s --tb=short ./tests/test_chapter_mocking.py
122143
.PHONY: test_chapter_fixtures_and_wait_decorator
123-
test_chapter_fixtures_and_wait_decorator: chapter_fixtures_and_wait_decorator.html $(TMPDIR)
124-
pytest -s --tb=short ./tests/test_chapter_fixtures_and_wait_decorator.py
144+
test_chapter_fixtures_and_wait_decorator: chapter_fixtures_and_wait_decorator.html $(TMPDIR) .venv/bin
145+
.venv/bin/pytest -s --tb=short ./tests/test_chapter_fixtures_and_wait_decorator.py
125146
.PHONY: test_chapter_server_side_debugging
126-
test_chapter_server_side_debugging: chapter_server_side_debugging.html $(TMPDIR)
127-
pytest -s --tb=short ./tests/test_chapter_server_side_debugging.py
147+
test_chapter_server_side_debugging: chapter_server_side_debugging.html $(TMPDIR) .venv/bin
148+
.venv/bin/pytest -s --tb=short ./tests/test_chapter_server_side_debugging.py
128149
.PHONY: test_chapter_outside_in
129-
test_chapter_outside_in: chapter_outside_in.html $(TMPDIR)
130-
pytest -s --tb=short ./tests/test_chapter_outside_in.py
150+
test_chapter_outside_in: chapter_outside_in.html $(TMPDIR) .venv/bin
151+
.venv/bin/pytest -s --tb=short ./tests/test_chapter_outside_in.py
131152
.PHONY: test_chapter_purist_unit_tests
132-
test_chapter_purist_unit_tests: chapter_purist_unit_tests.html $(TMPDIR)
133-
pytest -s --tb=short ./tests/test_chapter_purist_unit_tests.py
153+
test_chapter_purist_unit_tests: chapter_purist_unit_tests.html $(TMPDIR) .venv/bin
154+
.venv/bin/pytest -s --tb=short ./tests/test_chapter_purist_unit_tests.py
134155
.PHONY: test_chapter_CI
135-
test_chapter_CI: chapter_CI.html $(TMPDIR)
136-
pytest -s --tb=short ./tests/test_chapter_CI.py
156+
test_chapter_CI: chapter_CI.html $(TMPDIR) .venv/bin
157+
.venv/bin/pytest -s --tb=short ./tests/test_chapter_CI.py
137158
.PHONY: test_chapter_page_pattern
138-
test_chapter_page_pattern: chapter_page_pattern.html $(TMPDIR)
139-
pytest -s --tb=short ./tests/test_chapter_page_pattern.py
159+
test_chapter_page_pattern: chapter_page_pattern.html $(TMPDIR) .venv/bin
160+
.venv/bin/pytest -s --tb=short ./tests/test_chapter_page_pattern.py
140161

141162

142163

143164
.PHONY: silent_test_%
144-
silent_test_%: %.html $(TMPDIR)
145-
pytest --tb=short ./tests/$(subst silent_,,$@).py
165+
silent_test_%: %.html $(TMPDIR) .venv/bin
166+
.venv/bin/pytest --tb=short ./tests/$(subst silent_,,$@).py
146167

147168
.PHONY: unit-test
148-
unit-test: chapter_01.html
169+
unit-test: chapter_01.html .venv/bin
149170
SKIP_CHAPTER_SUBMODULES=1 ./tests/update_source_repo.py
150-
./run_test_tests.sh
171+
source .venv/bin/activate && ./run_test_tests.sh
151172

152173
.PHONY: clean
153174
clean:
154175
rm -rf $(TMPDIR)
155176
rm -v $(HTML_PAGES)
156-
157-
.PHONY = test clean test_chapter_%

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,15 @@ $ make test
4242
$ make test_chapter_06_explicit_waits_1
4343
```
4444

45+
If you see a problem that seems to be related to submodules, try:
46+
47+
```console
48+
make update-submodules
49+
```
50+
51+
4552
* Unit tests (tests for the tests for the tests in the testing book)
53+
4654
```console
4755
$ ./run_test_tests.sh
4856
```

run_test_tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
PYTHONHASHSEED=0 py.test \
2+
PYTHONHASHSEED=0 pytest \
33
--failed-first \
44
--tb=short \
55
-k 'not test_listings_and_commands_and_output' \

source/feed-thru-cherry-picks.sh

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,45 @@
11
#!/bin/bash
2+
# replay all the commits for a given chapter ($CHAP)
3+
# onto the latest version of the previous chapter ($PREV)
24
set -e
35

46
PREV=$1
57
CHAP=$2
68

7-
# assumes a git remote local pointing at a local bare repo...
9+
# assumes a git remote called "local" (eg pointing at a local bare repo...)
10+
# rather than using origin/github,
11+
# this allows us to feed through changes without pushing to github
812
REPO=local
913

10-
cd $CHAP/superlists
14+
cd "$CHAP/superlists"
1115

12-
git checkout $PREV
13-
git reset --hard $REPO/$PREV
16+
# determine the commit we want to start from,
17+
# which is the last commit of the $PREV branch as it was *before* our new version.
18+
# We assume that the repo version in $CHAP/superlists has *not* got this latest version yet.
19+
# (so that's why we don't do the git fetch until after this step)
20+
START_COMMIT="$(git rev-list -n 1 "$REPO/$PREV")"
21+
CHAP_COMMIT_LIST="$START_COMMIT..$REPO/$CHAP"
1422

15-
git fetch $REPO
16-
git checkout $CHAP
17-
git reset --hard $REPO/$PREV
23+
# check START_COMMIT exists in $CHAP branch's history
24+
# https://stackoverflow.com/a/4129070/366221
25+
if [ "$(git merge-base "$START_COMMIT" "$CHAP")" != "$START_COMMIT" ]; then
26+
echo "Error: $START_COMMIT is not in the history of $CHAP"
27+
exit 1
28+
fi
1829

19-
git cherry-pick -Xrename-threshold=20% $PREV..$REPO/$CHAP
20-
git diff -w $REPO/$CHAP
30+
# now we pull down the latest version of $PREV
31+
git fetch "$REPO"
32+
33+
# reset our chapter to the new version of the end of $PREV
34+
git checkout "$CHAP"
35+
git reset --hard "$REPO/$PREV"
36+
37+
# now cherry pick all the old commits from $CHAP onto this new base.
38+
# (we can't just use rebase because it does the wrong thing with trying to find common history)
39+
git cherry-pick -Xrename-threshold=20% "$CHAP_COMMIT_LIST"
40+
41+
42+
# display a little diff to sanity-check what we've done.
43+
git diff -w "$REPO/$CHAP"
2144

2245
cd ../..

0 commit comments

Comments
 (0)