Before you attempt this activity, it is best that you review lecture video four from week one. You can find the video and slides on the module page.
For the purpose of this lab activity, you will be using the Git repository you created earlier using the command line. However, you will not be using the local repository on your machine; instead you will clone a copy from the remote repository using the tools available in the IDE.
With IntelliJ IDEA open, and focused on the Welcome to IntelliJ IDEA screen, click on Get from VCS. You will be diverted to a new screen which will present you with a variety of options:
Click on GitHub Enterprise and you will be presented two input boxes:
The Server field can be populated with: http://github.coventry.ac.uk. Whilst for the Token field, click on Generate. This will open an internet browser window, which will direct you towards the Coventry University GitHub service. Login to the service and you will then be presented with another screen for generating a New personal access token. For now, check all the items on this page, and click Generate token at the bottom of the page. This will generate something similar to:
$ 82368bb66dc95cec65a6cb8a3423add3b120b85f
You can copy and paste this token into IntelliJ IDEA and then click on Log In. This will log you in to the GitHub service and enable you to clone your online repository to your machine.
Once you have logged into your GitHub account, you will be presented with a list of remote repositories for that account. Look for the repository you created earlier on (4061CEM) and click on the button labelled Clone. This will begin the process of cloning the repository onto your local machine.
You will be asked to enter your GitHub credentials once again, so fill these out and click on the button labelled Login once more.
As it stands, you will not be able to run your Python scripts, you will need to add the Python Interpreter to the
project. Click on File > Project Structure and a new window will pop up. In this window click on the drop-down item
that says <No SDK>
in the Project SDK section. When you click on the item, it will automatically detect a Python
interpreter in \usr\bin (if you are using this on Linux). However, this is not the interpreter we are going to use.
Click on Add SDK > Python SDK...
You are going to create a Virtualenv Environment for this project. Check the box that is labelled New environment and leave the other fields as they are (their default options) and then click on the button labelled OK. The IDE will then proceed to creating the virtual environment and setting the SDK of the project to this newly created environment.
Close the dialogue boxes, and you will now see in the file explorer a new folder has been created named venv. This is the virtual environment consisting of the Python interpreter. To ensure that this folder will not be committed to the repository, right-click on venv > Git > Add to .gitignore > Add to .gitignore and then click on Create. A pop-up will show, asking whether you want to add this file to Git, click on Add.
With a new file automatically created from the previous step, you will see the that the file name in the file explorer has turned green. This highlights that the file is new in the repository and is yet to be committed and pushed to the remote repository.
At the top of the screen, in the version control toolbox, click on the Green Tick. The tab will change on the left-hand side of the screen where the file explorer use to be. In this tab you can see the change-list (the files that have been added to the local repository), and some non-versioned files. Below that, there is an input box where you can supply a commit message. In this box, add the following:
Added a file to ignore the virtual environment files
You can then click on the Commit button.
There is a button labelled Commit and Push..., which can simplify the process of pushing to the remote repository. However, disregard this for now.
When you click Commit you may be presented with a dialogue asking for a Name and E-mail address. This will pop up as you have not followed the previous lab activity. Therefore, in this instance you will need to enter your name along with your Coventry University e-mail address. I would also recommend you go back and follow that lab activity.
As part of this course, you are expected to know how to use Linux and Git commands via the terminal/shell window.
Once you have clicked Commit, click on the Project tab on the left-hand side of the screen to return to the file explorer. You will now notice that the .gitignore file is no longer green. However, the file has still not been pushed to the remote repository. In order to do this, click on the green arrow in the version control toolbox. A window will pop up showing the commit that has not been pushed. Ensure everything is correct and click on Push. This will make the appropriate changes to the remote repository.
You will be asked to enter your GitHub credentials once again, enter them and click Login and the process will continue in the background.
You will not have been formerly introduced to Python. However, you will need to learn how to run a Python script using the IDE. To aid you through this process, you will be supplied with simple Python code to get the IDE working as it should.
Inside the IDE, you will need to create a new Python file. This can be achieved by using the Right Button on the mouse, and clicking on a folder in the file explorer. A menu list will pop up, select New > Python File and give it the name: Example.py. You will be asked whether you want to add the file to Git, click on Add. There is an option to disable this pop-up, if you wish to do so - select the Don't ask again checkbox before clicking Add.
Inside this newly created file, copy and pase the following script:
print("Hello and welcome to 4061CEM! It is great to see you here.")
THis is a relatively simple script, which will print the following:
Hello and welcome to 4061CEM! It is great to see you here.
To run this script, you need to add a configuration to the IDE. At the top right-hand side of the IDE (next to the
version control toolbox) is a button labelled Add Configuration..., click on this button. A new window will pop up,
on the left-hand side of this new window is the +
character; click on this and look for Python in the list. Inside
this window, you will need to enter the following information:
Once you have populated these variables, click the button labelled OK. You will now see that the button previously labelled Add Configuration... has changed to a drop-down menu. This will consist of the newly created Run Script configuration, but also the ability to add another configuration for another script if required.
With the configuration now added to the IDE, you can now click on the green Play character next to the drop-down menu. Alternatively, you can also use the keyboard shortcut Shift+F10. Doing this will run the script you have inserted into the Example.py file; doing so will display the text to the console window.
Hello and welcome to 4061CEM! It is great to see you here.
The console window is located towards the bottom of the IDE, and is the place where any output from a script you are running will be displayed. It will also be the area of the IDE that will accept a user-input if you choose to ask for an input.
You have now reached the end of this tutorial. The outcome of this tutorial is the ability for you to clone a repository from Git, create a new Python script and run the script using the integrated development environment.
If you have spotted any errors or issues within this tutorial, you can e-mail Dr Ian Cornelius. Ensure to include in your message a description of the error/issue and a possible resolution.