diff --git a/README.md b/README.md index 2c9826b..1cb5ac3 100644 --- a/README.md +++ b/README.md @@ -13,16 +13,20 @@ List of steps to follow to adapt the template to your project. 2. Clone the new repo 3. [Recommended] Make a virtual environment 4. [Optional] Set up [git lfs](#git) and *.gitattributes* -4. Activate pre-commit hook +5. Activate [pre-commit hook](#git) ```console -mv scripts/git_hooks/pre-commit .git/hooks/ +./scripts/setup_git_hooks.sh ``` -5. Install dev tools +6. [Configure](#ide---linting) visual studio +```console +./scripts/setup_vscode_extensions.sh +./scripts/setup_vscode_config.sh +``` +7. Install dev tools ```console pip install -e .[dev] ``` -6. [Configure](#ide---linting) Visual Code with the linters -7. [Adapt](#unit-tests-and-test-coverage) workflow and bagdes links to this repo +8. [Adapt](#unit-tests-and-test-coverage) workflow and bagdes links to this repo ## Configuration @@ -59,11 +63,13 @@ A *.gitignore* file ensures that the Python temporary files are not committed. I [git LFS](https://git-lfs.com/) can be configured to manage all non-script files (3D models, deep learning models, images, etc.). The list of files is defined in *gitattributes_example*. If you wish to utilize LFS, rename this file to *.gitattributes* and then run ```git lfs install```. It's also a good practice to maintain another repository as a submodule containing all the data. -A git hook can be set up to automatically check for PEP8 compliance before committing. Refer to *scripts/git_hooks*. Installing this is recommended as the GitHub workflows will perform the same checks. +A git hook can be set up to automatically check for PEP8 compliance before committing. Refer to *scripts/git_hooks*. Installing this is recommended as the GitHub workflows will perform the same checks. The script *./scripts/setup_git_hooks.sh* will do this for you. ### IDE - Linting +TL;DR Use *./scripts/setup_vscode_extensions.sh* and *./scripts/setup_vscode_config.sh* + Visual Studio Code is the recommended IDE. Ensure you have the Python extension installed and [configure](https://dev.to/adamlombard/how-to-use-the-black-python-code-formatter-in-vscode-3lo0) VS Code to auto-format your code using [black](https://black.readthedocs.io). [isort](https://pycqa.github.io/isort/) verifies the order of Python imports. [Set up](https://github.com/microsoft/vscode-isort#import-sorting-on-save) VS Code to handle this automatically. @@ -72,7 +78,7 @@ Visual Studio Code is the recommended IDE. Ensure you have the Python extension Lastly, [mypy](https://mypy.readthedocs.io/en/stable/index.html) will perform static type checking. In this guide, it's set to run in **strict** mode. Feel free to [adjust the constraints](https://mypy.readthedocs.io/en/stable/getting_started.html?highlight=strict#strict-mode-and-configuration) if they don't align with your project's needs. -These tools are configured in the **setup.cfg** file. Their versions are predefined to prevent discrepancies between local and remote checks. It's advisable to keep them updated. +These tools are configured in the **setup.cfg** and **pyproject.toml** files. Their versions are predefined to prevent discrepancies between local and remote checks. It's advisable to keep them updated. **A code not compliant with PEP8 guidelines will not be merged.** diff --git a/scripts/setup_git_hooks.sh b/scripts/setup_git_hooks.sh new file mode 100755 index 0000000..2e62c2b --- /dev/null +++ b/scripts/setup_git_hooks.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# Define the source and destination directories +SOURCE_DIR="$(git rev-parse --show-toplevel)/scripts/git_hooks" +DEST_DIR="$(git rev-parse --show-toplevel)/.git/hooks" + +# Check if the git repository root is found +if [ -z "$DEST_DIR" ]; then + echo "Error: This script must be run within a git repository." + exit 1 +fi + +# Create the destination directory if it doesn't exist +mkdir -p "$DEST_DIR" + +# Copy the git_hooks folder to the destination +cp -r "$SOURCE_DIR/"* "$DEST_DIR" + +# Make scripts executable +chmod +x "$DEST_DIR"/* + +echo "git hooks copied in $DEST_DIR" diff --git a/scripts/setup_vscode_config.sh b/scripts/setup_vscode_config.sh new file mode 100755 index 0000000..6a642aa --- /dev/null +++ b/scripts/setup_vscode_config.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +# Define the source and destination directories +SOURCE_DIR="$(git rev-parse --show-toplevel)/scripts/vscode" +DEST_DIR="$(git rev-parse --show-toplevel)/.vscode" + +# Check if the git repository root is found +if [ -z "$DEST_DIR" ]; then + echo "Error: This script must be run within a git repository." + exit 1 +fi + +# Create the destination directory if it doesn't exist +mkdir -p "$DEST_DIR" + +# Copy the vscode folder to the destination +cp -r "$SOURCE_DIR/"* "$DEST_DIR" + +echo "vscode config has been copied to $DEST_DIR" diff --git a/scripts/setup_vscode_extensions.sh b/scripts/setup_vscode_extensions.sh new file mode 100755 index 0000000..03d53a3 --- /dev/null +++ b/scripts/setup_vscode_extensions.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +# List of VSCode extensions to install +EXTENSIONS=( + "ms-python.python" + "ms-python.mypy-type-checker" + "ms-python.black-formatter" + "ms-python.flake8" + "ms-python.isort" +) + +# Installing each extension +for EXT in "${EXTENSIONS[@]}"; do + code --install-extension "$EXT" +done + +# Uninstall Pylance if it is installed +if code --list-extensions | grep -q 'ms-python.vscode-pylance'; then + echo "Uninstalling Pylance..." + code --uninstall-extension ms-python.vscode-pylance +fi + +echo "Extensions installation complete." diff --git a/scripts/vscode/settings.json b/scripts/vscode/settings.json new file mode 100644 index 0000000..9bc35e0 --- /dev/null +++ b/scripts/vscode/settings.json @@ -0,0 +1,15 @@ +{ + "black-formatter.importStrategy": "fromEnvironment", + "isort.check": true, + "isort.importStrategy": "fromEnvironment", + "editor.formatOnSave": true, + "editor.codeActionsOnSave": { + "source.organizeImports": "explicit" + }, + "isort.args": [ + "--profile", + "black" + ], + "mypy-type-checker.importStrategy": "fromEnvironment", + "flake8.importStrategy": "fromEnvironment" +} \ No newline at end of file