From 9dafb20273dda7e62b0b8f03651bb5204fc7360f Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Fri, 8 Oct 2021 08:10:55 +0200 Subject: [PATCH 1/2] Fix TypeError on MacOS when lilypond was not found This fixes a runtime error on MacOS when a user tries to build a preview and the Lilypond installation was not found. Traceback (most recent call last): [...] File "/Applications/Frescobaldi.app/Contents/Resources/lib/python3.9/frescobaldi_app/signals.py", line 308, in call File "/Applications/Frescobaldi.app/Contents/Resources/lib/python3.9/frescobaldi_app/cachedproperty.py", line 264, in checkstart File "/Applications/Frescobaldi.app/Contents/Resources/lib/python3.9/frescobaldi_app/cachedproperty.py", line 276, in run File "/Applications/Frescobaldi.app/Contents/Resources/lib/python3.9/frescobaldi_app/lilypondinfo.py", line 306, in frommacports TypeError: unsupported operand type(s) for +: 'bool' and 'str' Signed-off-by: Stefan Weil --- frescobaldi_app/lilypondinfo.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frescobaldi_app/lilypondinfo.py b/frescobaldi_app/lilypondinfo.py index 931c9bb56..868715348 100644 --- a/frescobaldi_app/lilypondinfo.py +++ b/frescobaldi_app/lilypondinfo.py @@ -301,7 +301,8 @@ def done(): @CachedProperty.cachedproperty(depends=(abscommand, bindir)) def frommacports(self): """Return True if this LilyPond is provided by MacPorts.""" - if sys.platform.startswith('darwin'): + bindir = self.bindir() + if sys.platform.startswith('darwin') and bindir: import subprocess portbin = os.path.abspath(self.bindir() + '/port') if os.path.isfile(portbin) and os.access(portbin, os.X_OK): From 0a195936b3f1be7c0e41ce9fdd7f016e6e1c7bbd Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Fri, 8 Oct 2021 08:13:31 +0200 Subject: [PATCH 2/2] MacOS: Set PATH in app bundle for Homebrew installations of lilypond Signed-off-by: Stefan Weil --- frescobaldi_app/job/lilypond.py | 9 --------- frescobaldi_app/lilypondinfo.py | 17 ++++++++++++++++- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/frescobaldi_app/job/lilypond.py b/frescobaldi_app/job/lilypond.py index 9acc8cdde..fe4252195 100644 --- a/frescobaldi_app/job/lilypond.py +++ b/frescobaldi_app/job/lilypond.py @@ -167,15 +167,6 @@ def configure_command(self): cmd.extend(self.backend_args()) self.set_input_file() - # By default, the PATH environment variable for app bundles is empty. - # Setting it in __init__ is too early, since lilypond_info can be - # changed in the custom engraving dialog; configure_command is called - # just before starting the process. - if sys.platform.startswith('darwin'): - import macosx - if macosx.inside_app_bundle() and self.lilypond_info.frommacports(): - self.environment['PATH'] = self.lilypond_info.bindir() - def d_option(self, key): return self._d_options.get(key, None) diff --git a/frescobaldi_app/lilypondinfo.py b/frescobaldi_app/lilypondinfo.py index 868715348..a0e9bbc41 100644 --- a/frescobaldi_app/lilypondinfo.py +++ b/frescobaldi_app/lilypondinfo.py @@ -38,6 +38,8 @@ import util import qutil +if sys.platform.startswith('darwin'): + import macosx _infos = None # this can hold a list of configured LilyPondInfo instances @@ -181,7 +183,21 @@ def abscommand(self): os.path.join('/Applications', 'LilyPond.app', 'Contents', 'Resources', 'bin'), os.path.join('/opt', 'local', 'bin'), os.path.join('/opt', 'lilypond', 'bin'), + # Default path for Homebrew on MacOS arm64. + '/opt/homebrew/bin', + # Default path for Homebrew on MacOS x86_64. + '/usr/local/bin', ] + if macosx.inside_app_bundle(): + # By default, the PATH environment variable for app bundles + # does not contain the path which is required for lilypond + # and other helper programs like gs. + # Add the lilypond path to PATH to find the helper programs + # for Homebrew, Macports and other local installations. + exe = util.findexe(self.command, path) + if exe: + bindir = os.path.dirname(exe) + os.environ['PATH'] = bindir + ':' + os.environ['PATH'] else: path = None return util.findexe(self.command, path) or False @@ -351,7 +367,6 @@ def toolcommand(self, original_command, use_ly_tool=True): toolpath += '.py' command = [self.python(), toolpath] elif sys.platform.startswith('darwin'): - import macosx command = macosx.best_python(self, original_command) if command is None: return None