Skip to content
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

Error when running poetry new in parent directory of "git.exe". #5420

Closed
3 tasks done
michiharu2017 opened this issue Apr 6, 2022 · 5 comments
Closed
3 tasks done
Labels
kind/bug Something isn't working as expected status/triage This issue needs to be triaged

Comments

@michiharu2017
Copy link

  • I am on the latest Poetry version.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).
  • OS version and name: Windows 10 Pro
  • Poetry version: 1.1.13
  • Link of a Gist with the contents of your pyproject.toml file: None (This is poetry new issue.)

Issue

When I run poetry new in the parent directory of the directory where Git is installed, I get the following error:

C:\Users\personal>poetry new poetry_demo

  RuntimeError

  Unable to find a valid git executable

  at AppData\Roaming\pypoetry\venv\lib\site-packages\poetry\core\vcs\git.py:189 in executable
      185│     else:
      186│         _executable = "git"
      187│
      188│     if _executable is None:
    → 189│         raise RuntimeError("Unable to find a valid git executable")
      190│
      191│     return _executable
      192│
      193│

The path to Git is as follows:

C:\Users\personal>where git
C:\Users\personal\AppData\Local\Programs\Git\cmd\git.exe

If it is not the parent directory of Git, no error will occur.

C:\Users\personal>mkdir tmp_dir
C:\Users\personal>cd tmp_dir
C:\Users\personal\tmp_dir>poetry new poetry-demo
Created package poetry_demo in poetry-demo

The code that causes is as follows
If ValueError is not raised (i.e., if the git path can be converted to a path relative to the current directory), the next process raises RuntimeError.

poetry/core/vcs/git.py

    if WINDOWS and PY36:
        # Finding git via where.exe
        where = "%WINDIR%\\System32\\where.exe"
        paths = decode(
            subprocess.check_output([where, "git"], shell=True, encoding="oem")
        ).split("\n")
        for path in paths:
            if not path:
                continue

            path = Path(path.strip())
            try:
                path.relative_to(Path.cwd())
            except ValueError:
                _executable = str(path)

                break
    else:
        _executable = "git"

    if _executable is None:
        raise RuntimeError("Unable to find a valid git executable")

I don't know the details of this function, but I think the error message should say that 'the poetry project cannot be created in the parent directory of "git.exe"'.

This is my first Issue, so I apologize if anything is incomplete.
I hope this helps.

@michiharu2017 michiharu2017 added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Apr 6, 2022
@Rafeqm
Copy link

Rafeqm commented Apr 16, 2022

Yea I get this error as well.

@clintonroy
Copy link
Contributor

There's work being done to git stuff with a library, without relying on an external git command: #5428

So I would just work around this.

@finswimmer
Copy link
Member

Closing this, because Poetry now uses dulwich for git interaction by default.

@LexSong
Copy link

LexSong commented Mar 12, 2023

I'm having the exact same issue with poetry 1.4.0 on Windows. The calling stack is the same as above. And I think dulwich didn't help solve this issue.

Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/bug Something isn't working as expected status/triage This issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

5 participants