Skip to content

Pronto project, second session

During this session, we will address collaborative work with Git and Gitlab.

Several on Gitlab

Here, we will place ourselves in real conditions of collaborative work by deepening the concepts of Git. You will be divided according to your PRONTO project group.

On Gitlab, one of the group members creates a project with README.md. Then search and add the other members of his group, giving them the Maintainer status.

All the necessary information on Gitlab to carry out these steps can be found here: Gitlab

Conflicts in Git

Locally, with Git and VScode, here are the steps to follow:

  1. All group members clone the Git repository of the Gitlab project
  2. All group members configure Git
  3. One member adds the following file (named calculator.py) to the repository
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    # Small Python Project: Simple Calculator
    def add(a, b):
        return a + b
    
    def subtract(a, b):
        return a - b
    
    def multiply(a, b):
        return a * b
    
    def divide(a, b):
        if b != 0:
            return a / b
        else:
            return "Error: Division by zero."
    
    def main():
        print("Welcome to the Simple Calculator!")
        print("Select an operation:")
        print("1. Add")
        print("2. Subtract")
        print("3. Multiply")
        print("4. Divide")
    
        choice = input("Enter choice (1/2/3/4): ")
    
        if choice in ['1', '2', '3', '4']:
            num1 = float(input("Enter first number: "))
            num2 = float(input("Enter second number: "))
    
            if choice == '1':
                print(f"The result is: {add(num1, num2)}")
            elif choice == '2':
                print(f"The result is: {subtract(num1, num2)}")
            elif choice == '3':
                print(f"The result is: {multiply(num1, num2)}")
            elif choice == '4':
                print(f"The result is: {divide(num1, num2)}")
        else:
            print("Invalid input.")
    
    if __name__ == "__main__":
        main()
    
    1. Add the file and commit it on local
    2. Propagate the changes by pushing them to the online repository
  4. Everybody in the group now pulls from the online repository to get the file
  5. The group divides the following tasks among its members:
    1. Task 1: add an operator
      • Add a new operation, modulus, to the calculator. This function should calculate the remainder when the first number is divided by the second.
      • Edit the menu to include an option for the modulus operation.
    2. Task 2: improve input validation
      • Modify the main function to validate user input for the choice of operation and numbers.
    3. Task 3: Add Test Cases
      • Create a new file named test_calculator.py.
      • Add unit tests for all functions (add, subtract, multiply, divide, and modulus). Use Python's unittest module.
  6. Then each members split to work on their allocated task
    1. Each member adds their modifications to the index with the add command
    2. Then make a commented commit
    3. Then send their commit to the remote repository with the push command
    4. And now?

Tip

The git status command is very useful for providing information about the state of a repository and often offers solution hints.

All the necessary information on Git to carry out these steps can be found here: Git.

Documentation

Warning

An undocumented project is an unusable project!

Gitlab offers several possibilities to document its projects, from a simple readme file in minimalist text format to a custom website. A README.md file in Markdown format at the root of the project will be displayed directly in Gitlab automatically.