Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add .pre-commit-hooks.yaml #769

Closed
wants to merge 1 commit into from

Conversation

r-barnes
Copy link
Contributor

Pre-submission checklist

  • I've ran the linters locally and fixed lint errors related to the files I modified in this PR. You can install the linters by running pip install -r requirements-dev.txt && pre-commit install
  • pre-commit run

Summary

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

Test Plan

@connernilsen
Copy link
Contributor

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
Copy link
Contributor

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

@facebook-github-bot
Copy link
Contributor

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

@facebook-github-bot
Copy link
Contributor

@connernilsen merged this pull request in 4f8e05b.

@eggplants
Copy link

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants