Development Tools

Cyriel Mallart
Ludovic Deneuville
Rémi Pépin

Development Environment

  • Practical exercises and projects completed on a Datalab
  • Can also be done on the VM (backup)

Datalab stack

  • Visual Studio Code: your code editor
  • Python 3.13
  • Git: to manage your repositories
  • PostgreSQL: a database
    • cloudBeaver: for viewing and editing this database

What’s on your school VM?

  • Python 3.10: Python version chosen by ENSAI
  • Visual Studio Code
  • Git
  • PostgreSQL
    • DBeaver: database administration tool to consult or edit

Visual Studio Code

  • Widely used and known code editor
  • Includes a file navigator and a terminal
  • Many (many many) extensions
  • Customization

Focus on Settings

.vscode/settings.json
{
  "workbench.colorTheme": "Dark Modern",
  "editor.fontSize": 16,
  "[python]": {
    "editor.formatOnSave": true,
    "editor.insertSpaces": true,
    "editor.tabSize": 4,
    "editor.defaultFormatter": "charliermarsh.ruff",
  },
  "ruff.lint.enable": true,
  "files.exclude": {
    "**/__pycache__": true,
    "**/.pytest_cache": true,
  }
}

Code Quality

What is “quality” for code?

  • Maintenance: easier to understand, maintain, and change/improve
  • Readability: reduces errors and makes collaboration easier
  • Performance: works better, faster, with fewer resources
  • Security: less vulnerable and susceptible to exploits

Pylint

A static analysis tool for Python that:

  • Checks code compliance with style standards
  • Detects potential errors
  • Identifies bad practices
Commands
pylint src
pylint --output-format=colorized --disable=C0114,C0411,C0415,W0718 $(git ls-files '*.py') --fail-under=7.5

Repository Structure

🚧

PROJET-INFO-2A
    ├── .vscode/settings.json
    ├── data
    │   └── init_db.sql
    ├── doc
    │   └── suivi
    │       └── YYYY.MM.DD-semaineN.md
    ├── src
    │   ├── business_object
    │   │   └── une_classe.py
    │   ├── dao
    │   │   └── une_classe_dao.py
    │   ├── service
    │   │   └── une_classe_service.py
    │   ├── tests
    │   │   ├── dao
    │   │   └── service
    │   ├── utils
    │   └── view
    │       └── accueil_view.py
    ├── .gitignore
    ├── LICENCE
    ├── README.md
    └── requirements.txt

Documentation

Git Branch Diagram

Git Branch Diagram
mathematical_operations.py
class MathematicalOperations:
    """Mathematical Operations"""
    def divide_five_by(self, number) -> float:
        """Divides the number 5 by a given number.
        Parameters
        ----------
        number : float or int
            The number by which 5 will be divided.
        Returns
        -------
        float or None
            The result of dividing 5 by the given number.
            If the number is equal to 0, the method returns None.
        """
        if number != 0:
            return 5 / number
        else:
            return None

Logs

What are logs?

Note

Logging is the process of recording events, errors, and information in an application.

A log captures information about what happened at a given time:

  • Monitoring
  • Debugging

Level 1 - Beginner

  • You have an error in your code
  • But you don’t know exactly where?
  • What do you do?

Level 2 - Debug Mode

  • You add a breakpoint
  • You launch in debug mode
  • You proceed until the error

Level 3 - Logs

import logging
logging.basicConfig(
    filename='logs/example.log',
    level=logging.INFO,
    format="%(asctime)s - %(levelname)-8s - %(message)s",
    datefmt="%d/%m/%Y %H:%M:%S")

It is possible to externalize the configuration in a logging_config.yml file

logger.debug("This is a debug message")
logger.info("This is an info message")
logger.warning("This is a warning message")
logger.error("This is an error message")

Log Levels

  • DEBUG: useful for debugging during development
  • INFO: tracking executed code
  • WARNING: unusual but non-blocking situation
  • ERROR: affects program logic but doesn’t stop it completely
  • CRITICAL: requires urgent intervention

A Good Start

import logging
def my_method(a):
    logging.debug("my_method - START")
    ...
    logging.debug("my_method - END")

Going Further

Use the modules:

  • src/utils/log_init.py
  • src/utils/log_decorator.py

And add a @Log decorator before each method