Skip to content

Conversation

@halms
Copy link
Contributor

@halms halms commented Jan 30, 2026

It looked like prek was always re-installing my hooks.
Investigating with prek install-hooks -vv showed my a bunch of warnings:

WARN Skipping unhealthy installed hook err=Python executable mismatch: expected /home/user/.local/share/uv/python/cpython-3.12-linux-x86_64-gnu/bin/python, found /home/user/.local/share/uv/python/cpython-3.12.12-linux-x86_64-gnu/bin/python path=/home/user/.cache/prek/hooks/python-WQV7m1JFnTc6mHEMUIFe

/home/user/.local/share/uv/python/cpython-3.12-linux-x86_64-gnu
is a symlink to
/home/user/.local/share/uv/python/cpython-3.12.12-linux-x86_64-gnu
so these do actually match.

This PR fixes this by canonicalizing both paths before comparison to resolve symlinks and ensure consistent path matching regardless of how the Python toolchain is accessed.

  • Canonicalize python_exec in query_python_info after constructing it
  • Canonicalize info.toolchain in check_health before comparison
  • Add integration test for symlinked toolchain scenario

Copilot AI review requested due to automatic review settings January 30, 2026 14:09
@codecov
Copy link

codecov bot commented Jan 30, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.51%. Comparing base (4ddc515) to head (cbfb4bb).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1496      +/-   ##
==========================================
+ Coverage   91.50%   91.51%   +0.01%     
==========================================
  Files          87       87              
  Lines       18154    18149       -5     
==========================================
- Hits        16611    16609       -2     
+ Misses       1543     1540       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a bug where prek incorrectly identifies Python hooks as unhealthy when the Python toolchain path involves symlinks. The issue occurred because the health check compared paths without resolving symlinks, causing mismatches when the same path was accessed through different symlink hierarchies (e.g., cpython-3.12 vs cpython-3.12.12).

Changes:

  • Canonicalizes Python executable paths in query_python_info to resolve symlinks before storing
  • Canonicalizes stored toolchain path in health check before comparison
  • Adds integration test to verify symlinked toolchain scenario works correctly

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
crates/prek/src/languages/python/python.rs Adds path canonicalization in query_python_info (line 78) and check_health (line 203) to resolve symlinks before path comparison
crates/prek/tests/languages/python.rs Adds integration test that creates a symlinked home directory to verify health checks pass when paths involve symlinks

@prek-ci-bot
Copy link

prek-ci-bot bot commented Jan 30, 2026

📦 Cargo Bloat Comparison

Binary size change: +0.00% (22.5 MiB → 22.5 MiB)

Expand for cargo-bloat output

Head Branch Results

 File  .text    Size           Crate Name
 0.3%   0.8% 77.0KiB           prek? <prek::cli::Command as clap_builder::derive::Subcommand>::augment_subcommands
 0.3%   0.6% 59.4KiB            prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.2%   0.6% 56.1KiB            prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.2%   0.5% 43.2KiB            prek prek::run::{{closure}}
 0.2%   0.5% 43.1KiB            prek prek::identify::by_extension::{{closure}}
 0.2%   0.4% 41.5KiB            prek prek::cli::run::run::run::{{closure}}
 0.2%   0.4% 41.0KiB            prek prek::languages::<impl prek::config::Language>::install::{{closure}}
 0.1%   0.3% 32.0KiB           prek? <prek::cli::RunArgs as clap_builder::derive::Args>::augment_args
 0.1%   0.2% 21.6KiB            prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 21.6KiB            prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 21.0KiB    clap_builder clap_builder::parser::parser::Parser::get_matches_with
 0.1%   0.2% 20.8KiB            prek prek::archive::unzip::{{closure}}
 0.1%   0.2% 20.0KiB cargo_metadata? <cargo_metadata::_::<impl serde_core::de::Deserialize for cargo_metadata::Package>::deserialize::__Visitor as serde_core::de::Visitor>::visit_map
 0.1%   0.2% 19.4KiB            prek prek::cli::run::filter::collect_files_from_args::{{closure}}
 0.1%   0.2% 19.4KiB            prek prek::cli::run::filter::collect_files_from_args::{{closure}}
 0.1%   0.2% 19.3KiB            prek <prek::languages::ruby::ruby::Ruby as prek::languages::LanguageImpl>::install::{{closure}}
 0.1%   0.2% 18.6KiB            ring ring_core_0_17_14__x25519_ge_frombytes_vartime
 0.1%   0.2% 18.2KiB             std core::ptr::drop_in_place<prek::languages::<impl prek::config::Language>::install::{{closure}}>
 0.1%   0.2% 18.1KiB       [Unknown] fe_loose_invert
 0.1%   0.2% 18.1KiB      hyper_util hyper_util::client::legacy::client::Client<C,B>::send_request::{{closure}}
36.8%  91.6%  8.3MiB                 And 20110 smaller methods. Use -n N to show more.
40.2% 100.0%  9.1MiB                 .text section size, the file size is 22.5MiB

Base Branch Results

 File  .text    Size           Crate Name
 0.3%   0.8% 77.0KiB           prek? <prek::cli::Command as clap_builder::derive::Subcommand>::augment_subcommands
 0.3%   0.6% 59.4KiB            prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.2%   0.6% 56.1KiB            prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.2%   0.5% 43.2KiB            prek prek::run::{{closure}}
 0.2%   0.5% 43.1KiB            prek prek::identify::by_extension::{{closure}}
 0.2%   0.4% 41.5KiB            prek prek::cli::run::run::run::{{closure}}
 0.2%   0.4% 41.0KiB            prek prek::languages::<impl prek::config::Language>::install::{{closure}}
 0.1%   0.3% 32.0KiB           prek? <prek::cli::RunArgs as clap_builder::derive::Args>::augment_args
 0.1%   0.2% 21.6KiB            prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 21.6KiB            prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 21.0KiB    clap_builder clap_builder::parser::parser::Parser::get_matches_with
 0.1%   0.2% 20.8KiB            prek prek::archive::unzip::{{closure}}
 0.1%   0.2% 20.0KiB cargo_metadata? <cargo_metadata::_::<impl serde_core::de::Deserialize for cargo_metadata::Package>::deserialize::__Visitor as serde_core::de::Visitor>::visit_map
 0.1%   0.2% 19.4KiB            prek prek::cli::run::filter::collect_files_from_args::{{closure}}
 0.1%   0.2% 19.4KiB            prek prek::cli::run::filter::collect_files_from_args::{{closure}}
 0.1%   0.2% 19.3KiB            prek <prek::languages::ruby::ruby::Ruby as prek::languages::LanguageImpl>::install::{{closure}}
 0.1%   0.2% 18.6KiB            ring ring_core_0_17_14__x25519_ge_frombytes_vartime
 0.1%   0.2% 18.2KiB             std core::ptr::drop_in_place<prek::languages::<impl prek::config::Language>::install::{{closure}}>
 0.1%   0.2% 18.1KiB       [Unknown] fe_loose_invert
 0.1%   0.2% 18.1KiB      hyper_util hyper_util::client::legacy::client::Client<C,B>::send_request::{{closure}}
36.8%  91.6%  8.3MiB                 And 20111 smaller methods. Use -n N to show more.
40.2% 100.0%  9.1MiB                 .text section size, the file size is 22.5MiB

@halms halms force-pushed the fix/resolve-python-symlinks branch from d4fd812 to b8c78d4 Compare January 30, 2026 14:33
Copilot AI review requested due to automatic review settings January 30, 2026 14:36
@halms halms force-pushed the fix/resolve-python-symlinks branch from b8c78d4 to d4fd812 Compare January 30, 2026 14:36
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@j178 j178 added the bug Something isn't working label Jan 30, 2026
@j178 j178 changed the title Canonicalize Python executable paths before comparison in health check Don't Python executable paths health check Jan 30, 2026
@j178 j178 changed the title Don't Python executable paths health check Don't check Python executable paths health check Jan 30, 2026
@j178
Copy link
Owner

j178 commented Jan 30, 2026

Thanks! I simplified it a bit so it just doesn’t check the Python executable path at all. I think it’s not necessary, and it lines up with how pre-commit works.

Copilot AI review requested due to automatic review settings January 30, 2026 19:18
@j178 j178 force-pushed the fix/resolve-python-symlinks branch from 2d995e6 to 876c6fa Compare January 30, 2026 19:18
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

@j178 j178 force-pushed the fix/resolve-python-symlinks branch from 876c6fa to 8d6991a Compare January 30, 2026 19:39
@j178 j178 changed the title Don't check Python executable paths health check Don't check Python executable path in health check Jan 30, 2026
halms and others added 2 commits January 30, 2026 23:06
When checking the health of a Python hook installation, the stored
toolchain path and the queried path may differ if symlinks are involved
(e.g., when the Python executable or a parent directory is a symlink).

This change canonicalizes both paths before comparison to resolve
symlinks and ensure consistent path matching regardless of how the
Python toolchain is accessed.

- Canonicalize `python_exec` in `query_python_info` after constructing it
- Canonicalize `info.toolchain` in `check_health` before comparison
- Add integration test for symlinked toolchain scenario
@halms halms force-pushed the fix/resolve-python-symlinks branch from 8d6991a to cbfb4bb Compare January 30, 2026 22:06
@halms
Copy link
Contributor Author

halms commented Jan 30, 2026

Thanks! I simplified it a bit so it just doesn’t check the Python executable path at all. I think it’s not necessary, and it lines up with how pre-commit works.

Okay, sounds good to me. I don't mind.

@j178 j178 merged commit 1baa911 into j178:master Jan 31, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants