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

Pre-commit install hook doesn't actually install Pyright #225

Open
Timmmm opened this issue Oct 27, 2023 · 5 comments
Open

Pre-commit install hook doesn't actually install Pyright #225

Timmmm opened this issue Oct 27, 2023 · 5 comments

Comments

@Timmmm
Copy link

Timmmm commented Oct 27, 2023

Pyright is only actually installed on the first use. This makes installing Pyright in a docker image so you avoid re-downloading it for every CI run (and depending on unreliable networks / github servers) difficult.

Here's what we have to do currently:

RUN python3 -m pip install --no-cache-dir pre-commit

# Make a git repo with a pre-commit config that we can use to pre-install the
# hook tools so they aren't installed on every run.
WORKDIR /opt/repo

# Add the pre-commit config (this just contains the hooks we use).
COPY .pre-commit-config.yaml .

# Pre-install tools used by the pre-commit hooks we have so that we don't
# have to install them on every CI run. pre-commit requires us to be in a git
# repo.
RUN git init --quiet && pre-commit install-hooks --config .pre-commit-config.yaml

# Unfortunately the Pyright hook does not *actually* install Pyright when you
# use install-hooks so we have to run it on some Python.
RUN printf '"""\nTest\n"""\n\nprint("hello")\n' > main.py && \
    git config --global user.email "[email protected]" && \
    git config --global user.name "Your Name" && \
    git add . && \
    git commit -m "Add python script" && \
    pre-commit run -a

# This prevents the Pyright hook from accessing the network.
ENV PYRIGHT_PYTHON_IGNORE_WARNINGS=1

It's a mild annoyance. (Also slightly annoying that pre-commit forces you to make a git repo to install things.)

@Kache
Copy link

Kache commented Nov 9, 2023

Are you just looking to trigger an install without typechecking? Does #178 help?

@Timmmm
Copy link
Author

Timmmm commented Nov 9, 2023

Yes, but unfortunately that doesn't help because if you run pyright via pre-commit it isn't actually installed for the user, so when I run pyright --help it just says pyright: not found.

As far as I understand it, behind the scenes pre-commit is just running pip3 install pyright, so I guess you could either arrange for pip to run pyright --help (effectively) after install (which looks annoying) or maybe pre-commit should be able to run a post-install command (it can't at the moment).

@DetachHead
Copy link

i raised #231 which would solve this problem

@acefei
Copy link

acefei commented Jan 19, 2024

Yes, but unfortunately that doesn't help because if you run pyright via pre-commit it isn't actually installed for the user, so when I run pyright --help it just says pyright: not found.

As far as I understand it, behind the scenes pre-commit is just running pip3 install pyright, so I guess you could either arrange for pip to run pyright --help (effectively) after install (which looks annoying) or maybe pre-commit should be able to run a post-install command (it can't at the moment).

Your comment inspired me, and I found a workaround.

COPY .pre-commit-config.yaml .
SHELL ["/bin/bash", "-c"]
RUN git init . && \
    pre-commit install-hooks && \
    eval "\$(find ~/.cache/pre-commit | grep 'bin/pyright\$') --help"

@DetachHead
Copy link

DetachHead commented Jan 19, 2024

i've created a fork of pyright that fixes this issue: https://github.com/detachhead/basedpyright

it includes all of the node dependencies as part of the pypi package, so it doesn't need to install anything on its initial run.

# .pre-commit-config.yaml

repos:
  - repo: https://github.com/DetachHead/basedpyright
    rev: v1.8.0
    hooks:
    - id: basedpyright

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

No branches or pull requests

4 participants