We already have pre-commit
(docs) configured, and working, in our traditional development environments to run pre-commit Git hooks. This works as expected.
However, we often do work from inside AWS SageMaker Studio, and using the built-in Git GUI does not seem compatible with pre-commit (or perhaps Git hooks, in general). I'm pretty new to SageMaker and to managing environments via CLI, so I may be overlooking something obvious.
Issue
The Git GUI does not work, but shell commands executed through a Jupyter notebook cell in SageMaker Studio do.
With staged changes, clicking commit on the Git GUI will immediately throw error: /opt/conda/bin/python: No module named pre_commit
But if you run !git commit -m \<message\>
via a notebook cell, the commit/hooks run as expected.
This makes me think that the Git panel operates independently from notebook kernel environments. Though running !git status
from a notebook cell and git status
from the system terminal show the same staged/changed/untracked files.
Just to see if we could get it working, we tried pip install pre-commit
from the system terminal. This flips from the "No module named pre_commit" error to a new error: An error has occurred: InvalidManifestError: =====\> /root/.cache/pre-commit/repogox81zzt/.pre-commit-hooks.yaml is not a file Check the log at /home/sagemaker-user/.cache/pre-commit/pre-commit.log
Log dump
pre-commit version: 3.5.0
git --version: git version 2.40.1
sys.version:
3\.9.15 | packaged by conda-forge | (main, Nov 22 2022, 08:45:29)
\[GCC 10.4.0\]
sys.executable: /opt/conda/bin/python3.9
os.name: posix
sys.platform: linux
### error information
An error has occurred: InvalidManifestError:
=====\> /root/.cache/pre-commit/repogox81zzt/.pre-commit-hooks.yaml is not a file
Traceback (most recent call last):
File "/opt/conda/lib/python3.9/site-packages/pre_commit/error_handler.py", line 73, in error_handler
yield
File "/opt/conda/lib/python3.9/site-packages/pre_commit/main.py", line 386, in main
return hook_impl(
File "/opt/conda/lib/python3.9/site-packages/pre_commit/commands/hook_impl.py", line 271, in hook_impl
return retv | run(config, store, ns)
File "/opt/conda/lib/python3.9/site-packages/pre_commit/commands/run.py", line 425, in run
for hook in all_hooks(config, store)
File "/opt/conda/lib/python3.9/site-packages/pre_commit/repository.py", line 252, in all_hooks
return tuple(
File "/opt/conda/lib/python3.9/site-packages/pre_commit/repository.py", line 255, in \<genexpr\>
for hook in \_repository_hooks(repo, store, root_config)
File "/opt/conda/lib/python3.9/site-packages/pre_commit/repository.py", line 230, in \_repository_hooks
return \_cloned_repository_hooks(repo_config, store, root_config)
File "/opt/conda/lib/python3.9/site-packages/pre_commit/repository.py", line 197, in \_cloned_repository_hooks
by_id = {hook\['id'\]: hook for hook in load_manifest(manifest_path)}
File "/opt/conda/lib/python3.9/site-packages/cfgv.py", line 416, in load_from_filename
return apply_defaults(data, schema)
File "/opt/conda/lib/python3.9/contextlib.py", line 137, in __exit__
self.gen.throw(typ, value, traceback)
File "/opt/conda/lib/python3.9/site-packages/cfgv.py", line 45, in reraise_as
raise tp(e).with_traceback(tb) from None
File "/opt/conda/lib/python3.9/site-packages/cfgv.py", line 42, in reraise_as
yield
File "/opt/conda/lib/python3.9/site-packages/cfgv.py", line 401, in load_from_filename
raise ValidationError(f'{display_filename} is not a file')
pre_commit.clientlib.InvalidManifestError:
=====\> /root/.cache/pre-commit/repogox81zzt/.pre-commit-hooks.yaml is not a file
For added context:
- We provision notebooks off the standard AWS-managed Data Science 3.0 kernel
- Here is our
.pre-commit-config.yaml
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- repo: https://github.com/psf/black
rev: 23.9.1
hooks:
- id: black
args: [
"--line-length", "88"
]
- repo: https://github.com/asottile/reorder-python-imports
rev: v3.12.0
hooks:
- id: reorder-python-imports
- repo: local
hooks:
- id: pytest
name: Run pytest
entry: pytest -v --ignore="docs/*"
language: python
pass_filenames: false
additional_dependencies: [aioboto3==11.2.0]