College: | CUNY School of Professional Studies |
---|---|
Course-Name: | Software Application Programming I |
Course-Code: | IS 210 |
Lesson: | 02 |
The warm-up tasks this week will focus on general git repository tasks. You'll be tasked to manipulate files with git's tools prior to submitting the work through the git pull request workflow.
The following tasks will either have you interacting with existing files in the assignment repository or creating new ones on the fly. Don't forget to add your interpreter directive, utf-8 encoding, and a short docstring with any new files that you create!
Important
In these exercises, you may, on occasion, come across a task that requres you to research or use a function or method not directly covered by the course text. Since Python is such a large language it would be impossible for the author to have included descriptions of each and every available function which would largely duplicate the offical Python documentation.
A vital skill to successful programming is being comfortable searching for and using official language documentation sources like the Python String Documentation page. Throughout our coursework we will be practicing both the use of the language in practice and the search skills necessary to become functional programmers.
We'll start by creating a new file and adding it to our repository.
Create a new file named
task_01.txt
in the root of your repository. You can useidle
to create a new file by typing the file's name after theidle
command such as:$ idle somefile
Tip
While
idle
will likely be the main tool for many of you, you could also use thetouch
command to achieve the same objective.Use
git status
to check that git sees your unstaged file.Use the
git add
command to add this file to staging for the next commit.Use
git status
to check that your changes are properly staged for committing.Use
git commit
to commit your change into the repository.
For task 02, you'll be making a small change to an existing file.
Open the file,
task_02.py
with youridle
python editor.Replace the name
Snoopy
with your own name.Tip
Since this is a Python file, you can test to see if you made the right change by running your python file in idle or on the command line.
Use
git status
to check that git sees your unstaged file.Use the
git add
command to add this file to staging for the next commit.Use
git status
to check that your changes are properly staged for committing.Use
git commit
to commit your change into the repository.
For our third warm-up exercise, we'll move a file with git mv
to retain
the history of the file. When renaming or moving files in Git, it's important
to use git mv
and not other tools that rename files or folders as Git
could lose track of file history if done incorrectly.
Use
git mv
to rename the file,Task 3.txt
totask_03.txt
.Hint
As you'll quickly discover, having spaces in file names on the console can be a pain in the neck! Either encapsulate the file name with quotation marks (eg,
"some file.txt"
) or try escaping the space with a backslash (some\ file.txt
).Use
git status
to check that your changes are properly staged for committing.Use
git commit
to commit your change into the repository.
Note
Did you notice how you didn't have to use git add
this time around?
Some Git commands that interact with files already under version control
don't require you to add the changes to the repository and are
automatically staged.
The last in our quartet of major operations in git is removing (aka deleting) a file in Git. As you'll see in this exercise, removing a file and a directory are not exactly the same.
Use the
git rm
to remove the single file,task_04.txt
Use
git rm
to remove the directorytask_04
and all of the files contained within it.Hint
Look into what the
-r
or recursive flag does to modify howgit rm
works.Use
git status
to check that your changes are properly staged for committing.Use
git commit
to commit your change into the repository.
As we discussed in the Concepts and Terms document, executable Python files should have an interpreter directive. One such file in our repository happens to be missing one!
- Edit
task_05.py
and add an interpreter directive in the proper location. - Use
git status
to check that git sees your unstaged file. - Use the
git add
command to add this file to staging for the next commit. - Use
git status
to check that your changes are properly staged for committing. - Use
git commit
to commit your change into the repository.
The encoding statement is as, if-not more, important to add to your Python files than your interpreter directive. As it happens, one of our files happens to be missing its coding statement. Correct it to receive credit for this task.
- Edit
task_06.py
and add an coding statement in the appropriate location. - Use
git status
to check that git sees your unstaged file. - Use the
git add
command to add this file to staging for the next commit. - Use
git status
to check that your changes are properly staged for committing. - Use
git commit
to commit your change into the repository.
Code must be functional and pass tests before it will be eligible for credit.
Lint tests check your code for syntactic or stylistic errors To execute lint tests against a specific file, simply open a terminal in the same directory as your code repository and type:
$ pylint filename.py
Where filename.py
is the name of the file you wish to lint test.
Unit tests check that your code performs the tested objectives. Unit tests may be executed individually by opening a terminal in the same directory as your code repository and typing:
$ nosetests tests/name_of_test.py
Where name_of_test.py
is the name of the testfile found in the tests
directory of your source code.
All tests may be run simultaneously by executing the runtests.sh
script
from the root of your assignment repository. To execute all tests, open a
terminal in the same directory as your code repository and type:
$ ./runtests.sh
Code should be submitted to GitHub by means of opening a pull request.
As-of Lesson 02, each student will have a branch named after his or her
GitHub username. Pull requests should be made against the branch that
matches your GitHub username. Pull requests made against other branches will
be closed. This work flow mimics the steps you took to open a pull request
against the pull
branch in Week Two.
For a refresher on how to open a pull request, please see homework instructions in Lesson 01. It is recommended that you run PyLint locally after each file is edited in order to reduce the number of errors found in testing.
In order to receive full credit you must complete the assignment as-instructed and without any violations (reported in the build status). There will be automated tests for this assignment to provide early feedback on program code.
When you have completed this assignment, please post the link to your pull request in the body of the assignment on Blackboard in order to receive credit.