Short Exercises #0

Due Monday, October 3rd at 4:30pm CT

The purpose of this assignment is to set up and familiarize yourself with some of the tools you will use in CAPP 121 and with the workflow for the course. In this assignment, you will:

  1. Set up and practice with Visual Studio Code, a text editor

  2. Set up your GitHub repository for the short exercises

  3. Submit your work for SE #0 on Gradescope

If you attended CAPP Camp, you performed some of these tasks already. Still, make sure you work through the relevant steps in #2 and #3, as your short exercises repository is distinct from the ones you used in CAPP Camp. You will also need to turn in some work for SE #0 for credit.

Visual Studio Code

Visual Studio Code is a modern text editor that you will be using in CAPP 121. Furthermore, you will be using the Linux operating system to run your code in this course.

Follow the the instructions in the pages below to download VSCode and to use VSCode to log on to the Linux server:

You will probably also want to configure some options in VSCode specifically for this class. In particular, you will want to make sure that pressing the tab key inserts four spaces instead of a tab character and you’ll want to add a “ruler” at 80 characters to give you a visual reminder when your lines get too long.

To ensure that the tab key inserts four space, look at the purple bar at the bottom of the VSCode window. If you see “Spaces: 4”, you’re all set. If you see “Tab” or “Spaces: 2”, you will want to change it. Just click on the item. You’ll see a pop-up menu. Choose “Indent with spaces” and choose 4 as the number of spaces to use.

To set up the ruler, click on the gear icon in the bottom left of the VSCode window, then “Settings, and search for “editor.rulers”. Click on “Edit settings in Json”. Change "editor.rulers": [] to "editor.rulers": [80]. and save the file.

GitHub Classroom

GitHub is a web-based hosting service for Git repositories. In this course, we are going to use GitHub Classroom, a service that makes it easy to create coursework repositories and is well-integrated with Gradescope, which you will use to submit your work.

Create a GitHub account

First, you need to get a GitHub account. If you already have a GitHub account, please move on to the next step.

If you do not have a GitHub account please create one one now. You can get an account here: https://github.com/join. We encourage you to use your CNetID as your GitHub account name, if possible. If that name is already taken, try using your CNetID as a prefix in your Github username.

Make sure you are logged into GitHub for the next steps.

Using Git with SSH

Before we set up your short exercises repository, we need to handle a few administrative tasks.

When you log into the GitHub website, you will use the username and password associated with your GitHub account. However, when using Git commands from the terminal, things are a bit different. In particular, GitHub uses two mechanisms for authenticating yourself from the terminal: Personal Access Tokens and SSH Keys. We will be using SSH keys.

In a nutshell, an SSH key is a file that resides in your home directory, and which you can think of as a file that stores a secure password (SSH keys are a bit more complex than that but, for our purposes, we can just think of them as extra-secure passwords).

Complete the following instructions to set up your SSH key with GitHub so that you can use GitHub from the terminal: Git I: Getting started.

Set up your short exercises repo

In this section, you will work through a series of steps to initialize your short exercises repository.

We encourage you to use copy-and-paste, rather than typing out the commands listed below. It is very easy to make a mistake, such as leaving out a $, when typying one of the commands by hand.

Step 0: Accept the Short Exercises invitation URL and verify that your repository has been created on GitHub.

First, log on to Ed Discussion and accept the Short Exercises invitation URL in the pinned post “Short Exercises #0 now available”. To verify that your repository exists, open a browser tab to this URL: https://github.com/uchicago-capp30121-aut-2022/short-exercises-GITHUB_USERNAME where GITHUB_USERNAME is replaced by your GitHub username. If you are not able to open this URL successfully, please ask for help.

Step 1: Create a directory for your work this class and the short exercises repository.

First, create an environment variable called GITHUB_USERNAME by running the following (replacing replace_me with your GitHub username):

GITHUB_USERNAME=replace_me

This will make it easy to copy-and-paste the rest of the commands. You can double-check whether the variable is properly set by running echo $GITHUB_USERNAME from the command line.

Next, create a directory for your work this class and the short exercises repository:

cd
mkdir -p capp30121/short-exercises-$GITHUB_USERNAME
cd capp30121/short-exercises-$GITHUB_USERNAME

The purpose of the initial cd is to make sure you are starting from your home directory.

Notice how we’re using the GITHUB_USERNAME variable that we defined earlier. When you run the above commands, the shell will automatically replace the text $GITHUB_USERNAME with your GitHub username.

The -p flag to mkdir tells mkdir to create all the parent directories if needed. That is, if you don’t already have a capp30121 directory, it will create one, and then will create a directory for your short exercises repo inside of it.

The purpose of the second cd is to move you to the directory where you will do your work for the short exercises. Run pwd to make sure you are in the right place. A little sanity checking goes a long way towards avoiding mistakes.

Step 2: Run this command to initialize a local repository:

git init

Step 3: Run this command to connect your local repository to your short exercises repository on GitHub:

git remote add origin git@github.com:uchicago-capp30121-aut-2022/short-exercises-$GITHUB_USERNAME.git

This command will not generate any output, if it ran successfully.

Step 4: Run these commands to connect your repository to the “upstream” repository that we will use to distribute code for SE #0 (and subsequent short exercises) and to pull the initial files for SE #0:

git remote add upstream git@github.com:uchicago-capp30121-aut-2022/short-exercises-initial-code.git
git pull upstream main

If these commands were successful, you will see something roughly of the form:

remote: Enumerating objects: 9, done.
remote: Counting objects: 100% (9/9), done.
remote: Compressing objects: 100% (9/9), done.
remote: Total 9 (delta 0), reused 9 (delta 0), pack-reused 0
Unpacking objects: 100% (9/9), 1.53 KiB | 9.00 KiB/s, done.
From github.com:uchicago-capp30121-aut-2022/short-exercises-initial-code
 * branch            main       -> FETCH_HEAD
 * [new branch]      main       -> upstream/main

The exact number of files and/or objects may differ. If you get an error, please ask for help. It is important to pay attention to the error messages from git commands. Don’t just blindly run them. Make sure the output looks sensible and does not contain any errors or warnings.

Step 5: Set the name of the branch:

git branch -M main

This command will not generate any output, if it runs successfully.

Step 6: And finally, upload your local Git repository to GitHub, by running:

git push -u origin main

If this command fails, please ask for help; you likely made a mistake in Step 3.

Step 7: Do a sanity check.

Run ls *. If everything went smoothly, you should find the following files in your short exercises directory:

README

se0:
se0.py test_se0.py pytest.ini README

You may also see a directory and the files for Short Exercises #1, since that assignment will become available during week #1. You can safely ignore those files for now.

You should also see these files in your repository on Github (https://github.com/uchicago-capp30121-aut-2022/short-exercises-GITHUB_USERNAME where GITHUB_USERNAME is replaced by your GitHub username.)

Also, if you run:

git status .

in your short-exercises-GITHUB_USERNAME directory, the result should be:

On branch main
Your branch is up to date with 'origin/main'.

nothing to commit, working tree clean

In this assignment, you will be working in the se0 subdirectory. Change into your se0 subdirectory to do the rest of the work in this lab. If you are not sure how to navigate into se0, take some time to work through the Introduction to Linux: The Linux File System.

You are now set to do the work required for SE #0.

Note

The repositories created by GitHUb Classroom can be a bit hard to find from the standard GitHub interface. Fortunately, there is a page that lists your repositories for this course. We strongly recommend creating a bookmark in your browser to it: https://github.com/uchicago-capp30121-aut-2022.

SE #0 Tasks

Open se0.py in VSCode. Replace the 0 in the return statement in the function two_plus_two with 2+2.

You can run your code from the command line using:

python3 se0.py

The output should be:

2+2 is 4

You can run the automated test using:

py.test -vx

There is only one test for this assignment, so you should see this if your code ran correctly:

test_se0.py::test_two_plus_two PASSED

The Testing Your Code page on the course website contains more thorough descriptions of the automated tests, as well as instructions on how to run your code in IPython.

Once you have finished this task, add, commit, and push your changes to Github:

git add se0.py
git commit -m "Finished SE #0"
git push

You can run git add -u to add the files you have updated instead of git add se0.py. Never use git add . since it will likely cause you to add executables, editor backup files, large output files, etc that have no place in a repository.

Gradescope

Once you’ve completed the task above, you must submit your work through Gradescope (linked from our Canvas site). Gradescope will fetch your files directly from your GitHub repository, so it is important that you remember to add, commit and push your work!

It is a good idea at this point to run:

git status .

You should see something like:

On branch main
Your branch is up to date with 'origin/main'.

nothing to commit, working tree clean

If se0.py is listed under “Changes to be committed”, “Changes not staged for commit”, or “Untracked files, then you have not successfully pushed your code to the server. You should ignore any directories called __pycache__.

To submit your work, go to the “Gradescope” section on our Canvas site. Then, click on “Short Exercises #0”. If this is your first submission on Gradescope for this course, you may first need to connect your Gradescope account to GitHub. Click on the “Connect to GitHub” button. Pressing that button will take you to a GitHub page asking you to confirm that you want to authorize Gradescope to access your GitHub repositories. Just click on the green “Authorize Gradescope” button.

Then, under “Repository”, make sure to select your uchicago-capp30121-aut-2022/short-exercises-GITHUB_USERNAME.git repository (where GITHUB_USERNAME is your GitHub username). Under “Branch”, just select “main”.

Finally, click on “Upload”. An autograder will run, and will report back a score. If you coded and uploaded everything properly, the score should be 100.

The CAPP Camp material comains information that will help you become more fluent in Git and Linux, and includes topics that will help you do your more more efficiently. We strongly recommend that you work through all the material early in CAPP 121. You can find the CAPP Camp webpage here.

Grading

The short exercises will be graded automatically. There is only one automated test for this assignment, so your ESNU score will be determined solely on the basis of that test:

Grade

Percent tests passed

Exemplary

100%

Unsatisfactory

0%

It should be easy to earn an E on this assignment. You just need to

  1. make the required change to the two_plus_two function, and

  2. push your changes your repository on Github, and then

  3. upload your repository to Gradescope.