Skip to content

Commit

Permalink
Merge pull request #106 from akleinhesselink/gh-pages
Browse files Browse the repository at this point in the history
Better motivate archive creation in final exercise.

Fix #105.
  • Loading branch information
gcapes authored Oct 5, 2017
2 parents d041ed5 + 588b640 commit f33e9f0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
14 changes: 8 additions & 6 deletions code/09-conclusion-challenge-2/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
include config.mk

TXT_FILES=$(wildcard books/*.txt)
DAT_FILES=$(patsubst books/%.txt, %.dat, $(TXT_FILES))
PNG_FILES=$(patsubst books/%.txt, %.png, $(TXT_FILES))
TXT_DIR=books
TXT_FILES=$(wildcard $(TXT_DIR)/*.txt)
DAT_FILES=$(patsubst $(TXT_DIR)/%.txt, %.dat, $(TXT_FILES))
PNG_FILES=$(patsubst $(TXT_DIR)/%.txt, %.png, $(TXT_FILES))
RESULTS_FILE=results.txt
ZIPF_DIR=zipf_analysis
ZIPF_ARCHIVE=$(ZIPF_DIR).tar.gz
Expand All @@ -15,10 +16,10 @@ $(ZIPF_ARCHIVE) : $(ZIPF_DIR)
tar -czf $@ $<

$(ZIPF_DIR): Makefile config.mk $(RESULTS_FILE) \
$(DAT_FILES) $(PNG_FILES) \
$(DAT_FILES) $(PNG_FILES) $(TXT_DIR) \
$(COUNT_SRC) $(PLOT_SRC) $(ZIPF_SRC)
mkdir -p $@
cp $^ $@
cp -r $^ $@
touch $@

## results.txt : Generate Zipf summary table.
Expand All @@ -29,7 +30,7 @@ $(RESULTS_FILE) : $(DAT_FILES) $(ZIPF_SRC)
.PHONY : dats
dats : $(DAT_FILES)

%.dat : books/%.txt $(COUNT_SRC)
%.dat : $(TXT_DIR)/%.txt $(COUNT_SRC)
$(COUNT_EXE) $< $@

## pngs : Plot word counts.
Expand All @@ -51,6 +52,7 @@ clean :
## variables : Print variables.
.PHONY : variables
variables:
@echo TXT_DIR: $(TXT_DIR)
@echo TXT_FILES: $(TXT_FILES)
@echo DAT_FILES: $(DAT_FILES)
@echo PNG_FILES: $(PNG_FILES)
Expand Down
31 changes: 23 additions & 8 deletions episodes/09-conclusion.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,37 @@ The following figure shows the dependencies involved in building the `all` targe

> ## Creating an Archive
>
> Add new rules, update existing rules, and add new variables to:
> Often it is useful to create an archive file of your project that includes all data, code
> and results. An archive file can package many files into a single file that can easily be
> downloaded and shared with collaborators. We can add steps to create the archive file inside
> the Makefile itself so it's easy to update our archive file as the project changes.
>
>
> Edit the Makefile to create an archive file of your project. Add new rules, update existing
> rules and add new variables to:
>
> * Define the name of a directory, `zipf_analysis`, to hold all our
> code, data, plots and the Zipf summary table.
> * Create a new directory called `zipf_analysis` in the project directory.
> * Copy all our code, data, plots and the Zipf summary table to this
> directory.
> directory. The `cp -r` command can be used to copy files and directories
> into the new `zipf_analysis` directory:
>
> ~~~
> $ cp -r [files and directories to copy] zipf_analysis/
> ~~~
> {: .bash}
>
> * Hint: create a new variable for the `books` directory so that it can be
> copied to the new `zipf_analysis` directory
> * Create an archive, `zipf_analysis.tar.gz`, of this directory. The
> bash command `tar` can be used, as follows:
>
> ~~~
> $ tar -czf zipf_analysis.tar.gz zipf_analysis
> ~~~
> {: .bash}
>
>
> * Update `all` to create `zipf_analysis.tar.gz`.
> * Remove `zipf_analysis` and `zipf_analysis.tar.gz` when `make
> clean` is called.
> * Remove `zipf_analysis.tar.gz` when `make clean` is called.
> * Print the values of any additional variables you have defined when
> `make variables` is called.
>
Expand All @@ -86,7 +100,8 @@ The following figure shows the dependencies involved in building the `all` targe
> ## Archiving the Makefile
>
> Why does the Makefile rule for the archive directory add the Makefile to our archive of code, data, plots and Zipf summary table?
> Why does the Makefile rule for the archive directory add the Makefile to our archive of code,
> data, plots and Zipf summary table?
>
> > ## Solution
> > Our code files (`wordcount.py`, `plotcount.py`, `zipf_test.py`) implement
Expand Down

0 comments on commit f33e9f0

Please sign in to comment.