+def adjust_include_path (path, outpath):
+ """Rewrite an include path relative to the dir where lilypond is launched.
+ Always use forward slashes since this is what lilypond expects."""
+ path = os.path.expanduser (path)
+ path = os.path.expandvars (path)
+ path = os.path.normpath (path)
+ if os.path.isabs (outpath):
+ return os.path.abspath (path).replace (os.path.sep, '/')
+ if os.path.isabs (path):
+ return path.replace (os.path.sep, '/')
+ return os.path.join (inverse_relpath (original_dir, outpath), path).replace (os.path.sep, '/')
+
+def inverse_relpath (path, relpath):
+ """Given two paths, the second relative to the first,
+ return the first path relative to the second.
+ Always use forward slashes since this is what lilypond expects."""
+ if os.path.isabs (relpath):
+ return os.path.abspath (path).replace (os.path.sep, '/')
+ relparts = ['']
+ parts = os.path.normpath (path).split (os.path.sep)
+ for part in os.path.normpath (relpath).split (os.path.sep):
+ if part == '..':
+ relparts.append (parts[-1])
+ parts.pop ()
+ else:
+ relparts.append ('..')
+ parts.append (part)
+ return '/'.join (relparts[::-1])
+