-
-
Notifications
You must be signed in to change notification settings - Fork 907
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
Git.refresh warns to stdout and does not log #1808
Comments
Thanks for bringing this up! To my mind, libraries have no business with the stdout/stderr of a program, which makes this usage (and those like it) as bug. If other programs rely on the output of a library, they rely on an unstable API without any guarantees. This is an opening for using the logging facility here instead. Maybe in relation to #1806, if the logging would be configured to show warnings by default as it is suggested to well-behaved users of the logging module, then this important message should still show up even if GitPython is only used in an ad-hoc fashion. I am sure this was also the reason it prints to stdout, it was such a common issue that it should be assured the users can see it even without any prior configuration to the logging module. |
I agree.
I think the change for that should just be to no longer prevent that from happening, by no longer registering any There is also the question of what logging level should be used for this message. It's described as a warning, currently, but if it really represents an error then it can be logged with the
I don't see why that would be, since writing to stderr has never required that logging be configured. It's true that doing so with print >> sys.stderr, "WARNING: %s" % err # Old way (Python 2).
print("WARNING: %s" % err, file=sys.stderr) # New way (Python 3, or either with a __future__ import). I don't know if that's sufficient to explain why it wasn't done, though. |
Yes, that's absolutely OK and I would appreciate that. If folks override the logger in their application, they know what they are doing. Those who use
I agree, and this would make it even more likely to actually show up even if the logging is configured at application level. Since this is configurable, maybe that means the message level should be adjusted depending on the GitPython configuration.
Apologies for the confusion. What I tried to say is that in order to avoid that the message might not show up as logging is disabled, it was emitted to stdout or stderr directly. Maybe it's just an oversight, the true reason might be lost in the tides of time. |
I agree. Common approaches when not doing anything special with logging are to not configure logging or to configure it with (The messages are formatted more nicely when logging is configured, including with
Do you just mean importing and using the I ask because one nit I plan to fix at the same time as some of this other logging-related stuff is to make
Some further considerations:
Ah, I see. The two of us were focusing on different things there. I was specifically worried about why it was going to standard output rather than standard error, in case that behavior had at some point been needed. Edit: Fixed a misspelling of |
Can you elaborate on this? (I've posted this as its own comment since it seems like the issue may be especially important, and I don't want you to feel pressured to respond to my various thoughts above, or to do so at the same time, if this is the priority.) |
I used this example as I know this imports
If anything in the
I agree that this configuration should keep working, and maybe I am wrong to assume that this can integrate nicely with logging severities.
I see, each message comes with a severity, and we would be talking about increasing the severity of this message in particular, which is hard-coded. Indeed, I wouldn't want this to get anymore complicated and don't think users should get one more way to configure this.
I hope this is explained above, and also think that once the messaging of |
You are correct and I was simply mistaken here. My mind was already so much on the issue of what modules if any in GitPython might be runnable as a script (relevant to 987dbf4), I didn't think to check my belief that the check for I'll try to reply to the rest soon, but I wanted to get this out since it addresses an inaccuracy in what I had said above. |
If no new values of I think on reflection that it's at least an
The reason I'm not sure how well they would work is that the current recognized options that can be set via One way to get around that is to add another environment variable. But then we have another environment variable, have to decide what to do when it is unset as well as whether or not and how to report when its values makes no sense, and complexity for the user may be increased if this information is all presented in a message.
Other than the above issue with how it would be specified, I don't think the level/severity needs to be hard-coded. The |
Maybe you have an idea or preference on how this issue can be resolved by using a logger to report the matter in the most suitable way. I'd love to go with that :). |
When working on #1813, I wrote dc62096, which I didn't include there because, as noted there, I think it should have tests, which should build on the test changes in #1812. Both #1812 and #1813 are merged (and they will be able to run on Cygwin, since #1814), so those tests can be written and proposed. So I am thinking I'll go with an approach like in dc62096 initially, but with tests, and possibly with Then if a release ends up happening between that and future changes to this feature, future changes might be constrained by the need to avoid breakage or confusion. But even then, it could still probably be built on further. Delays in implementing this have not been due to design questions here, but instead the CI problems discovered in #1813 and worked around in #1814. I may still not get to this immediately, mostly for reasons not related (not even indirectly) to GitPython, but in part because I agree with the idea that the cause and exact conditions of the problem worked around in #1814 should be further investigated. With all that said, I do have another idea for how the logging level could be specified. I don't know if it's really a good idea, and it's not part of my initial plan as described above.
The The case that could be confusing is:
|
Thanks for sharing - I am already looking forward to what might cause these hangs deeply under the hood of C-Python apparently. Event though I think this could work while being backward compatible, some UX issues notwithstanding, my question is if there could ever be user-side demand for this. Maybe the demand appears with awareness though, which can be provided of course as part of the printed messages. In any case, I am open to that for when the time comes. |
This adds tests of the initial refresh that is attempted automatically on import. All the refresh tests prior to this point test subsequent refreshes. Those tests are kept, and new ones are added that simulate the condition of not having yet done the initial refresh by setting Git.GIT_PYTHON_GIT_EXECUTABLE to None. Some current behavior these tests assert may change for gitpython-developers#1808.
This is instead of the current behavior writing the message to stdout. This commit does not change the behavior of the code under test, but it changes tests to assert the following: - "Bad git executable" messages are logged, at level CRITICAL. - "log" (and "l") is recognized as another synonym of "warn". - "silent" is recognized as a synonym of "quiet" (as "silence" is). Although it is ambiguous whether this should be logged at level ERROR or CRITICAL, because git.refresh is still expected to be usable and can be called manually, not having a working git is a condition in which GitPython, and any program that really relies on its functionality, should be expected not work. That is the general rationale for using CRIICAL here. There are also two specific reasons: - Existing messages GitPython logs as ERROR typically represent errors in individual operations on repositories, which could fail without indicating that GitPython's overall functionality is in an unusable state. Using the higher CRITICAL level for this situation makes sense for contrast. - Prior to gitpython-developers#1813, logging messsges emitted from GitPython modules, no matter the level, were suppressed when logging was not configured, but because this message was printed instead of being logged, it was still shown. Now that it is to be logged, there may be a benefit to have an easy way for someone to bring back a close approximation of the old behavior. Having this message be at a higher logging level makes that easier to do. (This is a less important reason, as that should rarely be done.) test_initial_refresh_from_bad_git_path_env_warn is the main changed test. All tests should pass again once code is changed for gitpython-developers#1808.
For gitpython-developers#1808. See ac50d8e for details on the changes.
Warning messages are most often written to standard error. Furthermore, warnings from GitPython, when they are displayed, are in most cases displayed that way unless the caller arranges otherwise, because they are displayed by calling loggers'
warning
methods or, forDeprecationWarning
s, by callingwarnings.warn
.However, the warning
Git.refresh
displays when running a test command likegit --version
(with the command being tested used forgit
) fails, andGIT_PYTHON_REFRESH
is set to1
,w
,warn
, orwarning
, is different. It is printed to standard output. It also does not use any logging facility, so attempts to capture it by configuring Python logging will not succeed.GitPython/git/cmd.py
Lines 453 to 454 in d28c20b
If there is a reason for this behavior, then I think it should be commented or otherwise stated. Otherwise, I am not sure what to do. It may still not be feasible to change, because programs that use GitPython may be relying on the warning being printed to standard output, or on it not being printed to standard error. But if he behavior is going to change in the next major version, then that could be commented and/or this issue could be kept open until then. If the reason is unknown and it is undecided whether the behavior should be changed in the next major release, then a comment could be added just saying that it prints to standard output for backward compatibility.
The text was updated successfully, but these errors were encountered: