Skip to content

Commit 2674bed

Browse files
Merge pull request #31 from pollen-robotics/30-visual-studio-config
30 visual studio config
2 parents 42cd7a2 + d13a4cc commit 2674bed

File tree

5 files changed

+92
-7
lines changed

5 files changed

+92
-7
lines changed

README.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,20 @@ List of steps to follow to adapt the template to your project.
1313
2. Clone the new repo
1414
3. [Recommended] Make a virtual environment
1515
4. [Optional] Set up [git lfs](#git) and *.gitattributes*
16-
4. Activate pre-commit hook
16+
5. Activate [pre-commit hook](#git)
1717
```console
18-
mv scripts/git_hooks/pre-commit .git/hooks/
18+
./scripts/setup_git_hooks.sh
1919
```
20-
5. Install dev tools
20+
6. [Configure](#ide---linting) visual studio
21+
```console
22+
./scripts/setup_vscode_extensions.sh
23+
./scripts/setup_vscode_config.sh
24+
```
25+
7. Install dev tools
2126
```console
2227
pip install -e .[dev]
2328
```
24-
6. [Configure](#ide---linting) Visual Code with the linters
25-
7. [Adapt](#unit-tests-and-test-coverage) workflow and bagdes links to this repo
29+
8. [Adapt](#unit-tests-and-test-coverage) workflow and bagdes links to this repo
2630

2731

2832
## Configuration
@@ -59,11 +63,13 @@ A *.gitignore* file ensures that the Python temporary files are not committed. I
5963

6064
[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.
6165

62-
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.
66+
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.
6367

6468

6569
### IDE - Linting
6670

71+
TL;DR Use *./scripts/setup_vscode_extensions.sh* and *./scripts/setup_vscode_config.sh*
72+
6773
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).
6874

6975
[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
7278

7379
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.
7480

75-
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.
81+
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.
7682

7783

7884
**A code not compliant with PEP8 guidelines will not be merged.**

scripts/setup_git_hooks.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
# Define the source and destination directories
4+
SOURCE_DIR="$(git rev-parse --show-toplevel)/scripts/git_hooks"
5+
DEST_DIR="$(git rev-parse --show-toplevel)/.git/hooks"
6+
7+
# Check if the git repository root is found
8+
if [ -z "$DEST_DIR" ]; then
9+
echo "Error: This script must be run within a git repository."
10+
exit 1
11+
fi
12+
13+
# Create the destination directory if it doesn't exist
14+
mkdir -p "$DEST_DIR"
15+
16+
# Copy the git_hooks folder to the destination
17+
cp -r "$SOURCE_DIR/"* "$DEST_DIR"
18+
19+
# Make scripts executable
20+
chmod +x "$DEST_DIR"/*
21+
22+
echo "git hooks copied in $DEST_DIR"

scripts/setup_vscode_config.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
# Define the source and destination directories
4+
SOURCE_DIR="$(git rev-parse --show-toplevel)/scripts/vscode"
5+
DEST_DIR="$(git rev-parse --show-toplevel)/.vscode"
6+
7+
# Check if the git repository root is found
8+
if [ -z "$DEST_DIR" ]; then
9+
echo "Error: This script must be run within a git repository."
10+
exit 1
11+
fi
12+
13+
# Create the destination directory if it doesn't exist
14+
mkdir -p "$DEST_DIR"
15+
16+
# Copy the vscode folder to the destination
17+
cp -r "$SOURCE_DIR/"* "$DEST_DIR"
18+
19+
echo "vscode config has been copied to $DEST_DIR"

scripts/setup_vscode_extensions.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
# List of VSCode extensions to install
4+
EXTENSIONS=(
5+
"ms-python.python"
6+
"ms-python.mypy-type-checker"
7+
"ms-python.black-formatter"
8+
"ms-python.flake8"
9+
"ms-python.isort"
10+
)
11+
12+
# Installing each extension
13+
for EXT in "${EXTENSIONS[@]}"; do
14+
code --install-extension "$EXT"
15+
done
16+
17+
# Uninstall Pylance if it is installed
18+
if code --list-extensions | grep -q 'ms-python.vscode-pylance'; then
19+
echo "Uninstalling Pylance..."
20+
code --uninstall-extension ms-python.vscode-pylance
21+
fi
22+
23+
echo "Extensions installation complete."

scripts/vscode/settings.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"black-formatter.importStrategy": "fromEnvironment",
3+
"isort.check": true,
4+
"isort.importStrategy": "fromEnvironment",
5+
"editor.formatOnSave": true,
6+
"editor.codeActionsOnSave": {
7+
"source.organizeImports": "explicit"
8+
},
9+
"isort.args": [
10+
"--profile",
11+
"black"
12+
],
13+
"mypy-type-checker.importStrategy": "fromEnvironment",
14+
"flake8.importStrategy": "fromEnvironment"
15+
}

0 commit comments

Comments
 (0)