From 1da076773d523f6cd0cd8f233e6f8ae73a693391 Mon Sep 17 00:00:00 2001 From: Oliverpool Date: Mon, 9 Nov 2015 07:30:11 +0100 Subject: [PATCH 1/4] Test for lilypond compiler before starting compilation --- patacrep/build.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/patacrep/build.py b/patacrep/build.py index a720b9b1..f3391744 100644 --- a/patacrep/build.py +++ b/patacrep/build.py @@ -123,6 +123,9 @@ class Songbook(object): renderer.render_tex(output, config) + def requires_lilypond(self): + return 'lilypond' in self.config.get('bookoptions', []) + def _log_pipe(pipe): """Log content from `pipe`.""" while 1: @@ -227,6 +230,20 @@ class SongbookBuilder(object): except Exception as error: raise errors.ExecutableNotFound(compiler) + # Test if lilypond compiler is accessible + lilypond_compiler = 'lilypond' + if self.songbook.requires_lilypond(): + try: + check_call( + [lilypond_compiler, "--version"], + stdin=PIPE, + stdout=PIPE, + stderr=PIPE, + universal_newlines=True, + ) + except Exception as error: + raise errors.ExecutableNotFound(lilypond_compiler) + # Perform compilation try: process = Popen( From 95d27724ea2522ae7a3ef6eed4df90e082af7882 Mon Sep 17 00:00:00 2001 From: Oliverpool Date: Mon, 9 Nov 2015 07:33:26 +0100 Subject: [PATCH 2/4] (pylint) Add docstring --- patacrep/build.py | 1 + 1 file changed, 1 insertion(+) diff --git a/patacrep/build.py b/patacrep/build.py index f3391744..83817d1c 100644 --- a/patacrep/build.py +++ b/patacrep/build.py @@ -124,6 +124,7 @@ class Songbook(object): renderer.render_tex(output, config) def requires_lilypond(self): + """Tell if lilypond is part of the bookoptions""" return 'lilypond' in self.config.get('bookoptions', []) def _log_pipe(pipe): From 61bc9a5731e9b459e8aaf3dbf1f446f13b6331a7 Mon Sep 17 00:00:00 2001 From: Oliverpool Date: Mon, 9 Nov 2015 07:41:18 +0100 Subject: [PATCH 3/4] move variable declaration --- patacrep/build.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patacrep/build.py b/patacrep/build.py index 83817d1c..baa335fb 100644 --- a/patacrep/build.py +++ b/patacrep/build.py @@ -232,8 +232,8 @@ class SongbookBuilder(object): raise errors.ExecutableNotFound(compiler) # Test if lilypond compiler is accessible - lilypond_compiler = 'lilypond' if self.songbook.requires_lilypond(): + lilypond_compiler = 'lilypond' try: check_call( [lilypond_compiler, "--version"], From 0ebf52a9c9ac68a4a4d4f4b1ed5a41d2e363eff3 Mon Sep 17 00:00:00 2001 From: Louis Date: Sat, 21 Nov 2015 02:12:50 +0100 Subject: [PATCH 4/4] More precise exception handling --- patacrep/build.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/patacrep/build.py b/patacrep/build.py index baa335fb..f61a5dae 100644 --- a/patacrep/build.py +++ b/patacrep/build.py @@ -228,7 +228,7 @@ class SongbookBuilder(object): stderr=PIPE, universal_newlines=True, ) - except Exception as error: + except FileNotFoundError as error: raise errors.ExecutableNotFound(compiler) # Test if lilypond compiler is accessible @@ -242,7 +242,7 @@ class SongbookBuilder(object): stderr=PIPE, universal_newlines=True, ) - except Exception as error: + except FileNotFoundError as error: raise errors.ExecutableNotFound(lilypond_compiler) # Perform compilation