Skip to content

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

@Timmmm

Description

@Timmmm

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 "you@example.com" && \
    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.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions