check if your codespace has uncommitted changes on github
note:
you can only have 2 active at a time(green dots)
you can see if any have uncommitted changes
you can export those changes to a branch from this page
Today we are going to pick up from where we left off talking about the conventional commits.
That is a core example of the types of detailed communication we do in programming that is embedded into the work.
Where else have you seen how communication about the work shape the work
Why Documentation¶
Today we will talk about documentation, there are several reasons this is important:
using official documentation is the best way to get better at the tools
understanding how documentation is designed and built will help you use it better
writing and maintaining documentation is really important part of working on a team
even if you use an LLM to help improve the writing, a human must verify the actual facts
documentation building tools are a type of developer tool (and these are generally good software design)
documentation building tools can help produce other types of writing in more developer-centric ways (nice automation of tedious things, etc)
Design is best learned from examples. Some of the best examples of software design come from developer tools.
In particular documentation tools are really good examples of:
pattern matching
modularity and abstraction
automation
the build process beyond compiling
By the end of today’s class you will be able to:
describe different types of documentation
find different information in a code repo
generate documentation as html
create a repo locally and push to GitHub
Plus we will reinforce things we have already seen:
ignoring content from a repo
paths
good file naming
What is documentation¶
We looked at a documentation types table from an article ethnography of documentation data science
Read the table and answer the following questions in your experience badge.
Which have you used before?
Which have you contributed to before?
what kinds did you review in the prepare work?
Why is documentation so important?¶
we should probably spend more time on it

So, how do we do it?¶
Different types of documentation live in different places and we use tools to maintain them.
As developers, we rely on code to do things that are easy for computers and hard for people.
You can read a list of documentation tools built by the researchers at UC Berkeley who hosted a docathon, week long hackathon to help people get better at building documentation for the tools they used and built.
The site shows different tools for many different languages and a short description of many of the top tools.
There is even a whole community and site just for documentation: write the docs
Jupyterbook¶
Jupyterbook v1 wraps a tool called sphinx and uses markdown instead of restructured text. The project authors note in the documenation that it “can be thought of as an opinionated distribution of Sphinx”.
We’re goign to use this.
sphinx is a very popular tool so knowing how it works is a general advantage. reStructuredText is not hard to learn, but I did not want to spend time on that, so we’re using markdown to keep it simple, and to demonstrate that these tools are extensible.
Even the linux kernel uses sphinx and here is why and how it works
navigate to your folder for this course (mine is inclass/systems,)
Make sure you are not in a repository
We can confirm that jupyter-book is installed by checking the version.
jupyter-book --versionWe will run a command to create a jupyterbook from a template:
jupyter-book create tiny-bookthe command has 3 parts:
jupyter-bookis a program (the thing we installed)createis a subcommand (one action that program can do)tiny-bookis an argument
===============================================================================
Your book template can be found at
tiny-book/
===============================================================================
We see that it succeeds
Give an example of another command we have done that has these 3 parts (program, subcommand, argument)
Solution to Exercise 4
Making sure you know these vocab terms precisely is important for talking with other developers and especially interviews
because the name is an argument or input, you can make it with any name:
jupyter-book create exampleEach one makes a directory, we can see by listing
lsgh-inclass-sp26-brownsarahm tiny-book
kwl-sp26-brownsarahm exampleAnd we can delete the second one since we do not actually want it.
rm example/rm: example/: is a directorywe get an error because it is not well defined to delete a directory, and potentially risky, so rm is written to throw an error
Instead, we have to tell it two additional things:
to delete recusively
rto force it to do something risky with
f
note we can stack single character options together with a single -
rm -rf example/In most of bash the -f is reserved for potentially dangerous things, so use it with care and take time to verify that it is really what you want to do
Now, let’s move inside the new folder
cd tiny-book/and look at what is there
ls -a_build intro.md markdown.md
_config.yml logo.png notebooks.ipynb
_toc.yml markdown-notebooks.md references.bib
. requirements.txt
..How can you tell that this folder is not currently a git repo?
Solution to Exercise 5
there is no .git directory
Starting a git repo locally¶
We made this folder, but we have not used any git operations on it yet, it is actually not a git repo, which we could tell from the output above, but let’s use git to inspect and get another hint.
We can try git status
git statusfatal: not a git repository (or any of the parent directories): .gitThis tells us the .git directory is missing form the current path and all parent directories.
To make it a git repo we use git init with the path we want to initialize, which currently is .
git init .hint: Using 'master' as the name for the initial branch. This default branch name
hint: will change to "main" in Git 3.0. To configure the initial branch name
hint: to use in all of your new repositories, which will suppress this warning,
hint: call:
hint:
hint: git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m <name>
hint:
hint: Disable this message with "git config set advice.defaultBranchName false"
Initialized empty Git repository in /Users/brownsarahm/Documents/inclass/systems/tiny-book/.git/Historically the default branch was called master.
derived from a master/slave analogy which is not even how git works, but was adopted terminology from other projects
literally the person who chose the names “master” and “origin” regrets that choice the name main is a more accurate and not harmful term and the current convention.
this is one of a long list of terms ACM recommends not using
+++{"lesson_part": "main"}
We want to use up to date, inclusive terminology, and we have already been using main for the default branch so far so let's do that again:
```{code-cell} bash
:tags: ["skip-execution"]
git branch -m main
```
+++{"lesson_part": "site"}
::::::{important}
This is also a good reminder that branch names are just names of variables we choose, we can make them whatever we want, `git` does not care what they are. We need branch names because otherwise we would have to keep track of commit hashes ourselves, but we can name them whatever we want. and check in with git now
git statusOn branch main
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
_config.yml
_toc.yml
intro.md
logo.png
markdown-notebooks.md
markdown.md
notebooks.ipynb
references.bib
requirements.txt
nothing added to commit but untracked files present (use "git add" to track)and we will commit the template.
git add .We have to add separately because the files are untracked we cannot use the -a option on commit
and then we will commit with a simple message
git commit -m 'jupyter book template'CR LF Warning
This is GitBash telling you that git is helping. Windows uses two characters for a new line CR (cariage return) and LF (line feed).
Classic Mac Operating system used the CR character. Unix-like systems (including MacOS X) use only the LF character.
If you try to open a file on Windows that has only LF characters, Windows will think it’s all one line. To help you,
since git knows people collaborate across file systems, when you check out files from the git database (.git/ directory)
git replaces LF characters with CRLF before updating your working directory.
When working on Windows, when you make a file locally, each new line will have CRLF in it. If your collaborator
(or server, eg GitHub) runs not a unix or linux based operating system (it almost certainly does) these extra
characters will make a mess and make the system interpret your code wrong. To help you out,
git will automatically, for Windows users, convert CRLF to LF when it adds
your work to the index (staging area). Then when you push, it’s the compatible version.
git documentation of the feature this is added to a new Windows page under resources
Structure of a Jupyter book¶
We will explore the output by looking at the files
ls_config.yml logo.png notebooks.ipynb
_toc.yml markdown-notebooks.md references.bib
intro.md markdown.md requirements.txtA jupyter book has two required files (_config.yml and _toc.yml), some for content, and some helpers that are common but not required.
the
*.mdfiles are contentthe
.bibfile is bibiolography informationThe other files are optional, but common. Requirements.txt is the format for pip to install python depndencies. There are different standards in other languages for how
the extention (.yml) is yaml, which stands for “YAML Ain’t Markup Language”. It consists of key, value pairs and is deigned to be a human-friendly way to encode data for use in any programming language.
Dev tools mean we do not have to write bibliographies manually¶
bibliographies are generated with bibtex which takes structured information from the references in a bibtex file with help from sphinxcontrib
For general reference, reference managers like zotero and mendeley can track all of your sources and output the references in bibtex format that you can use anywhere or sync with tools like MS Word or Google Docs.
You can use these in a build or explore badge
cat _config.yml The configuration file, tells jupyter-book basic iformation about the book, it provides all of the settings that jupyterbook and sphinx need to render the content as whatever output format we want.
The table of contents file describe how to put the other files in order.
cat _toc.yml 1 2 3 4 5 6 7 8 9# Table of contents # Learn more at https://jupyterbook.org/customize/toc.html format: jb-book root: intro chapters: - file: markdown - file: notebooks - file: markdown-notebooks
The one last file tells us what dependencies we have
cat requirements.txtIf your book generates with error messages run pip install -r requirements.txt
Building Documentation¶
We can transform from raw source to an output by building the book
jupyter-book build .Running Jupyter-Book v1.0.4.post1
Source Folder: /Users/brownsarahm/Documents/inclass/systems/tiny-book
Config Path: /Users/brownsarahm/Documents/inclass/systems/tiny-book/_config.yml
Output Path: /Users/brownsarahm/Documents/inclass/systems/tiny-book/_build/html
Running Sphinx v7.4.7
loading translations [en]... done
[etoc] Changing master_doc to 'intro'
loading pickled environment... checking bibtex cache... up to date
done
myst v3.0.1: MdParserConfig(commonmark_only=False, gfm_only=False, enable_extensions={'colon_fence', 'linkify', 'tasklist', 'substitution', 'dollarmath'}, disable_syntax=[], all_links_external=False, links_external_new_tabWhich files created by the template are not included in the rendered output? How could you tell?
we note that this made a new folder called _build. we can look inside there.
ls _build/and in the html folder:
ls _build/html/We can also copy the path to the file and open it in our browser
we can change the size of a browswer window or use the screen size settings in inspect mode to see that this site is responsive.
We didn’t have to write any html and we got a responsive site!
If you wanted to change the styling with sphinx you can use built in
themes which tell sphinx to put different
files in the _static folder when it builds your site, but you don’t have to change any of your content! If you like working on front end things (which is great! it’s just not alwasy the goal) you can even
build your own theme that can work with sphinx.
Handling Built files¶
The built site files are compeltey redundant, content wise, to the original markdown files.
We do not want to keep track of changes for the built files since they are generated from the source files. It’s redundant and makes it less clear where someone should update content.
Git helps us with this with the .gitignore
echo "_build" >> .gitignoregit statusOn branch main
Untracked files:
(use "git add <file>..." to include in what will be committed)
.gitignore
nothing added to commit but untracked files present (use "git add" to track)only the gitingore file itself is listed! just as we want.
now that’s the only new file as far as git is concerned, so we will track this,
git add .and finally commit
git commit - 'ignore build'error: pathspec '-' did not match any file(s) known to git
error: pathspec 'ignore build' did not match any file(s) known to gitI made a typo, so git said it couldn’t find files
git commit -m 'ignore build'[main 7436ea1] ignore build
1 file changed, 1 insertion(+)
create mode 100644 .gitignorePrepare for Next Class¶
Create a file gitcommandsbreakdown.md and for each command in the template below break down what steps it must do based on what we have learned so far about git objects. I started the first one as an example. Next class, we will make a commit using plumbing commands, so thinking about what you already know about commits will prepare you to learn this material.
# What git commands do
## `git status`
- check the branch of the HEAD pointer
- compare the HEAD pointer to the FETCH_HEAD, if different trace back through parent commits to find out how many commits apart they are and which is ahead (or if both ahead and behind)
- compare the snapshot at the HEAD pointer's commit to the current working directory
- if staging is not empty, compare that to the working directory
## `git commit`
-
## `git add`
- Badges¶
Review the notes from today
Review the notes, jupyterbook docs, and experiment with the
jupyter-bookCLI to determine what files are required to makejupyter-book buildrun in your kwl repo. Make your kwl repo into a jupyter book, by manually adding those files. Do not add the whole template to your repo, make the content you have already so it can build into html. Set it so that the_builddirectory is not under version control.Add
docs.mdto your KWL repo and explain the most important things to know about documentation in your own words using other programming concepts you have learned so far. Include in a markdown (same as HTML<!-- comment -->) comment the list of CSC courses you have taken for context while we give you feedback.
Review the notes from today
Review the notes, jupyterbook docs, and experiment with the
jupyter-bookCLI to determine what files are required to makejupyter-book buildrun. Make your kwl repo into a jupyter book. Set it so that the_builddirectory is not under version control.Learn about the documentation ecosystem in another language that you know using at least one official source and additional sources as you find helpful. In
docs.mdinclude a summary of your findings and compare and contrast it to jupyter book/sphinx. Include a bibtex based bibliography of the sources you used. You can use this generator for informal sources and google scholar for formal sources (or a reference manager).
Experience Report Evidence¶
Tiny book repo should exist. Append your terminal output or this repo’s git log to your experience report.
Questions After Today’s Class¶
These are a bit late, but will come!
- Geiger, R. S., Varoquaux, N., Mazel-Cabasse, C., & Holdgraf, C. (2018). The Types, Roles, and Practices of Documentation in Data Analytics Open Source Software Libraries: A Collaborative Ethnography of Documentation Work. Computer Supported Cooperative Work (CSCW), 27(3–6), 767–802. 10.1007/s10606-018-9333-1