[!NOTE]
This pre-commit hook changed significantly from version 0.0.1 to version 0.42.0.
See the Migration from 0.0.1 section for how to upgrade.
Usage
There are two ways to use the pyrefly-check hook. Add one of the following to your project’s .pre-commit-config.yaml:
Option 1: System Install
Use an already-installed pyrefly so your CLI/CI/IDE versions stay in sync:
repos:
- repo: https://github.com/facebook/pyrefly-pre-commit
rev: 0.60.2 # Note: this is the version of the pre-commit hook, NOT the pyrefly version used for type checking
hooks:
- id: pyrefly-check
name: Pyrefly (type checking)
pass_filenames: false # Recommended to do full repo checks. However, you can change this to `true` to only check changed files
language: system # Use system-installed pyrefly
This expects pyrefly to already be available on your PATH (e.g., installed via your project’s dependencies).
The hook will be able to see your project’s other installed dependencies when type checking.
Option 2: Managed Install
Let pre-commit manage the pyrefly installation:
repos:
- repo: https://github.com/facebook/pyrefly-pre-commit
rev: 0.60.2 # The pyrefly version to use
hooks:
- id: pyrefly-check
name: Pyrefly (type checking)
pass_filenames: false
additional_dependencies: [ ... ] # Your project's dependencies
Note that you must list all of your project’s dependencies (aside from pyrefly, which is bundled with the hook)
in additional_dependencies for type checking to work correctly.
Examples
See the examples/ directory for complete working examples of both approaches:
We run pyrefly check at the repo root and ignore filenames from pre-commit (pass_filenames: false), since Pyrefly checks project state rather than individual files.
The hook targets stages: [pre-commit, pre-merge-commit, pre-push, manual] so you can run it locally and in CI.
You can skip temporarily with SKIP=pyrefly-check git commit -m "...".
In version 0.0.1, this repository offered two hooks, pyrefly-typecheck-system and
pyrefly-typecheck-specific-version. Since 0.42.0, these hooks have been consolidated
into a single pyrefly-check hook.
pyrefly-pre-commit
A pre-commit hook for Pyrefly.
Usage
There are two ways to use the
pyrefly-checkhook. Add one of the following to your project’s.pre-commit-config.yaml:Option 1: System Install
Use an already-installed
pyreflyso your CLI/CI/IDE versions stay in sync:This expects
pyreflyto already be available on your PATH (e.g., installed via your project’s dependencies). The hook will be able to see your project’s other installed dependencies when type checking.Option 2: Managed Install
Let pre-commit manage the pyrefly installation:
Note that you must list all of your project’s dependencies (aside from
pyrefly, which is bundled with the hook) inadditional_dependenciesfor type checking to work correctly.Examples
See the
examples/directory for complete working examples of both approaches:examples/system-hook/- demonstrates system installexamples/specific-version-hook/- demonstrates managed installInstallation
Once the hook is set up, install and run:
Behavior and Defaults
pyrefly checkat the repo root and ignore filenames from pre-commit (pass_filenames: false), since Pyrefly checks project state rather than individual files.stages: [pre-commit, pre-merge-commit, pre-push, manual]so you can run it locally and in CI.SKIP=pyrefly-check git commit -m "...".argsto pass flags to Pyrefly, e.g.["--ignore=missing-source"]. See full config options here: https://pyrefly.org/en/docs/configuration/CI Example
Use the official
pre-commit/actionto run the hook in GitHub Actions:Migration from 0.0.1
In version 0.0.1, this repository offered two hooks,
pyrefly-typecheck-systemandpyrefly-typecheck-specific-version. Since 0.42.0, these hooks have been consolidated into a singlepyrefly-checkhook.To migrate from
pyrefly-typecheck-system, change:to:
To migrate from
pyrefly-typecheck-specific-version, change:to:
Note that if you were using
pyrefly-typecheck-specific-versionwith a version of pyrefly older than 0.42.0, you’ll need to upgrade to 0.42.0 or newer.License
MIT