Skip to content

Commit

Permalink
Merge pull request #2 from cs106l/assign0
Browse files Browse the repository at this point in the history
release: Assign0
  • Loading branch information
fabioibanez authored Jan 9, 2025
2 parents a3943b3 + de5e072 commit 0db0f80
Show file tree
Hide file tree
Showing 75 changed files with 380 additions and 6,795 deletions.
38 changes: 38 additions & 0 deletions admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import subprocess
import shutil
import os
import argparse


def find_last_commit_with_path(path):
try:
commit_hash = subprocess.check_output(
["git", "log", "-n", "1", "--pretty=format:%H", "--", path],
stderr=subprocess.DEVNULL
).decode("utf-8").strip()
return commit_hash
except subprocess.CalledProcessError:
return None

def copy_from_commit(commit_hash, path):
os.makedirs(path, exist_ok=True)
subprocess.run(["git", "checkout", commit_hash, "--", path])
shutil.copytree(path, path, dirs_exist_ok=True)


def main():
parser = argparse.ArgumentParser(description="Copies an old assignment into the worktree.")
parser.add_argument("assignment", help="An assignment, e.g. 'assign0', 'assign1', etc.")
args = parser.parse_args()

path = args.assignment
commit_hash = find_last_commit_with_path(path)

if commit_hash:
print(f"Last commit for {path}: {commit_hash}")
copy_from_commit(commit_hash, path)
print(f"Copied {path} from commit {commit_hash}.")
else:
print(f"No commits found for the specified assignment: {path}.")

main()
274 changes: 274 additions & 0 deletions assign0/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,274 @@
<img src="docs/header.png" width="100%" />

# Assignment 0: Setup!

Due Friday, January 17th at 11:59PM

## Overview

Welcome to CS106L! This assignment will get you setup for the rest of the quarter so that setup for the rest of the assignments is simple and smooth. By the end of this assignment, you should be able to compile and run C++ files from VSCode and run the autograder, which you'll be doing for each of the remaining assignments!

If you run into any issues during setup, please reach out to us on [EdStem](https://edstem.org/us/courses/72089/discussion) or come to our office hours!

## Part 1: Installing Python

### Part 1.1: Checking for an existing Python installation

The autograder for each assignment in CS106L uses Python. You must have a Python installation of version `3.8` or higher. To check your Python version you can run the following in your terminal:

If you're on Linux or Mac:

```sh
python3 --version
```

If you're on Windows:

```sh
python --version
```

If you get a version that is `3.8` or higher, then you're good, **you can continue to Part 2**. Otherwise, please follow Part 1.2 to install Python on your machine.

### Part 1.2: Installing Python (if you don't already have it installed)

#### Mac & Windows

Please download the latest Python version [here](https://www.python.org/downloads/) and run the installer. **Note: on Windows, you must check `Add python.exe to PATH` in the installer**. After installing, verify that the installation worked by following the steps in **Part 1.1**.

#### Linux

These instructions are for Debian-based distributions, like Ubuntu. Tested on Ubuntu 20.04 LTS.

1. Update the Ubuntu package lists by running

```sh
sudo apt-get update
```

2. Install Python:

```sh
sudo apt-get install python3
```

3. Restart your terminal and verify that the installation worked by running:

```sh
python3 --version
```

## Part 2: Setup VSCode and C++ Compiler

We will use VSCode to write C++ code for this class. Below are instructions to setup VSCode along with the GCC compiler for your machine.

### Mac

#### Step One: Installing VSCode

Go to [this link](https://code.visualstudio.com/docs/setup/mac)
and download Visual Studio Code for Mac. Follow the instructions on this webpage under the
section **Installation**.

Inside VSCode, head to the extensions tab <img src="docs/vscode-extensions.png" display="inline" height="20px"></img> and search for **C/C++**. Click on the **C/C++** extension, and then click **Install**.

Finally, open the command palette (<kbd>Cmd+Shift+P</kbd>), search for `Shell Command: Install 'code' command in PATH`, and select it. This will allow you to launch VSCode directly from the terminal by running the `code` command.
**🥳 At this point you should successfully have VSCode on your Mac 👏**
#### Step Two: Installing a C++ Compiler
1. Check if you have Homebrew by running
```sh
brew --version
```
If you get something like
```sh
brew --version
Homebrew 4.2.21
```
then skip ahead to step 3. If you get anything else that looks suspicious, proceed to step 2!
2. Run this command:
```sh
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)
```
which will download Homebrew🍺, a package manager for Mac. Woot woot.
3. Run the following command:
```sh
brew install gcc
```
which will install the GCC compiler on your machine.
4. Make note of which GCC version Homebrew installs. In most cases, this will be `g++-14`.
By default, the `g++` command on Mac is an alias to the built-in `clang` compiler. We can fix this by running
```sh
echo 'alias g++="g++-14"' >> ~/.zshrc
```
to make `g++` point to the version of GCC we just installed. Change `g++-14` in the above command to whichever version of GCC was installed.
5. Restart your terminal and verify that everything worked by running the following command:
```sh
g++ --version
```
### Windows
#### Step One: Installing VSCode
Go to [this link](https://code.visualstudio.com/docs/setup/windows)
and download Visual Studio Code for Windows. Follow the instructions on this webpage under the
section **Installation**.
Inside VSCode, head to the extensions tab <img src="docs/vscode-extensions.png" display="inline" height="20px"></img> and search for **C/C++**. Click on the **C/C++** extension, and then click **Install**.
**🥳 At this point you should successfully have VSCode on your PC 👏**
#### Step Two: Installing a C++ Compiler
1. Follow the instructions at [this link](https://code.visualstudio.com/docs/cpp/config-mingw) under the section **Installing the MinGW-w64 toolchain.**
2. After fully following the instructions under **Installing the MinGW-w64 toolchain** you should now be able to verify everything worked by running the following command:
```sh
g++ --version
```
### Linux
These instructions are for Debian-based distributions, like Ubuntu. Tested on Ubuntu 20.04 LTS.
#### Step One: Installing VSCode
Go to [this link](https://code.visualstudio.com/docs/setup/linux)
and download Visual Studio Code for Linux. Follow the instructions on this webpage under the section **Installation**.
Inside VSCode, head to the extensions tab <img src="docs/vscode-extensions.png" display="inline" height="20px"></img> and search for **C/C++**. Click on the **C/C++** extension, and then click **Install**.
Finally, open the command palette (<kbd>Ctrl+Shift+P</kbd>), search for `Shell Command: Install 'code' command in PATH`, and select it. This will allow you to launch VSCode directly from the terminal by running the `code` command.
**🥳 At this point you should successfully have VSCode on your Linux machine 👏**
#### Step Two: Installing a C++ Compiler
1. In a terminal, update the Ubuntu package lists by running
```sh
sudo apt-get update
```
2. Next install the `g++` compiler:
```sh
sudo apt-get install g++-10
```
3. By default, the system version of `g++` will be used. To change it to the version you just installed, you can configure Linux to use G++ version 10 or a higher version installed like so:
```sh
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 10
```
4. Restart your terminal and verify that GCC was installed correctly. You must have a `g++` version of 10 or higher:
```sh
g++ --version
```
## Part 3: Cloning the class code via Git!
Git is a popular VCS (version control system) that we will use to distribute starter codes for the assignments. Make sure that you have Git installed by running
```sh
git --version
```
If you see anything that looks off, [download and install Git from this page](https://git-scm.com/downloads)!
### Download the starter code
Open VSCode, and then open a terminal (hit <kbd>Ctrl+\`</kbd> or go to **Terminal > New Terminal** at the top of the window) and run the following command:
```sh
git clone https://github.com/cs106l/cs106l-assignments.git
```
which will download the starter code into a folder `cs106l-assignments`.
### Opening a VSCode workspace
When working on assignments in this class, we recommend you open up a VSCode workspace for the specific assignment folder you are working on. So if you now have a folder `cs106l-assignments`, you can first `cd` (change directory) into the correct folder:
```sh
cd cs106l-assignments/assign0
```
which changes your working directory to `assign0`, and then you can open up a VSCode workspace dedicated to this folder:
```sh
code .
```
and now you should be ready to go!
### Fetching assignments
As we update existing assignments and release new ones, we will push updates to this repository. To fetch a new assignment, open up a terminal to your `cs106l-assignments` directory and run
```sh
git pull origin main
```
You should now have the latest starter code!
# Part 4: Testing your setup!
Now we will have you compile your first C++ file and run the autograder. To run any C++ code, first you'll need to compile it. Open up a VSCode terminal (again, hit <kbd>Ctrl+\`</kbd> or go to **Terminal > New Terminal** at the top of the window). Then make sure that you are in the `assign0/` directory and run:
```sh
g++ -std=c++20 main.cpp -o main
```
This **compiles** the C++ file `main.cpp` into an executable file called `main` which contains raw machine code that your processor can execute. Assuming that your code compiles without any errors, you can now do:
```sh
./main
```
which will actually run the `main` function in `main.cpp`. This will execute your code and then run an autograder that will check that your installation is correct.
> [!NOTE]
>
> ### Note for Windows
>
> On Windows, you may need to compile your code using
>
> ```sh
> g++ -static-libstdc++ -std=c++20 main.cpp -o main
> ```
>
> in order to see output. Also, the output executable may be called `main.exe`, in which case you'll run your code with:
>
> ```sh
> ./main.exe
> ```
# 🚀 Submission Instructions
After compiling and running, if your autograder looks like this:
![An image showing a terminal window where the autograder has run with all tests passing](docs/autograder.png)
then you have finished the assignment! Woot woot. To submit the assignment, please complete the feedback form [at this link](https://forms.gle/QNedgpAXdVHipZgYA). Once you submit the form, a link to the submission page will show up in the form submission confirmation.
48 changes: 48 additions & 0 deletions assign0/autograder/autograder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from utils import Autograder

import base64
from colorama import Fore
import difflib
import pickle
import re
import os
import subprocess
import getpass

PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
AUTOGRADER_DIR = os.path.join(PATH, "autograder")

def test_python_installed():
"""Check that Python is installed."""
try:
result = subprocess.run(["python3", "--version"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
assert result.returncode == 0, "Python 3 is not installed or not in PATH."
except FileNotFoundError:
raise AssertionError("Python 3 is not installed or not in PATH.")


def test_cpp_compiler():
"""Check that a C++ compiler is installed."""
try:
result = subprocess.run(["g++", "--version"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
assert result.returncode == 0, "C++ compiler (g++) not found or not working."
except FileNotFoundError:
raise AssertionError("C++ compiler (g++) not installed or not in PATH.")


def test_git_installed():
"""Check that Git is installed."""
try:
result = subprocess.run(["git", "--version"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
assert result.returncode == 0, "Git is not installed or not in PATH."
except FileNotFoundError:
raise AssertionError("Git is not installed or not in PATH.")



if __name__ == "__main__":
grader = Autograder()
grader.add_part("Check C++ Compiler", test_cpp_compiler)
grader.add_part("Check Git Installation", test_git_installed)
grader.add_part("Check Python Installation", test_python_installed)
grader.run()
1 change: 1 addition & 0 deletions assign0/autograder/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
colorama>=0.4.6
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
#include <sstream>
#include <string>
#include <fstream>
#include <vector>

struct Course;
using FillMeIn = Course*;

int
run_autograder()
Expand Down
File renamed without changes.
Binary file added assign0/docs/autograder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assign0/docs/header.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assign0/docs/vscode-extensions.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions assign0/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* CS106L Assignment 0: Environment Setup!
* Created by Fabio Ibanez
*
* If you're reading this welcome to CS106L! For this assignment you don't
* actually need to write any C++ code. Instead, you'll be setting up your
* environment and getting familiar with the tools we'll be using in the course.
* The code in this file will verify that your installation is correct and that
* the autograder is working properly.
*/

#include <iostream>
#include <sstream>
#include "autograder/utils.cpp"

int main() {
return run_autograder();
}
Loading

0 comments on commit 0db0f80

Please sign in to comment.