Skip to content

feat: add support for python -m prek#1686

Merged
j178 merged 2 commits intoj178:masterfrom
uplsh580:python/m_option
Feb 27, 2026
Merged

feat: add support for python -m prek#1686
j178 merged 2 commits intoj178:masterfrom
uplsh580:python/m_option

Conversation

@uplsh580
Copy link
Contributor

Related Issue: #1685

Summary

prek can now be run with python -m prek in addition to the prek command, matching common Python CLI tools like black, ruff, and uv.

Motivation

  • Consistency: Many Python tools support python -m
  • Virtual environments: Makes it clear which Python interpreter (and venv) is used
  • Scripts & CI: Explicit execution environment
  • Tool integration: Some tools only support the python -m form

Changes

  • Add python/prek/ package with __init__.py and __main__.py
  • Set python-source = "python" in pyproject.toml so maturin includes the Python package
  • __main__.py invokes the prek binary next to the Python executable (e.g. .venv/bin/prek with .venv/bin/python), falling back to PATH if not found

@uplsh580 uplsh580 requested a review from j178 as a code owner February 22, 2026 00:55
@uplsh580
Copy link
Contributor Author

Validation

image

@codecov
Copy link

codecov bot commented Feb 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.59%. Comparing base (e3857a5) to head (b714eee).
⚠️ Report is 5 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1686      +/-   ##
==========================================
- Coverage   91.65%   91.59%   -0.06%     
==========================================
  Files          96       96              
  Lines       18665    18880     +215     
==========================================
+ Hits        17107    17294     +187     
- Misses       1558     1586      +28     

☔ 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.

@uplsh580
Copy link
Contributor Author

uplsh580 commented Feb 22, 2026

Actually, This comment motivated me to open this PR.
apache/airflow#62277 (comment)

@uplsh580 uplsh580 marked this pull request as draft February 22, 2026 01:20
@uplsh580 uplsh580 marked this pull request as ready for review February 22, 2026 01:20
@uplsh580 uplsh580 closed this Feb 22, 2026
@uplsh580 uplsh580 reopened this Feb 22, 2026
@uplsh580
Copy link
Contributor Author

https://github.com/j178/prek/actions/runs/22267961503/job/64417541100?pr=1686

I think the prek::run color failure does not appear to be related to this PR. The changes here only add Python package support for python -m prek and do not modify any Rust code or the prek run logic. The color test checks ANSI color output when running the prek binary directly, and the snapshot mismatch is likely due to CI environment differences (e.g., terminal emulation or how cargo-llvm-cov captures output) rather than these changes.

@prek-ci-bot
Copy link

prek-ci-bot bot commented Feb 27, 2026

📦 Cargo Bloat Comparison

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

Expand for cargo-bloat output

Head Branch Results

 File  .text    Size             Crate Name
 0.3%   0.8% 80.2KiB             prek? <prek::cli::Command as clap_builder::derive::Subcommand>::augment_subcommands
 0.3%   0.7% 71.3KiB              prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.3%   0.6% 65.6KiB              prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.2%   0.5% 51.2KiB annotate_snippets annotate_snippets::renderer::render::render
 0.2%   0.5% 50.5KiB              prek prek::languages::<impl prek::config::Language>::install::{{closure}}
 0.2%   0.4% 41.2KiB              prek prek::cli::run::run::run::{{closure}}
 0.2%   0.4% 39.2KiB              prek prek::run::{{closure}}
 0.1%   0.3% 31.1KiB             prek? <prek::cli::RunArgs as clap_builder::derive::Args>::augment_args
 0.1%   0.3% 28.5KiB      serde_saphyr saphyr_parser_bw::scanner::Scanner<T>::fetch_more_tokens
 0.1%   0.2% 24.7KiB             prek? <prek::config::_::<impl serde_core::de::Deserialize for prek::config::Config>::deserialize::__Visitor as serde_core::de::Visitor>::visit_map
 0.1%   0.2% 22.8KiB      serde_saphyr saphyr_parser_bw::scanner::Scanner<T>::fetch_more_tokens
 0.1%   0.2% 22.7KiB              prek <prek::languages::ruby::ruby::Ruby as prek::languages::LanguageImpl>::install::{{closure}}
 0.1%   0.2% 22.5KiB              prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 21.1KiB      clap_builder clap_builder::parser::parser::Parser::get_matches_with
 0.1%   0.2% 20.5KiB              prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 20.0KiB               std core::ptr::drop_in_place<prek::languages::<impl prek::config::Language>::install::{{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.5KiB              prek prek::archive::unzip::{{closure}}
 0.1%   0.2% 18.7KiB     serde_saphyr? <serde_saphyr::de::YamlDeserializer as serde_core::de::Deserializer>::deserialize_map
 0.1%   0.2% 18.6KiB     serde_saphyr? <serde_saphyr::de::YamlDeserializer as serde_core::de::Deserializer>::deserialize_map
38.3%  91.7%  9.1MiB                   And 21095 smaller methods. Use -n N to show more.
41.8% 100.0% 10.0MiB                   .text section size, the file size is 23.8MiB

Base Branch Results

 File  .text    Size             Crate Name
 0.3%   0.7% 71.3KiB              prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.3%   0.7% 66.4KiB             prek? <prek::cli::Command as clap_builder::derive::Subcommand>::augment_subcommands
 0.3%   0.6% 65.6KiB              prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.2%   0.5% 51.2KiB annotate_snippets annotate_snippets::renderer::render::render
 0.2%   0.5% 50.5KiB              prek prek::languages::<impl prek::config::Language>::install::{{closure}}
 0.2%   0.4% 41.7KiB              prek prek::cli::run::run::run::{{closure}}
 0.2%   0.4% 39.1KiB              prek prek::run::{{closure}}
 0.1%   0.3% 32.0KiB             prek? <prek::cli::RunArgs as clap_builder::derive::Args>::augment_args
 0.1%   0.3% 28.5KiB      serde_saphyr saphyr_parser_bw::scanner::Scanner<T>::fetch_more_tokens
 0.1%   0.2% 24.7KiB             prek? <prek::config::_::<impl serde_core::de::Deserialize for prek::config::Config>::deserialize::__Visitor as serde_core::de::Visitor>::visit_map
 0.1%   0.2% 22.8KiB      serde_saphyr saphyr_parser_bw::scanner::Scanner<T>::fetch_more_tokens
 0.1%   0.2% 22.7KiB              prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 21.1KiB      clap_builder clap_builder::parser::parser::Parser::get_matches_with
 0.1%   0.2% 20.5KiB              prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 20.3KiB              prek prek::main
 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.6KiB              prek prek::archive::unzip::{{closure}}
 0.1%   0.2% 19.3KiB               std core::ptr::drop_in_place<prek::languages::<impl prek::config::Language>::install::{{closure}}>
 0.1%   0.2% 19.2KiB              prek <prek::languages::ruby::ruby::Ruby as prek::languages::LanguageImpl>::install::{{closure}}
 0.1%   0.2% 18.7KiB     serde_saphyr? <serde_saphyr::de::YamlDeserializer as serde_core::de::Deserializer>::deserialize_map
38.3%  91.8%  9.1MiB                   And 21004 smaller methods. Use -n N to show more.
41.7% 100.0%  9.9MiB                   .text section size, the file size is 23.8MiB

@j178 j178 enabled auto-merge (rebase) February 27, 2026 10:15
@j178 j178 disabled auto-merge February 27, 2026 10:15
@j178 j178 merged commit a64312f into j178:master Feb 27, 2026
63 of 66 checks passed
@j178
Copy link
Owner

j178 commented Feb 27, 2026

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants