5.3 A report of the corpus
Build it yourself. Read the tutorial is the other way to read this part.
This part does not start where the part before it ends, because the walk skips some changes. This command puts the files that this part starts from in place of yours. Run it, and then go on:
git restore --source f79588d3b046 --staged -- :/ && git restore --source c4b92c9bd158 --staged --worktree -- :/If you start at this part, make your clone as Get the project says, and then run this command. It puts in your clone the files that this part starts from. A file that the project deleted before this part stays, so delete it if git check lists it:
git rm -rq --cached --ignore-unmatch -- :/ && git restore --source c4b92c9bd158 --staged --worktree -- :/just setupSince the last part, the walk leaves out the function top, its test, and the option --top. This part begins
with their code.
The code before this part. The code after it.
5.3 A report, which just setup makes
The most common words of the corpus make a report, which others want to read without running tally. A recipe of
the justfile, report, writes the ten most common words to build/top.txt. The recipe has two lines, and just
prints each line before it runs it. The second line has two parts.
mkdir -p buildmakes the folderbuild, and does nothing when the folder is there.uv run tally --top 10 data/corpus.txtcounts the corpus, and keeps the ten most common words.> build/top.txtsends what tally prints to the file, in place of the terminal.
Apply the patch to justfile, from the top of the project:
curl -fsSL https://github.com/rahuldave/tally/commit/9e37b6eed29516f62bc176d1eaa66bf4e86683a6.diff | git apply --include=justfileThe patch adds the recipe report at the end of the justfile.
The report is an artifact, as the corpus is. git ignores the folder build/, so git holds the recipe, and not the
report. just setup makes the report when the file is missing. test -f build/top.txt is true when the file is
there, and || runs just report only when it is not.
The same patch adds a line to the recipe setup, after the line that makes the corpus.
A report from an earlier run stays, because git ignores it. So remove the report first, and then just setup makes
it again:
rm -f build/top.txt
just setup
cat build/top.txtThe file has ten lines, the most common word first.
Open build/top.txt, and compare it with what uv run tally --top 10 data/corpus.txt prints.
tally is now finished. It counts, it has tests and types, and just setup makes its report.
Check your files against this move. The command prints nothing when they match, and otherwise shows what differs:
git check 9e37b6eed295If you are stuck, this command puts the files of this move in place of yours. A file that you made yourself stays:
git restore --source c4b92c9bd158 --staged -- :/ && git restore --source 9e37b6eed295 --staged --worktree -- :/What changed
justfile: the report, and the line insetupthat makes it when it is missing. 6 lines added. The file.- look at
uv run tally --top 10 data/corpus.txt > build/top.txt - look at
test -f build/top.txt || just report
- look at
The patch to justfile
@@ -6,6 +6,7 @@ default:
setup:
uv sync
uv run python scripts/corpus.py data/corpus.txt
+ test -f build/top.txt || just report
# Count the words of a file
run file:
@@ -14,3 +15,8 @@ run file:
# Run the tests
test:
uv run python -m unittest discover -s tests -q
+
+# Write the ten most common words of the corpus to build/top.txt
+report:
+ mkdir -p build
+ uv run tally --top 10 data/corpus.txt > build/top.txt