Skip to content

wxGUI: Add the matplotlib hint as an exception note - #7688

Merged
wenzeslaus merged 2 commits into
OSGeo:mainfrom
wenzeslaus:wxgui-matplotlib-import-notes
Jul 14, 2026
Merged

wenzeslaus merged 2 commits into
OSGeo:mainfrom
wenzeslaus:wxgui-matplotlib-import-notes

Conversation

@wenzeslaus

@wenzeslaus wenzeslaus commented Jul 14, 2026 •

Copy link
Copy Markdown
Member

Now, the Scatterplot, Timeline, and Temporal Plot tools raise a new ImportError whose message is the hint, with the original error appended to it using .format(e).

Add the hint as a note to the original error instead. From the Python documentation of BaseException.add_note(): "Add the string note to the exception's notes which appear in the standard traceback after the exception string."

Starting a tool without matplotlib then gives a single exception with the actual error as its message and the hint after it, instead of a chained pair of exceptions:

ModuleNotFoundError: No module named 'matplotlib'
The Timeline Tool needs the "matplotlib" (python-matplotlib and on some systems also python-matplotlib-wx) package(s) to be installed.

Nothing else is affected, because the tools are started with a plain except ImportError in main_window and lmgr which shows its own message and uses neither the message nor the traceback of the error.

A note is shown only in a traceback, never in str(exception), so this is not applicable where the caller prints the message, for example r.in.wms with gs.fatal().

Exception notes need Python 3.11, which is now the minimum version (discussed in #4032). This touches the same lines as #4032, so whichever is merged second needs a trivial conflict resolution.

Commit message

The Scatterplot, Timeline, and Temporal Plot tools raised a new ImportError
with the hint as its message, so the message of the original error, which
says which module is actually missing, was replaced by the hint.

Add the hint as a note to the original error instead. From the Python
documentation of BaseException.add_note(): Add the string note to the
exception's notes which appear in the standard traceback after the exception
string. The traceback then shows both the missing module and the hint.

The consumer code (various places) shows always its own message, so the
not, not the original message is not used. These changes do not change that.

Exception notes need Python 3.11, which is now the minimum version.

The Scatterplot, Timeline, and Temporal Plot tools raised a new ImportError
with the hint as its message, so the message of the original error, which
says which module is actually missing, was replaced by the hint.

Add the hint as a note to the original error instead. From the Python
documentation of BaseException.add_note(): "Add the string note to the
exception's notes which appear in the standard traceback after the exception
string." The traceback then shows both the missing module and the hint.

Exception notes need Python 3.11, which is now the minimum version.
@github-actions github-actions Bot added GUI wxGUI related Python Related code is in Python labels Jul 14, 2026
@wenzeslaus
wenzeslaus enabled auto-merge (squash) July 14, 2026 07:12
@wenzeslaus
wenzeslaus merged commit f5cd4fa into OSGeo:main Jul 14, 2026
26 checks passed
@wenzeslaus
wenzeslaus deleted the wxgui-matplotlib-import-notes branch July 14, 2026 14:29
@github-actions github-actions Bot added this to the 8.6.0 milestone Jul 14, 2026
echoix pushed a commit to wenzeslaus/grass that referenced this pull request Jul 14, 2026
The Scatterplot, Timeline, and Temporal Plot tools raised a new ImportError
with the hint as its message, so the message of the original error, which
says which module is actually missing, was replaced by the hint.

Add the hint as a note to the original error instead. From the Python
documentation of BaseException.add_note(): Add the string note to the
exception's notes which appear in the standard traceback after the exception
string. The traceback then shows both the missing module and the hint.

The consumer code (various places) shows always its own message, so the
not, not the original message is not used. These changes do not change that.  

Exception notes need Python 3.11, which is now the minimum version.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

GUI wxGUI related Python Related code is in Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants