Skip to content

ImportError on latest GitPython 3.1.16 #1238

Description

@wwwaldo

Hey all,

Our CI doesn't pin GitPython versions (always use latest) and some of our automated tests failed today with a mysterious GitPython ImportError. Here's the stack trace:

[2021-05-13T15:23:58.759Z] ERROR launching hyper random, stderr: sh: 0: getcwd() failed: No such file or directory

[2021-05-13T15:23:58.759Z] Traceback (most recent call last):

[2021-05-13T15:23:58.759Z]   File "/usr/local/lib/python3.7/site-packages/git/__init__.py", line 83, in <module>

[2021-05-13T15:23:58.759Z]     refresh()

[2021-05-13T15:23:58.759Z]   File "/usr/local/lib/python3.7/site-packages/git/__init__.py", line 73, in refresh

[2021-05-13T15:23:58.759Z]     if not Git.refresh(path=path):

[2021-05-13T15:23:58.759Z]   File "/usr/local/lib/python3.7/site-packages/git/cmd.py", line 215, in refresh

[2021-05-13T15:23:58.759Z]     cls().version()

[2021-05-13T15:23:58.759Z]   File "/usr/local/lib/python3.7/site-packages/git/cmd.py", line 542, in <lambda>

[2021-05-13T15:23:58.759Z]     return lambda *args, **kwargs: self._call_process(name, *args, **kwargs)

[2021-05-13T15:23:58.759Z]   File "/usr/local/lib/python3.7/site-packages/git/cmd.py", line 1005, in _call_process

[2021-05-13T15:23:58.759Z]     return self.execute(call, **exec_kwargs)

[2021-05-13T15:23:58.759Z]   File "/usr/local/lib/python3.7/site-packages/git/cmd.py", line 686, in execute

[2021-05-13T15:23:58.759Z]     cwd = self._working_dir or os.getcwd()

[2021-05-13T15:23:58.759Z] FileNotFoundError: [Errno 2] No such file or directory

[2021-05-13T15:23:58.759Z] 

[2021-05-13T15:23:58.759Z] The above exception was the direct cause of the following exception:

[2021-05-13T15:23:58.760Z] 

[2021-05-13T15:23:58.760Z] Traceback (most recent call last):

[2021-05-13T15:23:58.760Z]   File "/usr/local/bin/spell", line 7, in <module>

[2021-05-13T15:23:58.760Z]     from spell.cli.main import main

[2021-05-13T15:23:58.760Z]   File "/usr/src/spell/python/spell/cli/main.py", line 47, in <module>

[2021-05-13T15:23:58.760Z]     from spell.cli.commands.run import run

[2021-05-13T15:23:58.760Z]   File "/usr/src/spell/python/spell/cli/commands/run.py", line 11, in <module>

[2021-05-13T15:23:58.760Z]     from spell.cli.utils import (

[2021-05-13T15:23:58.760Z]   File "/usr/src/spell/python/spell/cli/utils/git_utils.py", line 8, in <module>

[2021-05-13T15:23:58.760Z]     import git

[2021-05-13T15:23:58.760Z]   File "/usr/local/lib/python3.7/site-packages/git/__init__.py", line 85, in <module>

[2021-05-13T15:23:58.760Z]     raise ImportError('Failed to initialize: {0}'.format(exc)) from exc

[2021-05-13T15:23:58.760Z] ImportError: Failed to initialize: [Errno 2] No such file or directory

I think this might be a regression in the new 3.1.16.

Many of our other tests also seem to import the gitpython library but they don't error. The only difference I can see between the failed and passed tests is that the failed tests run in a parallel thread executor, all passing tests run one at a time.

Activity

  1. Yobmod commented on May 13, 2021

    @Yobmod
    Contributor

    I think its due to a change in util.Expand_path(), as self._working_dir = expand_path(working_dir).

    But I don't know why it would only fail with parallel code.

    I've reverted the change (it added a None check as working_dir can be None, but logic must have been wrong somewhere) and added type:ignore to the resulting mypy errors for now to pass CI #1240

  2. Byron commented on May 13, 2021

    @Byron
    Member

    I have yanked the release and will see to these issues in a bit.

  3. added this to the v3.1.17 - Bugfixes milestone on May 14, 2021
  4. Byron commented on May 14, 2021

    @Byron
    Member

    @karenin-overseas It would be great if you could give the latest main a shot on your CI to see if the issue is indeed fixed. If so, I am happy to cut a new release. Thank you

  5. reopened this on May 14, 2021
  6. wwwaldo commented on May 14, 2021

    @wwwaldo
    Author

    @Byron, I'm able to verify that our CI does not error off main. Thanks

  7. Byron commented on May 14, 2021

    @Byron
    Member

    And here is the new release: https://pypi.org/project/GitPython/3.1.17/

  8. added a commit that references this issue on May 11, 2026
  9. added a commit that references this issue on May 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions