Skip to content

Commit d3662f2

Browse files
committed
__init__: don't run refresh on import
Consumers of gitpython may not need to use it in all use cases, and may want to be able to run (without using gitpython) in environments where git is not available on PATH. While this can be worked around by setting the GIT_PYTHON_REFRESH environment variable, adding special handling for gitpython means that it can't be imported just like everything else in an import block at the top of the module, and environment variables have potentially undesired propagation behaviour. Previously, it was also nontrivial to distinguish gitpython failing to import because of missing git or because e.g. gitpython isn't installed at all, because the exception that's raised is an ImportError without further qualification (except in the error message). Thus, we now no longer perform `refresh` at the module top level.
1 parent 2d4c541 commit d3662f2

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

doc/source/changes.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22
Changelog
33
=========
44

5+
4.0.0
6+
=====
7+
8+
GitPython will no longer throw an ImportError when no git executable can
9+
be found at import time. Instead, errors are deferred until the first
10+
attempt at using it. Consumers with special handling for
11+
the old ImportError behaviour should instead call `git.refresh` and handle
12+
GitCommandNotFoundErrors themselves.
13+
14+
See the following for all changes.
15+
https://github.com/gitpython-developers/GitPython/releases/tag/4.0.0
16+
17+
518
3.1.45
619
======
720

git/__init__.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,4 @@ def refresh(path: Optional[PathLike] = None) -> None:
291291

292292
GIT_OK = True
293293

294-
295-
try:
296-
refresh()
297-
except Exception as _exc:
298-
raise ImportError("Failed to initialize: {0}".format(_exc)) from _exc
299-
300294
# } END initialize git executable path

0 commit comments

Comments
 (0)