-
-
Notifications
You must be signed in to change notification settings - Fork 473
Description
What is the problem or limitation you are having?
The code contains a lot of messages like this:
briefcase/src/briefcase/integrations/java.py
Lines 117 to 136 in 9bbd110
| else: | |
| install_message = f""" | |
| ************************************************************************* | |
| ** WARNING: JAVA_HOME does not point to a Java {cls.JDK_MAJOR_VER} JDK ** | |
| ************************************************************************* | |
| Android requires a Java {cls.JDK_MAJOR_VER} JDK, but the location pointed to by the | |
| JAVA_HOME environment variable: | |
| {java_home} | |
| isn't a Java {cls.JDK_MAJOR_VER} JDK (it appears to be Java {version_str}). | |
| Briefcase will proceed using its own JDK instance. | |
| ************************************************************************* | |
| """ | |
| except OSError: | |
| install_message = f""" |
This has several problems:
-
It completely messes up the indentation of the surrounding code.
-
When the message contains placeholders, it's difficult to get the wrapping and alignment correct for all possible values. For example, the asterisk box alignment here is incorrect when the Java version contains 2 characters:
************************************************************************* ** WARNING: JAVA_HOME does not point to a Java 17 JDK ** *************************************************************************
Describe the solution you'd like
Add a helper function that takes a message, and optionally a title, and formats it automatically with textwrap or something similar. The places that call the function can then use normal indentation with no soft line breaks, like this:
briefcase/src/briefcase/exceptions.py
Lines 135 to 142 in 9bbd110
| super().__init__( | |
| msg=( | |
| f"Briefcase cannot install {tool} on this machine." | |
| f"\n\n" | |
| f"Install {tool} manually and specify the installation " | |
| f"directory in the {env_var} environment variable." | |
| ) | |
| ) |
At first, there's no need to use this function in every possible place. It's enough to prove that it works by using it in a few places whose messages are covered by the unit tests.
Describe alternatives you've considered
Maybe Rich has something like this already?