Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

__init__: don't run refresh on import#2073

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
lheckemann wants to merge1 commit intogitpython-developers:main
base:main
Choose a base branch
Loading
fromlheckemann:push-stqopxmnmomy

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 performrefresh at the module top level.


This istechnically 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

@ByronByron 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 isImportError, and that the change not only removes that but also therefresh() 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.

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

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.

@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.

@Byron
Copy link
Member

It looks like CI is failing, and I don't see my question about the lack ofrefresh() or lazy-refresh addressed.

@lheckemann
Copy link
Author

Sorry, I thought this was clear from the diff: I introduced arefresh call in_call_process, conditional on the executable not yet being known, so that it gets called on the first attempt to actually invoke git.

Will take a look at the tests.

Consumers of gitpython may not need to use it in all use cases, and maywant to be able to run (without using gitpython) in environments wheregit is not available on PATH. While this can be worked around by settingthe GIT_PYTHON_REFRESH environment variable, adding special handling forgitpython means that it can't be imported just like everything else inan import block at the top of the module, and environment variables havepotentially undesired propagation behaviour.Previously, it was also nontrivial to distinguish gitpython failing toimport because of missing git or because e.g. gitpython isn't installedat all, because the exception that's raised is an ImportError withoutfurther 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 commandto work without, e.g. ref listing.
@Byron
Copy link
Member

Byron commentedSep 25, 2025
edited
Loading

Thanks for clarifying.
And now, I really have to drag@EliahKagan into this as he has much more experience by now with Python and the Git command.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@ByronByronByron left review comments

@EliahKaganEliahKaganAwaiting requested review from EliahKagan

Assignees
No one assigned
Labels
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@lheckemann@Byron

[8]ページ先頭

©2009-2025 Movatter.jp