pyright-python
pyright-python copied to clipboard
Pre-commit install hook doesn't actually install Pyright
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.)
Are you just looking to trigger an install without typechecking? Does #178 help?
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).
i raised #231 which would solve this problem
Yes, but unfortunately that doesn't help because if you run
pyrightviapre-commitit isn't actually installed for the user, so when I runpyright --helpit just sayspyright: not found.As far as I understand it, behind the scenes
pre-commitis just runningpip3 install pyright, so I guess you could either arrange for pip to runpyright --help(effectively) after install (which looks annoying) or maybepre-commitshould 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"
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