commitizen icon indicating copy to clipboard operation
commitizen copied to clipboard

Installing pre-commit hook step in `cz init` fails when using rye

Open my1e5 opened this issue 9 months ago • 0 comments

Description

I'm using rye to manage my python project - it's similar to poetry. But during cz init the pre-commit hook install step fails.

Steps to reproduce

Similar to poetry, using rye I add commitizen as a dev dependency

$ rye add commitizen --dev

Then I run

$ rye run cz init
Welcome to commitizen!

Answer the questions to configure your project.
For further configuration visit:

https://commitizen-tools.github.io/commitizen/config/

? Please choose a supported config file:  pyproject.toml
? Please choose a cz (commit rule): (default: cz_conventional_commits) cz_conventional_commits
? Choose the source of the version: pep621: Get and set version from pyproject.toml:project.version field
No Existing Tag. Set tag to v0.0.1
? Choose version scheme:  pep440
? Please enter the correct version format: (default: "$version")
? Create changelog automatically on bump Yes
? Keep major version zero (0.x) during breaking changes Yes
? What types of pre-commit hook you want to install? (Leave blank if you don't want to install) done (2 selections)
Failed to install pre-commit hook.
Error running pre-commit install --hook-type commit-msg --hook-type pre-push.Outputs are attached below:
stdout:
stderr: 'pre-commit' is not recognized as an internal or external command,
operable program or batch file.

Current behavior

The install pre-commit hook stage fails if you select hooks to install.

I guess this is because it tries to run

$ pre-commit install --hook-type commit-msg --hook-type pre-push

which with rye doesn't work. Instead rye expects you to 1) have pre-commit added as a dependency and 2) run the command as

$ rye add pre-commit --dev
$ rye run pre-commit install --hook-type commit-msg --hook-type pre-push

Desired behavior

if you skip the pre-commit step in cz init then you can do it manually. But new users are unaware this can fail. And the problem is the whole cz init step fails because of this. So you have to start again. It would nice if rye run cz init was supported if that's possible.

Screenshots

No response

Environment

$ rye run cz version
3.25.0
$ rye run python --version
Python 3.12.2
$ rye --version
rye 0.33.0
commit: 0.33.0 (58523f69f 2024-04-24)
platform: windows (x86_64)
self-python: [email protected]
symlink support: true
uv enabled: true

my1e5 avatar May 16 '24 12:05 my1e5