facebook / pyre-check

Performant type-checking for python.
https://pyre-check.org/
MIT License
6.86k stars 437 forks source link

Add .pre-commit-hooks.yaml #769

Closed r-barnes closed 1 year ago

r-barnes commented 1 year ago

Pre-submission checklist

Summary

This should make the Pyre compatible as a pre-commit tool

Test Plan

connernilsen commented 1 year ago

Hey @r-barnes, this sounds like a great idea. Let me bring it up in our next team meeting, and I'll let you know what they think.

facebook-github-bot commented 1 year ago

@connernilsen has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot commented 1 year ago

@connernilsen has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot commented 1 year ago

@connernilsen merged this pull request in facebook/pyre-check@4f8e05badeda0204cc09142a4bf1bb043f96bfad.

eggplants commented 1 year ago

This hook is not working due to failure of pip install .. pyproject.toml in the project root does not contain PEP621 configuration for building the package.

$ pre-commit
[INFO] Installing environment for https://github.com/facebook/pyre-check.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: command: ('/home/eggplants/.cache/pre-commit/repo6fvdksto/py_en
v-python3.9/bin/python', '-mpip', 'install', '.')
return code: 1
stdout:
    Processing /home/eggplants/.cache/pre-commit/repo6fvdksto
      Installing build dependencies: started
      Installing build dependencies: finished with status 'done'
      Getting requirements to build wheel: started
      Getting requirements to build wheel: finished with status 'error'
stderr:
      error: subprocess-exited-with-error

      × Getting requirements to build wheel did not run successfully.
      │ exit code: 1
      ╰─> [14 lines of output]
          error: Multiple top-level packages discovered in a flat-layout: ['api', 'stubs', 'source', 'client', 'pysa_
tutorial', 'pyre_extensions'].

          To avoid accidental inclusion of unwanted files or directories,
          setuptools will not proceed with this build.

          If you are trying to create a single distribution with multiple packages
          on purpose, you should not rely on automatic discovery.
          Instead, consider the following options:

          1. set up custom discovery (`find` directive with `include` or `exclude`)
          2. use a `src-layout`
          3. explicitly set `py_modules` or `packages` with a list of names

          To find more information, look for "package discovery" on setuptools docs.
          [end of output]

      note: This error originates from a subprocess, and is likely not a problem with pip.
    error: subprocess-exited-with-error

    × Getting requirements to build wheel did not run successfully.
    │ exit code: 1
    ╰─> See above for output.

    note: This error originates from a subprocess, and is likely not a problem with pip.
Check the log at /home/eggplants/.cache/pre-commit/pre-commit.log

docker_image hook would be a good choice to create a pre-commit hook for this project.

-   id: pyre-check-docker
    name: Run pyre check with docker
    language: docker_image
    entry: ghcr.io/facebook/pyre-check:X.Y.Z

Creating Dockerfile, building and publishing image to a container registry such as ghcr.io are needed.

Sample

Hook configuration file: https://github.com/igorshubovych/markdownlint-cli/blob/24627da39ba937d102861a5b42f81847c8f57b5e/.pre-commit-hooks.yaml#L15-L28

GitHub workflow for building and publishing: https://github.com/igorshubovych/markdownlint-cli/blob/master/.github/workflows/publish-container-image.yml

Published image: https://github.com/igorshubovych/markdownlint-cli/pkgs/container/markdownlint-cli

bisrat-otterai commented 1 month ago

Are there additional steps in order to be able to use pyre as a pre-commit hook? It seems that even if the issues raised by @eggplants are addressed, the pre-commit framework requires the library to be able to process a list of files which isn't something Pyre appears to be able to do.

eggplants commented 1 month ago

@behrooz-otter @bisrat-otterai try murilo-cunha/mirrors-pyre.

My sample: https://github.com/eggplants/getjump/blob/927775c85d3e8c0347fed9d56b03132f90f3e9b7/.pre-commit-config.yaml#L62-L68 https://github.com/eggplants/getjump/blob/927775c85d3e8c0347fed9d56b03132f90f3e9b7/.pyre_configuration