Reviewers: ,
Message:
Remove the use of absolute paths in lilypond-book.
Please review.
Description:
Fix .dep file from lilypond-book when include paths are involved.
Don't rewrite include paths; use relative paths whenever possible.
Similar to http://code.google.com/p/lilypond/issues/detail?id=1852#c1
Please review this at http://codereview.appspot.com/5486064/
Affected files:
M python/book_base.py
M python/book_snippets.py
M scripts/lilypond-book.py
Index: python/book_base.py
diff --git a/python/book_base.py b/python/book_base.py
index
b43b9e00d4b4477b5ea2fe0f05eea0be9e3ae8f5..1d0d9eca990407f3671a03c54af143515eef295e
100644
--- a/python/book_base.py
+++ b/python/book_base.py
@@ -14,9 +14,11 @@ error = ly.error
# Helper functions
########################################################################
-def find_file (name, include_path, raise_error=True):
- for i in include_path:
+def find_file (name, include_path, working_dir=None, raise_error=True):
+ current_path = working_dir or os.getcwd();
+ for i in [current_path] + include_path:
full = os.path.join (i, name)
+ full = os.path.normpath (os.path.join (current_path, full))
if os.path.exists (full):
return full
@@ -149,7 +151,8 @@ class BookOutputFormat:
return []
def input_fullname (self, input_filename):
- return find_file (input_filename, self.global_options.include_path)
+ return find_file (input_filename, self.global_options.include_path,
+ self.global_options.original_dir)
def adjust_snippet_command (self, cmd):
return cmd
Index: python/book_snippets.py
diff --git a/python/book_snippets.py b/python/book_snippets.py
index
e3fc2eff950ff6034ca41296ea7488ca192f0942..b12091596745de343c198fd67472912bdbf9fcc9
100644
--- a/python/book_snippets.py
+++ b/python/book_snippets.py
@@ -804,7 +804,8 @@ class LilypondFileSnippet (LilypondSnippet):
LilypondSnippet.__init__ (self, type, match, formatter,
line_number, global_options)
self.filename = self.substring ('filename')
self.ext = os.path.splitext (os.path.basename (self.filename))[1]
- self.contents = file (BookBase.find_file (self.filename,
global_options.include_path)).read ()
+ self.contents = file (BookBase.find_file (self.filename,
+ global_options.include_path,
global_options.original_dir)).read ()
def get_snippet_code (self):
return self.contents;
Index: scripts/lilypond-book.py
diff --git a/scripts/lilypond-book.py b/scripts/lilypond-book.py
index
9e5777284982a924aac8f74db7e76b22cb0e81f7..8847419fe0dc46e698e06873f7494e4bf0bae6f2
100644
--- a/scripts/lilypond-book.py
+++ b/scripts/lilypond-book.py
@@ -143,7 +143,7 @@ def get_option_parser ():
p.add_option ("-I", '--include', help=_ ("add DIR to include path"),
metavar=_ ("DIR"),
action='append', dest='include_path',
- default=[os.path.abspath (os.getcwd ())])
+ default=[])
p.add_option ('--info-images-dir',
help=_ ("format Texinfo output so that Info will "
@@ -616,8 +616,7 @@ def do_options ():
(global_options, args) = opt_parser.parse_args ()
global_options.information = {'program_version':
ly.program_version, 'program_name': ly.program_name }
-
- global_options.include_path = map (os.path.abspath,
global_options.include_path)
+ global_options.original_dir = original_dir
# Load the python packages (containing e.g. custom formatter classes)
# passed on the command line
@@ -667,7 +666,7 @@ def main ():
if global_options.lily_output_dir:
# This must be first, so lilypond prefers to read .ly
# files in the other lybookdb dir.
- includes = [os.path.abspath(global_options.lily_output_dir)] +
includes
+ includes = [global_options.lily_output_dir] + includes
global_options.process_cmd += ' '.join ([' -I %s' % ly.mkarg (p)
for p in includes])
@@ -713,7 +712,7 @@ def main ():
base_file_name +
global_options.formatter.default_extension)
os.chdir (original_dir)
- file (dep_file, 'w').write ('%s: %s'
+ file (dep_file, 'w').write ('%s: %s\n'
% (final_output_file, ' '.join (inputs)))
if __name__ == '__main__':
_______________________________________________
lilypond-devel mailing list
lilypond-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-devel