|
|

|
|
|

|
|
|
|
|
|
# Session 1: Tools-I
|
|
|
|
... | ... | @@ -43,7 +43,7 @@ |
|
|
|
|
|
In the **Programming in Network Environment** subject we will learn how to create programs capable of **communicating** one to other through Internet
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
But first, we need to learn about the tools we are going to use: [Github](https://github.com/), [Python](https://www.python.org/), [Firefox](https://www.mozilla.org/es-ES/firefox/new/) and [Pycharm](https://www.jetbrains.com/es-es/pycharm/download) (Community Edition)
|
|
|
|
... | ... | @@ -53,8 +53,8 @@ Modern **programming projects** have thousand of lines of code and hundred of ** |
|
|
|
|
|
Currently, the two most used controls systems are [Github](https://github.com/) and [GitLab](https://gitlab.com/). Both are based on the **opensource** engine called [git](https://es.wikipedia.org/wiki/Git), developed in 2005 by [Linux Torvalds](https://es.wikipedia.org/wiki/Linus_Torvalds), the creator of the [Linux Kernel](https://en.wikipedia.org/wiki/Linux_kernel)
|
|
|
|
|
|
\
|
|
|

|
|
|
\
|
|
|

|
|
|
|
|
|
In this **subject** we will focus on the use of **Github**
|
|
|
|
... | ... | @@ -161,15 +161,15 @@ For developing in python we are going to use the [PyCharm IDE](https://www.jetbr |
|
|
|
|
|
Go to the **activities menu** in the top left corner and write pycharm. Click on the PyCharm icon. **CAUTION!** In the lab there are two version of the program. We will use the **Community Edition** (which is OpenSource). Make sure the icon looks like this one (squared):
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
If this is **the first time** it is opened, some configuration windows will appear.
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
IThe initial window will show up (maybe the program requests some other information, but that would be easy to handle):
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
### Cloning our working repo
|
|
|
|
... | ... | @@ -177,87 +177,87 @@ We are going to work on our own **working repository** that is in gitlab (you ju |
|
|
|
|
|
From the main Pycharm windows we select the option **Get from version Control**
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
This window shows up. It is asking us for the location of our project in the repository:
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
We just go to the browser and go to our **working repo** main page and click on the **Clone or download** button.
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
Click on the **copy button** on the right side.
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
Then move to the Pycharm Windows and paste the URL.
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
Then select below the **local folder** were you want to store your project. By default it is located in the **PycharmProjects** folder in your home. I will use the default folder. Click on the **Clone** button.
|
|
|
|
|
|
Now you will be asked if you want to **open** the new project.
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
Click on **YES**. The main window appears along with a welcome message (as you can see, the images are from other repo, but it does not matter, right?).
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
Click on the **Close** button. **We are ready to work!**
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
In this **animation** the whole process is shown.
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
### Our first commit to the repo
|
|
|
|
|
|
If you click on the top left folder, you will see all the **contents** of your working project, with the structure I have designed.
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
Before doing our first python program, let's make some **changes** to the **README file** and upload into our remote repository in Gitlab. Click on the README file to edit it.
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
Add some text. Notice how the color of the README file has changed. It is indicating that a change has been made: the **current README** file is **different** than the one stored in the **repository**.
|
|
|
|
|
|
Let's **commit** that change. Click on the **green tick** in the upper right corner.
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
Every time you commit a change, you should write a comment. In this case we can write _my first change_. Then click on the **commit** button.
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
Congrats! You've done your first commit!
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
But you have committed your change to the **local repository** in your computer. It is not yet in gitlab. You have to execute a **push command**. Click on the option at **VCS/Git/Push**.
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
In the next screen click on the **Push** button.
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
Enter your Gitlab **username** and **password**. Then click on **Log In**.
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
After some seconds your changes will be pushed.
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
**Congrats!** You've made your first contribution to your remote gitlab repository!
|
|
|
|
|
|
If you go to your gitlab repo page, you will see the changes you just did.
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
## Hello world with Pycharm!
|
|
|
|
... | ... | @@ -267,27 +267,27 @@ Let's write our first python program in Pycharm. The first step is to configure |
|
|
|
|
|
We have to chose which python interpreter to use. Go to **File/Setting** and click to select the project interpreter as shown in the image below.
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
Click on the **configure** button on the right.
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
And then on the **Add** option.
|
|
|
|
|
|

|
|
|
|
|
|
Select the first option: **Virtual Environmnet**. Check **New Environment** and click on **OK**
|
|
|
Select the first option: **Virtual Environment**. Check **New Environment** and click on **OK**
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
And click again on **OK** for closing the Settings Windows
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
The **python interpreter** is ready! You will see the new folder called **venv**. It contains the python interpreter and all the related files needed.
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
### Writing the Hello world program
|
|
|
|
... | ... | @@ -297,19 +297,19 @@ Let's write our first Hello world program in PyCharm. You could create a specifi |
|
|
|
|
|
Let's create our first python file. Make sure the **Hello folder is selected**, as we want to create our new file in that directory. Then click on **File/new/python file**.
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
**Type in** the **filename**. For example **hello**. It is not necessary to introduce the extension (.py) since we already indicated we were creating a Python script.
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
As we are working with the **Gitlab repo**, PyCharm asks us if we want this new file to be **added** to our **local repository**. Click on **Add**. Sometimes you just want to make a quick test on a temporary file. In that case you may not want it to be included in the repo. But in this case, we want to include our **hello.py** file into the repo.
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
We can see now the **new hello.py file** in the **project view** on the right side.
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
Also, the file is opened on a new tab. **We are now ready for typing python code!**. Look at the **green tick** in the upper right corner. It tells us that the hello.py is **ok**, with **no errors**.
|
|
|
|
... | ... | @@ -317,7 +317,7 @@ Notice the color of the new file: green. It means that is a new file, added to t |
|
|
|
|
|
In this **animation** the process of creating a **new python file** is shown.
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
#### Writing the code
|
|
|
|
... | ... | @@ -330,65 +330,65 @@ print("Hello world!!") |
|
|
|
|
|
When the editor detects you have written the first letters, _pr_, it shows below some of the functions that matches. You can continue typing or pressing the **TAB key** for accepting the first choice,
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
Once the **print()** function is typed, the editor will show us all the possible **parameters** that the print function has. The first one (values) are variables or strings we want to print.
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
We continue writing the string we want to print. Finish pressing the **ENTER** key. You should see something like this, with the **green tick** on the right.
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
Imagine that you make a mistake typing the print. In that case you will see a **red exclamation marl** and a **red sign** on the location where the error is detected.
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
If you place the **mouse pointer** on the **red line** below the red icon, you will get **more information** about the error.
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
A typical error is to add a **blank new line** after the last line. The **python style guide** recommends not to do that. Therefore, you will see a **warning** in that case.
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
If you place the pointer in the **upper mark**, you will read that there is **1 weak error**.
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
If you place the pointer in the **second mark** on the right, you will see the **error message**.
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
In this **animation** the process of **writing the hello world** is shown.
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
In this **animation** some **errors** are forced and corrected.
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
### Running the program
|
|
|
|
|
|
The first time a file is created, cannot be executed directly. The buttons for running and debugging cannot be pressed. Also there is an option that says: **add configuration**.
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
Instead of creating a custom configuration, we will let PyCharm to create one for us. Click on **Run/Run**.
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
Click on the **hello** option.
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
The program will **run**. A **new run** tab is open in the bottom. There you will see the **messages** we have printed. Also notice that now there is a **new configuration**, called **hello** and the run and debug **green buttons** are activated.
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
Once the configuration has been created, **running the program is straightforward**. Just click on the green run button in the toolbar.
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
### Adding the program to the gitlab repo
|
|
|
|
... | ... | @@ -396,31 +396,31 @@ Now that the program is working, it is time to **add** it to our **repo**. First |
|
|
|
|
|
* Click on the **commit button**.
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
* Add a **comment** to the commit and press the commit button.
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
Notice that now the hello.py file is **NOT green anymore**. It has the same color than the other files in the local repo.
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
* Now go to **VCS/Git/Push** and click on **Push**.
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
After some seconds, you will see the **confirmation message**. Our local repo has been pushed to Gitlab!
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
* Go to the browser and **check** that the changes are in **Gitlab**.
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
If you enter into the Hello folder, the **hello.py** file will be there.
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
Congrats! You have created, running and committed to the Gitlab repo your first python program.
|
|
|
|
... | ... | |