pyright-python icon indicating copy to clipboard operation
pyright-python copied to clipboard

pre commit won't find my pyrightconfig.json settings

Open Aydin-ab opened this issue 1 year ago • 4 comments

Hello, I've just started using pyright and pre-commit so everything is still new to me and I'm aware the issue is probably because of my inexperience.

My project folder looks like that:

project/
    .pre-commit-config.yaml
    pyrightconfig.json
    repo1/
    repo2/
        src/
            module1.py
            module2.py
            ...

I want pyright to run only on the staged modules that are located at project/repo2/src/utils/ and nowhere else.

My pyrightconfig.json is

{
  "include": [
    "repo2/src"
  ],
  "typeCheckingMode": "strict"
}

My .pre-commit-config.yaml:

repos:
  - repo: https://github.com/RobertCraigie/pyright-python
    rev: v1.1.377
    hooks:
    - id: pyright
      name: pyright
      language: system
      entry: pyright
      types: [python]
      args: ["--project", "pyrightconfig.json", "--verbose"]
      # args: ["--project=pyrightconfig.json", "--verbose"]  # Tried this too
      

If I run pyright at the project root, I get what I want. If I run pre-commit run pyright I don't get the same behavior at all. The verbose arguments aren't even read. The files that are selected are all the ones in the staged, but I want to restrict pyright on the ones at repo2/src/ only

I guess my real question is: How do I make pre-commit run pyright behave as if I'm running pyright in my own conda environment at the project/ location

Aydin-ab avatar Aug 28 '24 16:08 Aydin-ab

Check that the .git directory is in the root of the project, not at a higher level. Shold be:

project/
    .pre-commit-config.yaml
    pyrightconfig.json
    .git/
    repo1/
    repo2/
        src/
            module1.py
            module2.py

pantafive avatar Sep 25 '24 16:09 pantafive

Has this been solved? I'm getting the same problem where my pyrightconfig.json is not being detected. When I run pyright --project ./pyrightconfig.json I get the desired output but when I run the pre-commit hook with the same argument it doesn't detect the config. My .git, .pre-commit-config.yaml and pyrightconfig.json are in the same top level folder.

3raser95 avatar Oct 24 '24 08:10 3raser95

I actually managed to fix it by manually setting my pythonpath parameter like this:

- repo: https://github.com/RobertCraigie/pyright-python
    rev: v1.1.386
    hooks:
      - id: pyright
        name: Pyright Type Checking
        language: python
        types: [python]
        args: ["--pythonpath", "/usr/local/bin/python"]

3raser95 avatar Oct 24 '24 09:10 3raser95

At least it finds the one from pyproject.toml which is perfect for me.

ssbarnea avatar Nov 22 '24 11:11 ssbarnea

Sorry for the delayed response. I'm not sure why this is happening but I no longer use pre-commit so I don't have capacity to investigate more deeply. If you're still running into this I'd recommend asking for help from the pre-commit folks directly

RobertCraigie avatar May 03 '25 16:05 RobertCraigie