Open my1e5 opened 6 months ago
To add to this. If I install cz
globally using pip
.
$ pip install --user -U Commitizen
Then cz bump
works in all my non-rye python projects. But in my rye
project even running cz
directly gives
$ cd my-rye-managed-project/
$ ls -a
. .. .git .gitignore .pre-commit-config.yaml .python-version .ruff_cache .venv dist pyproject.toml README.md requirements.lock requirements-dev.lock src
$ cz bump
fatal: not a git repository (or any of the parent directories): .git
Did some more digging
$ rye run cz --debug bump
fatal: not a git repository (or any of the parent directories): .git
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "C:\Users\my1e5\Projects\my1e5\myproject\.venv\Scripts\cz.exe\__main__.py", line 8, in <module>
File "C:\Users\my1e5\Projects\my1e5\myproject\.venv\Lib\site-packages\commitizen\cli.py", line 607, in main
args.func(conf, arguments)()
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\my1e5\Projects\my1e5\myproject\.venv\Lib\site-packages\commitizen\commands\bump.py", line 41, in __init__
raise NotAGitProjectError()
commitizen.exceptions.NotAGitProjectError: fatal: not a git repository (or any of the parent directories): .git
Looking specifically at the output of cmd.run
def is_git_project() -> bool:
c = cmd.run("git rev-parse --is-inside-work-tree")
print(c)
$ rye run cz --debug bump
Command(out='', err="'git' is not recognized as an internal or external command,\r\noperable program or batch file.\r\n", stdout=b'', stderr=b"'git' is not recognized as an internal or external command,\r\noperable program or batch file.\r\n", return_code=1)
But then even ls
doesn't work. Changing it to c = cmd.run("ls")
$ rye run cz --debug bump
Command(out='', err="'ls' is not recognized as an internal or external command,\r\noperable program or batch file.\r\n", stdout=b'', stderr=b"'ls' is not recognized as an internal or external command,\r\noperable program or batch file.\r\n", return_code=1)
However, for some reason, in cmd.py
if I change shell=False
. Then it works.
def run(cmd: str, env=None) -> Command:
if env is not None:
env = {**os.environ, **env}
process = subprocess.Popen(
cmd,
shell=False,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=subprocess.PIPE,
env=env,
)
$ rye run cz --debug bump
Tag 0.1.0 could not be found.
Possible causes:
- version in configuration is not the current version
- tag_format is missing, check them using 'git tag --list'
? Is this the first tag created? (Y/n)
Just as a reminder - in all my rye-managed projects running cz
directly (i.e. not using rye run
) gives the same error. But this can also be fixed using shell=False
. I have no issues running cz
directly in my other python projects not managed by rye.
Would you mind submitting a PR?
I think we can set shell=False
if the system is windows. I haven't had that issue on mac
Description
I'm using
rye
to manage my python project - it's similar topoetry
. Runningcz bump
throughrye
givesSteps to reproduce
Similar to
poetry
, we addcommitizen
as a dev dependency.Then
Current behavior
The way to run a script/executable you've added to your python project is using
rye run
Is this because
cz.exe
is stored in.venv/Scripts/cz.exe
?So it can't find the
.git
folder which is two levels above?Desired behavior
No fatal errors.
cz
is able to find the.git
repo.Screenshots
No response
Environment