astral-sh / ruff-pre-commit

A pre-commit hook for Ruff.
Apache License 2.0
802 stars 38 forks source link

Failed to create cache file #62

Closed bootswithdefer closed 6 months ago

bootswithdefer commented 6 months ago

Getting below error with 0.1.12 but works fine with 0.1.11. If I create .ruff_cache/0.1.12 then it proceeds without error.

pre-commit 3.6.0 ruff 0.1.13 Amazon Linux 2 Python 3.11

Error running pre-commit run -a

ruff.....................................................................Failed
- hook id: ruff
- exit code: 2

ruff failed
  Cause: Failed to create cache file '/home/me/src/repo/.ruff_cache/0.1.12/6018100345838758466'
  Cause: No such file or directory (os error 2)

My hook:

  - repo: https://github.com/astral-sh/ruff-pre-commit
    rev: v0.1.12
    hooks:
      - id: ruff
        args:
          - --line-length
          - "140"
          - --ignore
          - "E501"
trag1c commented 6 months ago

Duplicate of https://github.com/astral-sh/ruff/issues/9489, I believe the fix is coming soon in 0.1.13 :)

charliermarsh commented 6 months ago

Should be fixed now via v0.1.13 -- please let me know if not!

lemaadi commented 3 months ago

Hi @charliermarsh

Thank's for your efforts to maintain this great tool

We are using the latest version 0.3.5 in our pre-commit-config.yaml file :

repos:
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v4.4.0
    hooks:
      - id: check-merge-conflict
      - id: check-added-large-files
      - id: check-ast
      - id: check-symlinks
      - id: check-yaml
      - id: trailing-whitespace
      - id: check-json
      - id: debug-statements
      - id: pretty-format-json
        args: ["--autofix", "--allow-missing-credentials"]
        exclude: Pipfile.lock
  - repo: https://github.com/charliermarsh/ruff-pre-commit
    rev: v0.3.5
    hooks:
      - id: ruff
        args:
          - --fix
      # Run the formatter.
      - id: ruff-format
  - repo: https://github.com/psf/black
    rev: 23.3.0
    hooks:
      - id: black
        args: ["--target-version", "py311"]
  - repo: https://github.com/asottile/pyupgrade
    rev: v3.7.0
    hooks:
      - id: pyupgrade
        args: [--py310-plus]

And running the lint in github actions workflow with this command docker compose run -u root --rm app bash -c "git config --global --add safe.directory /app && pre-commit run --all-files" But we are getting this error :

ruff.....................................................................Failed
- hook id: ruff
- exit code: 2

error: Failed to initialize cache at /app/.ruff_cache: Permission denied (os error 13)
ruff failed
  Cause: Failed to create temporary file
  Cause: No such file or directory (os error 2) at path "/app/.ruff_cache/0.3.5/.tmpx87Ap3"

ruff-format..............................................................Failed
- hook id: ruff-format
- exit code: 2

error: Failed to initialize cache at /app/.ruff_cache: Permission denied (os error 13)
ruff failed
  Cause: Failed to create temporary file
  Cause: No such file or directory (os error 2) at path "/app/.ruff_cache/0.3.5/.tmpHIXT8j"

We tried to update the Dockerfile :

FROM python:3.11-slim-buster

# Prevent __pycache__ folder and files
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

RUN set -ex \
  && apt-get update \
  && apt-get install -qq -y --no-install-recommends \
  make \
  curl \
  gcc \
  git \
  jq \
  gettext \
  procps \
  python3-dev \
  sudo \
  postgresql-client \
  libssl-dev \
  swig \
  && pip install pipenv \
  && rm -rf /var/lib/apt/lists/* /usr/share/doc /usr/share/man \
  && apt-get clean

WORKDIR /app

# Add Tini
ENV TINI_VERSION v0.19.0
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
RUN chmod +x /tini

# Create appuser consumer for the application
RUN groupadd -g 9898 appuser && useradd --create-home -r -u 9898 -g appuser appuser -s /bin/bash
RUN usermod -aG sudo appuser
RUN mkdir /public_assets
RUN chown -R appuser:appuser /public_assets
RUN chown -R appuser:appuser /app
RUN chown -R appuser:appuser /etc/environment
RUN echo "appuser ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers

# Celery beat
RUN mkdir -p /home/celery/var/run
RUN chown -R appuser:appuser /home/celery/var/run && chmod 755 /home/celery/var/run

# Ruff
RUN mkdir -p /app/.ruff_cache
RUN chown -R appuser:appuser /app/.ruff_cache && chmod 755 /app/.ruff_cache

COPY Pipfile Pipfile.lock ./
RUN pipenv install --system --deploy --dev --verbose

ADD . ./

RUN chmod +x /app/docker-entrypoint.sh

USER appuser
EXPOSE 8000

ENTRYPOINT ["/tini", "-g", "--", "/app/docker-entrypoint.sh"]

But it didn't work Note that we are using pre-commit = "==3.7.0"

Thank you

dhruvmanila commented 3 months ago

@lemaadi thanks for the detailed write-up. I think it would be useful to create a new issue instead as otherwise it might get missed because the original issue is closed.