Tools for labs and projects
Instructions
- In the lab instructions, you have to replace
<...>
with an appropriate value.
git commit -m "<explicit message>"
- ➡️
git commit -m "fix: log in error"
- Don’t skip a step that didn’t work, telling yourself that it doesn’t matter
- This may cause problems later on
Datalabs
You require resources to start your services, the datalabs are available for that purpose.
Once you have completed your tasks, make sure to free up these resources by deleting or pausing your services.
- SSPCloud (INSEE): https://datalab.sspcloud.fr/
- GENES: https://onyxia.lab.groupe-genes.fr/
Custom service
If the catalogue services do not fully meet your needs, you can use customised services.
URLs to launch custom VSCode-python services for:
Explanations
In these labs, we will need a customised VSCode service, different from the one offered in the catalogue:
- by installing additional Python packages
- by modifying certain extensions
- using ➕ Ruff instead of ➖ Flake8 to format the code
- by opening a specific port to deploy an API
Opening the port to deploy the API must be done before launching the service.
After that, it is too late, and you will have to delete it and start over.
Ways to customise a service
- Launch the catalogue service, then modify it by executing commands manually
- Use an initialisation script that will run immediately after the catalogue service is launched
- In the form before Launch: Initialization scripts
- Example
- Create and use a Docker image based on the original service
- In the form before Launch: Service > Use a custom image
VSCode
Open Folder
File > Open Folder > /home/onyxia/work/<repo_name>
> OK
Open Folder allows you to determine the root folder you are currently in.
To find out the current folder, look at the top left of the explorer for the parent folder.
This choice is very important because imports between Python modules use relative paths.
Autocompletion
code-server (VSCode version used by datalabs) does not support Pylance, which normally provides autocompletion. 2 options for adding autocompletion:
Option 1
-
python -m venv venv
-
- Python: Select interpreter
- choose venv
When you install Python packages globally, everything gets mixed together.
If one project needs Django 3.2 and another needs Django 5.0, they’ll conflict.
Over time, your global Python also gets messy, with packages you don’t remember installing, and sharing your project becomes painful ➡️ the classic “it works on my machine” problem.
A venv solves this by creating a self-contained environment just for your project.
- create:
python -m venv venv
- activate:
source venv/bin/activate
Inside this bubble, you can install any packages you want in any version you want, completely isolated from other projects.
- save dependencies for sharing:
pip freeze > requirements.txt
- exit the venv:
deactivate
To recreate the environment elsewhere:
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
Option 2
To remove warnings:
pyrightconfig.json
{
"typeCheckingMode": "off",
"reportMissingParameterType": "none",
"reportImplicitRelativeImport": "none"
}
.vscode/settings.json
{
"basedpyright.analysis.inlayHints.callArgumentNames": false,
"basedpyright.analysis.inlayHints.variableTypes": false,
"basedpyright.analysis.inlayHints.functionReturnTypes": false
}
Git
Command | Description |
---|---|
git clone https://....git |
Creates a copy of a remote repository in your local directory. |
git add . |
Stages all changes for the next commit. |
git commit -m "<explicit message>" |
Commits the staged changes to the local repository. |
git push |
Uploads local changes to a remote repository. |
git pull |
Merge changes from a remote to the local repository. |
git switch <branch> |
Switches to the specified branch. |
Use a token
If you don’t want to enter your GitHub credentials every time you interact with a repository, you can use a personal access token.
This is particularly useful as it persists even after you’ve paused and resumed your VSCode service.
- Prerequisite: You must have already created a Personal Access Token in GitHub and declared it on the datalab (see Lab 1 for instructions)
- When cloning: Instead of using the standard clone URL, you embed the token directly into the command
- replace
git clone https://github.com/<username>/<reponame>.git
- with
git clone https://$GIT_PERSONAL_ACCESS_TOKEN@github.com/<username>/<reponame>.git
- replace
- To verify: After cloning, you can check that the remote URL now includes the token variable using the following command:
git remote -v
- GIT_PERSONAL_ACCESS_TOKEN is replaced by its value: ghp_…
Now, thanks to the token, you no longer need to enter your GitHub credentials, saving you time and effort.
VM ENSAI
In previous years, tutorials and projects were carried out on ENSAI VMs. You can therefore use it as a backup.
The necessary tools are still available there for development:
- Visual Studio Code
- Python 3.10
- Git
- a PostgreSQL database
All students have access to a database that can only be accessed from ENSAI VMs. For more information, click here
Personal computer
The biggest challenge if you want to work on your personal machine will be to setup a local PostgreSQL database.
That is why it is strongly advised not to work on your personal computer if you do not feel capable of carrying out these installations completely on your own.
This could take a lot of time and energy, and it is not the role of project managers to help you with these installations.
To complete the practical work and project on your personal computer, you must install:
- Visual Studio Code or another IDE
- Python
- Git
- PostgreSQL