Integrations with other tools¶
Git hooks¶
Git hooks automatically run code when you perform some operation in git, like a commit or a push.
Two useful hooks to consider are the pre-commit and pre-push hooks, which, as the names imply, are run before a commit is made or before commits are pushed to a remote.
Git hooks are installed in the .git/hooks/ directory in a repository, which are not synced across copies of the repository.
If you're going to use them, you need to set them up in each repository copy.
You can do this manually or using one of the tools listed below.
Manual configuration¶
To run scilo as a pre-commit hook, create and/or edit the ${PROJECT_ROOT}/.git/hooks/pre-commit file to include:
Ensure the file is executable with chmod +x ${PROJECT_ROOT}/.git/hooks/pre-commit.
scilo will now run before each commit.
If you prefer to run scilo as part of a pre-push hook1, add the above to ${PROJECT_ROOT}/.git/hooks/pre-push, instead.
Pre-commit¶
pre-commit is a tool to manage git pre-commit hooks within the repository itself.
Install pre-commit using your environment or package manager of choice, then add the following lines to the .pre-commit-config.yaml file in the project's root directory:
If you already have a .pre-commit-config.yaml file with existing hooks and a repo: header, don't duplicate the repos: line.
For example:
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks # (1)!
rev: v1.2.3
hooks:
- id: trailing-whitespace
- repo: https://gitlab.com/jrhawley/scilo # (2)!
rev: v0.1.0
hooks:
- id: lint
- This is a
pre-commithook from another repository - This is the
pre-commithook fromscilo
The lint hook runs all configured lints on the project.
If you only want to run a subset of lints, you can list the ids of the selected lints.
For example:
repos:
- repo: https://gitlab.com/jrhawley/scilo
rev: v0.1.0
hooks: # (1)!
- id: root_dirs
- id: root_files
- These hooks will only check for required directories and files in the project root.
Alternatively, you can leave - id: lint alone in .pre-commit-config.yaml and configure which lints run in the configuration file.
Running scilo lint from the terminal or through pre-commit will respect the configuration in the project's scilo.toml file.
Prek¶
prek is a drop-in replacement of pre-commit, built in Rust with slightly different goals in mind.
If you use prek instead of pre-commit, the above configuration for pre-commit should still work.
-
See this blog post for concerns about
pre-commithooks and wherepre-pushhooks are preferable. ↩