Locally execute pre-commit linting locally

Following pull request PR-6262, we integrated a linting workflow to our continuous integration.

Waiting we update the Utilities/SetupForDevelopment.sh to automatically install the requirements, the linting could be performed locally following these steps:

pip install pre-commit
cd Slicer
pre-commit run --all-files

And to install the tool within the Slicer environment:

./Slicer-Release/python-install/bin/PythonSlicer -m pip install pre_commit

and to perform the check:

cd Slicer
../Slicer-Release/python-install/bin/PythonSlicer -m pre_commit run --all-files
1 Like

Thank you @jcfr, this is very useful. I’ve tried to execute this on Windows and I got two errors:

  1. The script complained that DLLs folder is missing.
  • In Slicer install tree: c:\\Users\\andra\\AppData\\Local\\NA-MIC\\Slicer 4.13.0-2022-03-19\\lib\\Python\DLLs
  • In Slicer build tree: C:\\D\\S4R\\python-install\\DLLs

I created an empty folder at the not found location and restarted the script and it seemed to solve this issue.

  1. pythonw.exe not found

I copied PythonSlicer.exe to pythonw.exe and it seemed to solve this issue.

@jcfr do you know what may require this folder and file? Should we add them to the build tree or add a module to the Sandbox (DebuggingTools or DeveloperToolsForExtensions) extension that can create these folders, install the pre-commit package, and run the checks on a single click?