1) Setup Python environment
Create or modify your .bashrc (login) file
- Login to Rivanna. Make sure you are in your home directory ('pwd' shows you the current directory path. 'cd' with no argument will take you home.)
- In your home directory type ls and then type ls -a . Notice that ls -a displays additional “hidden files” in the listing. These files or directories begin with ”.” and they are typically used to store configuration options. The file called .bashrc contains options for the shell you will be using on rivanna.
- .bashrc is executed automatically every time you login. So, we can use it to setup your environment. First, look at my .bashrc file:
more ~rcg6p/phys1655/p1655.sh
Basically, the commands in the .bashrc setup python, and do a few other nice configurations to your terminal. - Now, edit your .bashrc file using one of the available text editors, eg: nano .bashrc,emacs .bashrc,vim .bashrc, gedit .bashrc, etc add the following line to the end of the .bashrc file.
source ~rcg6p/phys1655/p1655.sh
Note: if you do not have a .bashrc file, it will be created by the editor.
If you do it right, when you login from now on it will source (execute) the .bashrc file in my area and you will have all of the tools ready to use for class:
Very important Note: The command above needs to be copied exactly into your .bashrc file. The command executes a program in professor Group's area. So don't change "rcg6p" to your username. Don't do it! That file does not exist in your area, and you will get a "file not found error".
Watch out! If you make a typo in your .bashrc file you might not be able to log back in. So check it first with the command below before logging out! This command will execute your .bashrc file to make sure it works. Type this command on the linux command line:
source ~/.bashrc
If there are no errors, you are probably good.
Then log out and log back in - close the terminal, and open again should be good enough. Now type the command: printenv. This command will display a variety of variables that have been defined for your shell to use.
You can now also type p1655env to see a list of definitions related to this class (only 1). Don't worry about the details of how these are used for now, just make sure that you can see a variable with the string “P1655” in their name. This will allow your account to access special tools and programs throughout the semester. These settings are handled globally, so any changes will propagate to the whole class.
2) Git and GitHub
Next we will introduce working with the git code management system, which will be used to distribute starter code and for you and for you to submit your work for this class.
Using GitHub offers several advantages, including: gaining experience in one of the most highly-used tools for managing modern software development, providing backups of your work (as long as you check in your changes!), providing a way for TAs to check your work in progress, and more.
Start by:
- Login to Rivanna.
- Change directories into the 'phys1655' directory (that we created in class01). 'cd phys1655'
- Now, we will use GitHub to pull our class02 repository to Rivanna. But, first we have to setup GitHub....
For this part of the lab exercise, first read our GitHub/GitHub Classroom tutorial and get your GitHub account as described in the tutorial.
AFTER you complete our GitHub Classroom turotial above (you should have setup your GitHub account and loaded your ssh-key):
- Login to GitHub account on the GitHub webpage (using the Firefox Browser on your Rivanna desktop might be a good idea)
- Click on the link https://classroom.github.com/a/02Ornsjv and a GetHub repository will be created in your GitHub account
- Clone this repository to Rivanna to complete the exercise. In your shell on Rivanna (to get the link below use the green "code" button in the github repo and choose "ssh"). Make sure you can find the link. It should look like this: "git@github.com@
>>> git clone git@github.com:PHYS1655S24/Class02-userid.git (replace 'userid' with your user ID) /Class02-<userid>.git" . To clone the repository into your Rivanna working area type:
A directory named "Class02-<userid>" should have appeared in your area. cd into that directory and follow the instructions in the 'Readme.md' file of your repository (you can read it in the GitHub browser or from the rivanna command line using the command 'more Readme.md'). The Readme will be automatically shown when you view your repository in GitHub.
To run the included python file, type:
>>> python hello.py
at the command line.
You can edit the file using one of the available text editors, eg: nano .hello.py, emacs hello.py,vim hello.py, gedit hello.py,
Now that you cloned the repository, you can edit a file in the repository (hello.py), add it to the staging area, commit it, and push it back to your GitHub repository.
Don't know how to do that yet? No problem... The commands you will type are:
1) After we edit the file we need to do "git add". This adds a change in the working directory to the staging area. It tells Git that you want to include updates to a particular file in the next commit. But, it doesn't do the commit yet.
>>> git add hello.py
2) We can do a "git status" to see that our file is listed as not yet committed. This step isn't required. It just gives you the status
>>> git status
3) Now, we can commit. We need to add some comment about what we changed, that is what -m does.
>>> git commit -m "my first check in"
4) Now, we are ready to push it to GitHub
>>> git push
Now reload the web page for your GitHub repo and you will see that your file has changed.
You can find your repositories for the GitHub classroom by going to:
https://github.com/PHYS1655S24
That is it. Just make sure you got the updated 'hello.py' to upload to your GitHub account and you completed the work for today.