Skip to content

Conversation

lheckemann
Copy link

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.


This is technically observable behaviour that could break assumptions made downstream, so I've added a changelog entry with a major version bump. I'm not sure this is "breaking enough" that you would consider it needing a major bump.

Feedback both on the breakingness and on the change in principle very welcome!

Copy link
Member

@Byron Byron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing!

My intuition here is that the problem is ImportError, and that the change not only removes that but also the refresh() call which I'd think is important.

Besides that, I'd definitely be unwilling to to casually bump the major version for this alone, if it is a major bump. It could also be a fix, but I'd be very afraid it's breaking downstream in too many ways.

However, I can see that the issue to solve here is that GitPython might be imported somewhere in the dependency chain on a system that has no Git, without ever running into other issues as no Git specific features are used. Thus it's not needed to fail on import, but rather, it should fail on first use.

This is the direction I'd want to take this - can it fail later? After all, there is plenty of functionality that might work even without Git.

@EliahKagan might have a better feeling about what could be done to improve the underlying problem and avoid a breaking change.

@Byron Byron marked this pull request as draft September 24, 2025 03:11
@Byron
Copy link
Member

Byron commented Sep 24, 2025

Setting this back to draft as I'd not want it merged just yet until it's clear if there are no better solutions to the problem.

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,
instead performing it lazily when an invocation of git is attempted.
This also allows some functionality that doesn't rely on the git command
to work without, e.g. ref listing.
@lheckemann
Copy link
Author

How does the behaviour of this variant look to you? The GitCommandNotFound exception is a bit awkward as is, but that should be easy enough to clean up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants