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

NotADirectoryError: [WinError 267] The directory name is invalid when installing via pip install -e . using msys2 git. #197

Open
cr1901 opened this issue Sep 5, 2023 · 2 comments

Comments

@cr1901
Copy link
Contributor

cr1901 commented Sep 5, 2023

When installing a PDM project via pip install -e ., I get the following cryptic error:

William@DESKTOP-3H1DSBV MINGW64 ~/Projects/python/pdm-backend
$ pip install -e .
Obtaining file:///C://msys64/home/William/Projects/python/pdm-backend
  Checking if build backend supports build_editable ... done
  Getting requirements to build editable ... done
  Installing backend dependencies ... done
  Preparing editable metadata (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Preparing editable metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [39 lines of output]
      Traceback (most recent call last):
        File "C:/msys64/mingw64/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <mod

ule>
          main()
        File "C:/msys64/mingw64/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:/msys64/mingw64/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 181, in prep

are_metadata_for_build_editable
          return hook(metadata_directory, config_settings)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:/msys64/home/William/Projects/python/pdm-backend/src/pdm/backend/__init__.py", line 89, in prepare_metadata_for_build_e

ditable
          return builder.prepare_metadata(metadata_directory).name
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:/msys64/home/William/Projects/python/pdm-backend/src/pdm/backend/wheel.py", line 104, in prepare_metadata
          self.initialize(context)
        File "C:/msys64/home/William/Projects/python/pdm-backend/src/pdm/backend/base.py", line 180, in initialize
          self.call_hook("pdm_build_initialize", context)
        File "C:/msys64/home/William/Projects/python/pdm-backend/src/pdm/backend/base.py", line 138, in call_hook
          getattr(hook, hook_name)(context, *args, **kwargs)
        File "C:/msys64/home/William/Projects/python/pdm-backend/src/pdm/backend/hooks/version/__init__.py", line 69, in pdm_build_init

ialize
          metadata["version"] = getattr(self, f"resolve_version_from_{source}")(
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:/msys64/home/William/Projects/python/pdm-backend/src/pdm/backend/hooks/version/__init__.py", line 98, in resolve_versio

n_from_scm
          version = get_version_from_scm(context.root, tag_regex=tag_regex)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:/msys64/home/William/Projects/python/pdm-backend/src/pdm/backend/hooks/version/scm.py", line 333, in get_version_from_s

cm
          version = func(root, config)  # type: ignore
                    ^^^^^^^^^^^^^^^^^^
        File "C:/msys64/home/William/Projects/python/pdm-backend/src/pdm/backend/hooks/version/scm.py", line 187, in git_parse_version
          ret, output, err = _subprocess_call(describe_cmd, repo)
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:/msys64/home/William/Projects/python/pdm-backend/src/pdm/backend/hooks/version/scm.py", line 52, in _subprocess_call
          proc = subprocess.Popen(
                 ^^^^^^^^^^^^^^^^^
        File "C:/msys64/mingw64/lib/python3.11/subprocess.py", line 1026, in __init__
          self._execute_child(args, executable, preexec_fn, close_fds,
        File "C:/msys64/mingw64/lib/python3.11/subprocess.py", line 1538, in _execute_child
          hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      NotADirectoryError: [WinError 267] The directory name is invalid
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

William@DESKTOP-3H1DSBV MINGW64 ~/Projects/python/pdm-backend
$

From experience, I know what is causing this error; the msys2 git binary does not understand Windows paths:

William@DESKTOP-3H1DSBV MINGW64 ~/Projects/python/pdm-backend
$ git rev-parse --show-toplevel
/home/William/Projects/python/pdm-backend

scm.py is running git rev-parse --show-toplevel to get the path to the top-level. scm.py assumes that the returned path is formatted with a drive letter, which it isn't. It then passes this path on to the cwd of the following describe invocation, and dies with the above error.

Historically, I've fixed this with something like a call to the cygpath binary:

out = subprocess.check_output(["cygpath", "-w", out], cwd=(path or "."), universal_newlines=True, stderr=devnull,)

I'm not sure whether this would be accepted or not, since I'm unsure if other calls to binaries will need to be fixed as well; you can justifiably say I'm papering over the real problem. Unfortunately, cygpath is an 1100 line C file that has many edge cases, so re-implementing it as a Python library would not be viable for me right now. However, I think it's worth opening the issue anyway b/c I know what's wrong, how to fix it, and maybe some workarounds will come up :D!

@cr1901 cr1901 changed the title NotADirectoryError: [WinError 267] The directory name is invalid when installing via pip install -e . using msys2 git. NotADirectoryError: [WinError 267] The directory name is invalid when installing via pip install -e . using msys2 git`. Sep 5, 2023
@cr1901 cr1901 changed the title NotADirectoryError: [WinError 267] The directory name is invalid when installing via pip install -e . using msys2 git`. NotADirectoryError: [WinError 267] The directory name is invalid when installing via pip install -e . using msys2 git. Sep 5, 2023
@cr1901
Copy link
Contributor Author

cr1901 commented Sep 5, 2023

Actually, I believe the this patch will also fix the issue here (use --show-prefix instead of --show-toplevel and reconstruct an absolute path from within Python).

EDIT: Workaround for now: PDM_BUILD_SCM_VERSION=2.1.7.dev pip install -e .

@cr1901
Copy link
Contributor Author

cr1901 commented Sep 12, 2023

Alternate (better) workaround: Install an alternate git, like the Portable Windows download, decompress, and then prepend the binary directory to your PATH so that PDM finds and uses the alternate git.

I don't know how this info would be forwarded to pdm-backend, but... would a patch be accepted to override the git binary with a pdm config option?

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

No branches or pull requests

1 participant