Git, Example of Application

Lab 1
Author

Ludovic Deneuville

The practical labs will be carried out on one of the two datalabs :

We will be using the following tools:

Accounts and Configuration

GitHub account

Note

GitHub is a web-based platform that provides hosting for software development and version control using Git.

It’s widely used by developers to collaborate on projects.

Git Config

Tip

To avoid having to identify yourself every time you want to push code onto GitHub, we’re going to:

  • create a token on GitHub
  • declare this token on the datalab

See this tutorial for more information.

You must have an active Personal Access Token

If not :

    • Expiration: 90 days
    • tick repo and workflow
    • Generate token

Objectives

The objectives of this first tutorial are as follows:

  • Use of Git
  • Getting to grips with VS Code
  • Understand how an application works

This tutorial combines explanations and code phases.

The explanations in this tutorial should not take precedence over those of your instructor. Use them as a knowledge base for later, but always prefer oral explanations.

1 Repositories creation

Caution

For this first tutorial, you will work with your project team on a single remote repository.

One member of the team will create a repository on GitHub and then all the members (including the creator of the GitHub repository) will create their local repositories by cloning this remote repository.

1.1 Remote repository

Important

A single team member creates this remote repository.

    • A fork is a copy of a repository, allowing a user to develop independently without affecting the original
    • On the repository page > ⚙️ Settings > Collaborators > Add people

1.2 Local repositories

All team members will now create a local repository on a VSCode service in the datalab.

    • Important: in tab Network access, enable Port 9876
    • It will be usefull later to expose your webservice
    • Top left, icon with 3 horizontal bars > Terminal > New
    • or use shortcut CTRL + SHIFT + C
    • git clone https://${GIT_PERSONAL_ACCESS_TOKEN}@github.com/<user_name>/<repo_name>.git
    • GIT_PERSONAL_ACCESS_TOKEN
    • File > Open Folder > /home/onyxia/work/<repo_name> > OK
Environment Variables

An environment variable is a system-defined value used to configure how applications run or to securely store information like file paths, keys, or access tokens.

It is like a key-value pair in a dictionary. For example, GIT_PERSONAL_ACCESS_TOKEN is a variable whose value stores your GitHub personal access token.

export MY_VAR_KEY=my_var_value   # Create or replace
echo $MY_VAR_KEY                 # Display
printenv                         # Display all
printenv | grep GIT              # Display all containing the word GIT

2 Repository content

Note

Focus on some files.

2.1 README

The README file is essential for every project. It contains all the information needed to describe, install and use the application.

You will now follow the README instructions to :

Tip

You notice that you need to connect to a PostgreSQL database.

    • Ressources tab > Persistent volume size: 1Gi

2.2 VSCode settings

Most of these settings concern the automatic formatting of code when you save a file:

  • Formatter: Ruff
  • "editor.formatOnSave": true: apply format when you save a file
  • `“editor.insertSpaces”: true,: replace tabulation by spaces

Another important property :

  • "PYTHONPATH": "${workspaceFolder}/src": Python code is in folder src

3 Application example

To understand how a layered application is built, we’ll look at a project template.

You may be asked to design 2 types of application:

  • A CLI application
    • the user navigates through menus
  • A webservice
    • the application exposes endpoints
    • the user can query these endpoints and retrieve the results

3.1 CLI application

You arrive at the home menu. The principle of this type of application is to let you navigate from one view to another. If necessary, the view will call up services in the background.

Note

Below is a sequence diagram explaining the process.

You will find the same information in the log file.

sequenceDiagram
    participant CLI
    participant Vue as InscriptionVue
    participant Service as JoueurService
    participant Dao as JoueurDao

    CLI->>Vue: Enter pseudo
    Vue->>Service: pseudo_deja_utilise()
    Service->>Dao: lister_tous()
    Dao-->>Service: All players
    Service-->>Vue: True or False
    Vue->>CLI: continue if True

    CLI->>Vue: Enter pwd, mail...
    Vue->>Service: creer()
    Service->>Dao: creer()
    Dao-->>Service: True
    Service-->>Vue: Joueur object
    Vue->>CLI: Success

You’ll notice that the application asks for a password that’s a little too long.

    • You will find it in one of the classes above
You can do better

In software development, hardcoding fixed values is discouraged because it reduces flexibility and security.

Instead, using variables or configuration settings allows for easier adjustments and better adaptability across different environments.

    • with this code os.environ["PASSWORD_MIN_LENGTH"] after importing os
Tip

There are many ways of restricting user input.

It is also possible to create custom rules.

    • You will arrive at a new view with a new menu
    • 💡 to go faster, you can use user “a”, password “a”
Note

In the logs, you can see the flow of operations:

  • You navigate from view to view
  • Some views call services, which in turn call DAOs

3.2 A webservice

We’ll come back to webservices in more detail in TP3.

How to query it

Inside the Datalab VSCode service, You can query your webservice by running this command in another terminal: curl http://localhost:9876/hello/Alice

However, you may remember that at the beginning we opened port 9876 to the outside world, i.e. the whole Internet.

So anyone who knows the address can query this web service from any machine.

To get the address:

Caution

For other types of http request (PUT, POST, DELETE), the browser is not enough.

You will see how to make these requests in a later tutorial.

4 Git

Note

You’re now going to do a few basic things with Git :

  • Add files to the repository
  • Create save points
  • Send your local modifications to remote repositories
  • Update your local repository

4.1 Git routine

  • <firstname>.py
    a, b = 0, 5
    
    for i in range(b):
        print(" " * a, end="")
        a += 1
        print("Hello <firstname>")

The sequence of Git commands should become automatic.

If you get this message when you push, you need to start with pull.

To https://github.com/ludo2ne/ENSAI-2A-complement-info-TP.git
Merge branch 'main' of https://github.com/ludo2ne/ENSAI-2A-complement-info-TP
 ! [rejected]        main -> main (fetch first)
error: failed to push some refs to 'https://github.com/ludo2ne/ENSAI-2A-complement-info-TP.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first merge the remote changes (e.g.,
hint: 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

4.2 Creating conflict

Important

Only one team member will do it!

    • do not change the file names, only the code inside
      • print("Hello <firstname>") ➡️ print("Hello Mary-<firstname>")
    • And it add, commit and push

4.3 Solve conflits

    • print("Hello <firstname>") ➡️ print("Hello Anna-<firstname>")
    • And they add, commit, pull and push.

Normally a conflict arises during pull. This is because there is a version conflict

Version Code
Original version print("Hello <firstname>")
Your modification print("Hello Anne-<firstname>")
Version on remote repository print("Hello Marie-<firstname>")
<<<<<<< HEAD
print("Bonjour Anna-<firstname>")         # Your code - current change
=======
print("Bonjour Mary-<firstname>")         # Code in the remote repository - incoming change
>>>>>>>
    • either by clicking on Accept Current Change
    • Or by deleting print(‘Hello Mary-<firstname>’), as well as <<<<<<<, ======= and >>>>>>>.
Important

Having a conflict isn’t a big deal!

Having a conflict isn’t a big deal!

Having a conflict isn’t a big deal!

Conflict ≠ Error

This simply happens when Git encounters 2 versions and it doesn’t have a 🔮 or a 🎲 to choose which is the right one.

To avoid conflicts, get organised with your team to avoid working on the same files at the same time as much as possible.

5 Create your project repository

A team member :

    • Repository name: for example ENSAI-Projet-info-2A.
    • Public or Private, as you wish
    • Check Add a README file.
    • .gitignore : Python
    • Choose a license : Apache, GNU, MIT…
Mandatory

Next, each team member :

    • doc/tracking/2025.09.04-week1.md: the first weekly point
    • src/main.py: the file to launch your application
    • requirements.txt: the file listing the packages
Caution

Afterwards, you’ll make sure that your depot is “tidy”, in the same way as described in the previous section.

5.1 .env file

This file will contain environment variables that will be used, for example, to connect to the PostgreSQL database.

Just one member of the team needs to modify the appropriate file, push, and then the others pull.

Conclusion

The aim of this tutorial was to get you up to speed on using Git, and to help you discover and understand how a layered application works.

Important

When you have finished coding, don’t forget to :

  • push your code to GitHub
  • pause or delete your services