-
Notifications
You must be signed in to change notification settings - Fork 41
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
Nix: No such file or directory: '~/.cache/pre-commit/...python3.10/bin/ruff' #22
Comments
Could this be related to astral-sh/ruff#1699? |
Seems likely, I have that same experience:
I can add the nixpkgs ruff to my flake.nix, which allows me to call |
There is a workaround, but it's really really ugly: rm '<offending ruff binary>'
ln -s $(which ruff) '<offending ruff binary>' |
That workaround works, but obviously only until pre-commit regenerates that cache! It would be nice a more proper fix for this at some point :) |
This is indeed related to astral-sh/ruff#1699 and doesn't have a fix here. (I missed the repo context while writing my original suggestion) The contract for a Nix specific suggestion for people coming from googleThe beginnings of a fix might look like invoking autoPatchelf in the shell hook.An example ---
repos:
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.0.229'
hooks:
- id: ruff An example {
description = "Dev env";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
flake-compat.url = "github:edolstra/flake-compat";
flake-compat.flake = false;
};
outputs = {
nixpkgs,
flake-utils,
...
}:
flake-utils.lib.eachDefaultSystem (system: let
pkgs = import nixpkgs {
inherit system;
overlays = [];
};
in {
devShells.default = pkgs.mkShell {
name = "dev-env";
buildInputs = with pkgs; [
pre-commit
stdenv.cc.cc.libgcc
];
nativeBuildInputs = [ pkgs.autoPatchelfHook ];
shellHook = ''
pre-commit install
# oddly the python pre-commit hook doesn't actually install things during install
# here's a hack to force ruff into the pre-commit cache (works but is not great)
pre-commit run
# pre-commits output is a bit verbose when it succeeds, choose your own output wrangling
patch=$(autoPatchelf ~/.cache/pre-commit/)
if [[ $? -ne 0 ]]; then
echo "$patch"
exit 1
else
echo "patched ~/.cache/pre-commit"
fi
'';
};
});
} There are probably a number of ways to improve how this is handled. Improvements could include: a better way to get the pre-commit hook to actually install during 'install', better output wrapping, a better understanding of how/when pre-commit chooses to install things to
|
I believe this issue can be closed and, perhaps, tracked somewhere more nix specific. |
I agree. This repo is a way to access the problem, but it doesn't itself have a problem. Let's close it. The approach in @anund's post works on NixOS, but |
If I'm understanding correctly, the "right way" to fix this requires:
But a big part of the reason to be a 1-type person is because you don't want to deal with 2-type problems anymore. Maybe our hero is out there. Maybe they'll fix it the right way. But I'm probably not that hero, so I'm going to seek a better workaround--one that doesn't involve asking pip to package rust binaries in the first place. My initial explorations of https://github.com/cachix/pre-commit-hooks.nix indicate that it wants to be configured in a way that would break pre-commit for other contributors to the repo. It will say things like this:
My team would not like it if I made that change (they're not all nix users). But perhaps... A. a ruff hook can be added to pre-commit-hooks.nix This would solve my problem, but maybe it's overkill? Maybe it won't solve your problem? I'm curious if others think it's a sane approach. |
For anyone coming here still looking for a solution, here's what worked for me:
|
I'm working on a project which uses ruff via pre-commit. I've simplified the
.pre-commit-config.yaml
to the following:When I run
pre-commit run --all-files
I get the following:Which is weird, because that file definitely exists.
This is on my Linux machine (NixOS 23.05). I've been working around it by just doing the linting on macOS, but that's kind of a pain. Any idea what I can do to fix this?
The text was updated successfully, but these errors were encountered: