-
-
Notifications
You must be signed in to change notification settings - Fork 362
mkhtml: Fix print warning/fatal message during compilation #2139
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
mkhtml: Fix print warning/fatal message during compilation #2139
Conversation
This still fails on the gs.warning(
_(
) part.
|
Following seem to work: try:
import grass.script as gs
except ImportError:
# During compilation GRASS GIS
_ = str
class gs:
def warning(message):
pass
def fatal(message):
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that no translation is needed during compilation _ = str
on import error is the shortest way of making it work as @nilason suggests.
The warning function can pass or print. I don't know what is more appropriate, but if it can be pass, then I wonder if it is just a verbose message rather than a warning.
The fatal function should be at least print as in the PR (just pass as in @nilason's snippet is really "ignore all errors"). However, since it is fatal, that usually means in GRASS GIS ending the process immediately. You can do exit or raise an exception like we do grass.script.core when the library is configured that way.
Also, the messages would be prefixed by "ERROR: " if that would be the library function, so it makes sense to me to keep that behavior.
See also grass.py where similar code is needed.
Print gives new error: #2137 (comment) Also why would a HTTPError need to break compilation (with no git)? |
Maybe I'm missing something, but if printing itself gives an error, than that the printing should be fixed. If there is a subsequent error, than it means the code does not deal with a perfectly valid state. Or, that there is fatal/exit used where only a warning or verbose message should be.
I don't think it should. Compilation should work offline and without Git. Hence my suggestion to consider making some of these verbose messages (i.e., not printed by default). |
Alternatively I created a new PR #2140 (which solves this problem more comprehensively), where I replaced getting Git commit from remote GitHub API server during compilation (for core modules) with getting Git commit from a locally created/updated "pgms_with_last_commit.json" file (with GitHub action), and which is part of source code. |
#2140 is hopeful, but potentially complex, I think 8.2+ material, so this PR would be to get a solution for 8.0.1. |
I'm not too familiar with this code, but I think this function call is inside an ongoing stream (building the html) therefore the print() doesn't work there. gs.warning is output later.
Let's not forget these gs.warning and gs.fatal are only within |
Just tested compiling with and without git with above suggested code #2139 (comment). Succeeded in both cases. |
Yes I agree these warnings messages should be verbose messages. Rather, I think we should disable the download of Git commit info from the remote GitHub API server for core modules for now in the case of non-git source code. As I mentioned, there will be a situation where some core module man pages will have git commit info and others will not. |
Would that be a problem for the user? |
It seems that you can't use GitHub API for free for this amount of requests, so will that ever work in practice? With the calls sometimes hitting the rate limit, the result is just random. |
def warning(message): | ||
pass | ||
|
||
def fatal(message): | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is confusing to me. Why this is not verbose message in the first place? This is meant primary for compilation anyway, no? When you don't want the things to print ERROR:...
and exit or print WARNING:...
, then don't call gs.warning and gs.fatal. When reading the other part of the code, I will not remember that in this file the fatal function is redefined to do nothing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My original intention was to display these warning / fatal messages during the addon installation via g.extension, (then the remote GitHub API server is called) and not to display these messages during compilation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
download_git_commit()
function is called:
- During GRASS GIS compilation, when Git repo doesn't exists
- Addon installation (via g.extension module)
This can be confusing for the user because instead of the last commit date, it will have a build date depending on hit this error, Anyway, I'm adding your suggestions, which I tested. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can all agree, a better and more sustainable solution is needed. #2140 is a reminder of that.
If the present solution of this PR will not lead to consequences in usage, I'd suggest to go with this and make release 8.0.1 .
Fixes #2137, #2138. Suggested by #2137 (comment).
Note:
Git repository build: core modules manuals have git commit info
Non Git repository build: some core modules manuals have git commit info and some haven't, due GitHub API server error
urllib.error.HTTPError: HTTP Error 403: rate limit exceeded