Lab 1: Workflow and Toolchain
This labs focuses on the tools, techniques, and workflows used by Python programmers and programmers in general. We will adopt most of these best practices and use them for lab distribution, comments, and feedback
Step 0: Lab Preparation
-
Sign up for a GitHub
account. Please thoughtfully choose a username so that I can
reasonably infer who you are from it. Make sure to choose
the
free plan (it's the default) and don't set up an organization. After you've registered, please send me an email with your GitHub username. I will add you to the GitHub Williams CS organization and to the CS 135 Students team. - Read a virtualenv tutorial up to Why not virtualenv.
- Read a bit about pip and virtualenv
Step 1: Forking
Navigate to the Lab 1 GitHub repository. Fork the repository by using the Fork button in the top right-hand corner. This copies the repository to your GitHub account.
Step 2: Cloning
You should now have a copy of the repository in your own GitHub account. Now clone the repository to your local disk using the following steps.
- Look clone URL label along the bottom right of the repository page. You can clone via HTTPS, SSH, or Subversion. We'll use HTTPS so first click on that link and then click on the little clipboard with an arrow icon to copy the URL to the local clipboard.
- Open up the Terminal and navigate to your home directory with
$ cd
- Make a new directory called cs135 using
$ mkdir cs135
- Change directories into cs135 using
$ cd cs135
- Now clone your fork of lab 1 by typing git clone
and then pasting (⌘-v) the copied repo on the command
line. It should look like this
$ git clone https://github.com/<git-username>/cs135-lab1.git
- Change into the new repository directory using
$ cd cs135-lab1
Step 3: virtualenv
virtualenv is a program that isolates collections of python libraries for a particular programming project. It also allows you to associate a specific python verion with a project.
- Create a new python environment using
$ virtualenv -p python3 —-system-site-packages venv
(type it, don't copy it) - The -p python3 tells virtualenv that you want to use python3.x as your python interpreter
- The --system-site-packages says you want the site packages installed on the system to be available to you
- The venv is the directory where you want the project-specific libraries to live
- Explore the directory structures inside venv to see what happened
- You can activate the new environment by using
$ . venv/bin/activate
- This alters your PATH environment variable so that venv/bin/ is checked first
- Type
$ echo $PATH
to see what paths are searched and in what order - Deactivate the virual environment by typing
$ deactivate
at anytime (but not now)
Step 4: pip
Use pip to install the textblob package, which provides methods for spelling correction.
- Type
$ pip install textblob
to install the textblob python package - This package is now installed in your virtual environment
- Examine the directory venv/lib/<python3.x>/site-packages
Step 5: Text Editors
There are many good text editors. People swear by emacs and vim. In a pinch, you can also use nano. Currently, many people like sublime. Today we will use Atom, but in the future feel free to use whatever you want.
- Edit the rain.py file by typing
$ atom rain.py
Step 6: Python
Opening the rain.py file in the text editor should reveal the following code.
''' Use TextBlog spelling correction on the sentence 'the raain in sspain stayss mainly on the plane' ''' # make the textblog package available import textblob # our phrase to correct sentence = 'the raain in sspain stayss mainly on the plane' # create an instance of TextBlog using our sentence blog = textblob.TextBlob(sentence) # correct the spelling errors corrected = blog.correct() print(corrected)
- You can execute this code by typing
$ python rain.py
from the Terminal. Try it out. - Edit the code so that it corrects the phrase 'proffesor Dumbledore is my faverite'
- Try running your code. It should print
professor Dumbledore is my favorite
Step 7: Submitting Code
We will use Git and GitHub for submitting lab assignments.
Commit your changes
Recall that you cloned a forked a repository to your local disk. You need to save your changes to your locally cloned repository by committing them using$ git commit -m "joined Dumbledore's Army" rain.py
Push your changes to GitHub
You will now push these changes back to your forked repository on GitHub using$ git push
Verify your changes on Github
Navigate now in your web browser to your forked repository on GitHub. It should be available athttps://github.com/<git-username>/cs135-lab1
. If you click on rain.py you should see your changes reflected there.Issue a pull request
You should see a little green button next to the repostory name and branch on your GitHub repository page. Clicking this link will issue a pull request to the base repository from which the fork was originally made. Go ahead and issue a pull request.