Smartgit installed with flatpak can’t run pre-commit script

  Kiến thức lập trình

I’ve added a pre-commit hook using the pre-commit tool. Committing via the command line works fine, but committing with smartgit fails:

~/projects/jobby> git commit --cleanup=whitespace --allow-empty --file=/tmp/smartgit12407019311209412612/commit17051915623650681255.tmp
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/home/philip-f37/projects/jobby/.venv/lib/python3.11/site-packages/pre_commit/__main__.py", line 3, in <module>
    from pre_commit.main import main
  File "/home/philip-f37/projects/jobby/.venv/lib/python3.11/site-packages/pre_commit/main.py", line 10, in <module>
    from pre_commit import clientlib
  File "/home/philip-f37/projects/jobby/.venv/lib/python3.11/site-packages/pre_commit/clientlib.py", line 16, in <module>
    from pre_commit.all_languages import language_names
  File "/home/philip-f37/projects/jobby/.venv/lib/python3.11/site-packages/pre_commit/all_languages.py", line 6, in <module>
    from pre_commit.languages import dart
  File "/home/philip-f37/projects/jobby/.venv/lib/python3.11/site-packages/pre_commit/languages/dart.py", line 16, in <module>
    from pre_commit.yaml import yaml_load
  File "/home/philip-f37/projects/jobby/.venv/lib/python3.11/site-packages/pre_commit/yaml.py", line 6, in <module>
    import yaml
ModuleNotFoundError: No module named 'yaml'

This SO answer as well as the official documentation suggests extending the PATH by changing ~/.smartgit/smartgit.vmoptions. However, I have Smartgit installed via Flatpak, so no such file exists in my home directory or anywhere outside of the flatpak directory.

A smartgit.vmoptions file can be found in in the flatpak directory:

.var/app/com.syntevo.SmartGit/config/smartgit/

In that file, I have tried to include the path to the project’s virtualenv python binary, but that didn’t fix the issue:

#.var/app/com.syntevo.SmartGit/config/smartgit/smartgit.vmoptions
path=/home/philip-f37/projects/jobby/.venv/bin

I have also tried creating a similar file at ~/.smartgit/smartgit.vmoptions, but that didn’t help either.

I have also tried giving smartgit full filesystem access to my home directory via flatseal – again, no success.


pre-commit hook

#!/usr/bin/env bash
# File generated by pre-commit: https://pre-commit.com
# ID: 138fd403232d2ddd5efb44317e38bf03

# start templated
INSTALL_PYTHON=/home/philip-f37/projects/jobby/.venv/bin/python
ARGS=(hook-impl --config=.pre-commit-config.yaml --hook-type=pre-commit)
# end templated

HERE="$(cd "$(dirname "$0")" && pwd)"
ARGS+=(--hook-dir "$HERE" -- "$@")

if [ -x "$INSTALL_PYTHON" ]; then
    exec "$INSTALL_PYTHON" -mpre_commit "${ARGS[@]}"
elif command -v pre-commit > /dev/null; then
    exec pre-commit "${ARGS[@]}"
else
    echo '`pre-commit` not found.  Did you forget to activate your virtualenv?' 1>&2
    exit 1
fi

pre-commit config

repos:
  - repo: https://github.com/astral-sh/ruff-pre-commit
    rev: v0.4.4
    hooks:
      - id: ruff
  - repo: https://github.com/psf/black
    rev: 24.4.2
    hooks:
      - id: black

LEAVE A COMMENT