]> git.donarmstrong.com Git - lilypond.git/commitdiff
use sed-atfiles to put relocation handling in python scripts.
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Thu, 25 Jan 2007 14:37:30 +0000 (15:37 +0100)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Thu, 25 Jan 2007 14:37:30 +0000 (15:37 +0100)
python/relocate-preamble.py.in [new file with mode: 0644]
scripts/GNUmakefile
scripts/abc2ly.py
scripts/convert-ly.py
scripts/etf2ly.py
scripts/lilypond-book.py
scripts/midi2ly.py
scripts/musicxml2ly.py
stepmake/stepmake/python-module-rules.make
stepmake/stepmake/script-rules.make
stepmake/stepmake/substitute-vars.make

diff --git a/python/relocate-preamble.py.in b/python/relocate-preamble.py.in
new file mode 100644 (file)
index 0000000..23db6d8
--- /dev/null
@@ -0,0 +1,19 @@
+This generic code used for all python scripts.
+
+The quotes are to ensure that the source .py file can still be
+run as a python script, but does not include any sys.path handling.
+Otherwise, the lilypond-book calls inside the build
+might modify installed .pyc files.
+
+"""
+
+for d in ['@lilypond_datadir@',
+         '@lilypond_libdir@']:
+    sys.path.insert (0, os.path.join (d, 'python'))
+
+# dynamic relocation, for GUB binaries.
+bindir = os.path.abspath (os.path.split (sys.argv[0])[0])
+for p in ['share', 'lib']:
+    datadir = os.path.abspath (bindir + '/../%s/lilypond/current/python/' % p)
+    sys.path.insert (0, datadir)
+"""
index ce7b006479d511ef940cc11aede77faa3465c27b..2a683a89751f9ba6ab786c752098519d7161e0b6 100644 (file)
@@ -6,6 +6,9 @@ STEPMAKE_TEMPLATES=script help2man po
 LOCALSTEPMAKE_TEMPLATES = lilypond
 HELP2MAN_EXECS = $(SEXECUTABLES)
 
+AT_FILES=relocate-preamble
+at-ext=.py.in
+at-dir=$(depth)/python
+
 include $(depth)/make/stepmake.make
 include $(stepdir)/executable-targets.make
-
index 83dc1f79ae4d135b12b6c8b1d19a5be0a72d4ecd..570846c4ac40bbda4ebee33a5874be19eb82e974 100644 (file)
@@ -78,16 +78,9 @@ import os
 program_name = sys.argv[0]
 
 
-for d in ['@lilypond_datadir@',
-          '@lilypond_libdir@']:
-    sys.path.insert (0, os.path.join (d, 'python'))
-
-# dynamic relocation, for GUB binaries.
-bindir = os.path.abspath (os.path.split (sys.argv[0])[0])
-for p in ['share', 'lib']:
-    datadir = os.path.abspath (bindir + '/../%s/lilypond/current/python/' % p)
-    sys.path.insert (0, datadir)
-
+"""
+@relocate-preamble@
+"""
 
 import lilylib as ly
 global _;_=ly._
index 474144c3ce081d16b3f45f67e1a0aa0a52d53ff3..cf67f9f2400d0fbdb42ecf2d08299c5f283648fd 100644 (file)
@@ -15,18 +15,9 @@ import sys
 import string
 import re
 
-
-datadir = '@local_lilypond_datadir@'
-if not os.path.isdir (datadir):
-    datadir = '@lilypond_datadir@'
-
-sys.path.insert (0, os.path.join (datadir, 'python'))
-
-# dynamic relocation, for GUB binaries.
-bindir = os.path.abspath (os.path.split (sys.argv[0])[0])
-for p in ['share', 'lib']:
-    datadir = os.path.abspath (bindir + '/../%s/lilypond/current/python/' % p)
-    sys.path.insert (0, datadir)
+"""
+@relocate-preamble@
+"""
 
 import lilylib as ly
 global _;_=ly._
index 126288f6766723928689a2bd15b14dca78ca467f..f87778d9d4fc61c93fca965328ee60cdf3b5fd45 100644 (file)
@@ -39,25 +39,9 @@ version = '@TOPLEVEL_VERSION@'
 if version == '@' + 'TOPLEVEL_VERSION' + '@':
     version = '(unknown version)'           # uGUHGUHGHGUGH
 
-
-################################################################
-# Users of python modules should include this snippet.
-#
-
-
-
-
-for d in ['@lilypond_datadir@',
-          '@lilypond_libdir@']:
-    sys.path.insert (0, os.path.join (d, 'python'))
-
-
-# dynamic relocation, for GUB binaries.
-bindir = os.path.abspath (os.path.split (sys.argv[0])[0])
-for p in ['share', 'lib']:
-    datadir = os.path.abspath (bindir + '/../%s/lilypond/current/python/' % p)
-    sys.path.insert (0, datadir)
-
+"""
+@relocate-preamble@
+"""
 
 ################################################################
 
index dd495fc7509e213d10fbe49c3153aefc5e4e9489..09eefff340c2322be5dd50b53770ad8661d2d5cb 100644 (file)
@@ -37,23 +37,9 @@ import sys
 import re
 import md5
 
-################
-# RELOCATION
-################
-
-
-for d in ['@lilypond_datadir@',
-          '@lilypond_libdir@']:
-    sys.path.insert (0, os.path.join (d, 'python'))
-
-# dynamic relocation, for GUB binaries.
-bindir = os.path.abspath (os.path.split (sys.argv[0])[0])
-
-os.environ['PATH'] = bindir + os.pathsep + os.environ['PATH']
-for p in ['share', 'lib']:
-    datadir = os.path.abspath (bindir + '/../%s/lilypond/current/python/' % p)
-    sys.path.insert (0, datadir)
-
+"""
+@relocate-preamble@
+"""
 
 import lilylib as ly
 import fontextract
index f1db678cfb3990a50cda7e70925bcdb65e9d1fcb..35b10f39874a9dd3f5d561c07d92928d9b02e87d 100644 (file)
@@ -25,26 +25,15 @@ import os
 import string
 import sys
 
-################################################################
-# Users of python modules should include this snippet.
-#
-
-for d in ['@lilypond_datadir@',
-          '@lilypond_libdir@']:
-    sys.path.insert (0, os.path.join (d, 'python'))
-
-# dynamic relocation, for GUB binaries.
-bindir = os.path.abspath (os.path.split (sys.argv[0])[0])
-for p in ['share', 'lib']:
-    datadir = os.path.abspath (bindir + '/../%s/lilypond/current/python/' % p)
-    sys.path.insert (0, datadir)
-
+"""
+@relocate-preamble@
+"""
 
 import midi
 import lilylib as ly
 
 ################################################################
-################ CONSTANTS
+## CONSTANTS
 
 
 output_name = ''
index 665cc1d02fcab5623e45e14784d77f44c4fad17b..7a8e8c407165cc310fe7f54aaa3065b92537b02b 100644 (file)
@@ -7,20 +7,9 @@ import os
 import string
 from gettext import gettext as _
 
-
-
-for d in ['@lilypond_datadir@',
-          '@lilypond_libdir@']:
-    sys.path.insert (0, os.path.join (d, 'python'))
-
-# dynamic relocation, for GUB binaries.
-bindir = os.path.abspath (os.path.split (sys.argv[0])[0])
-for p in ['share', 'lib']:
-    datadir = os.path.abspath (bindir + '/../%s/lilypond/current/python/' % p)
-    sys.path.insert (0, datadir)
-
-
-
+"""
+@relocate-preamble@
+"""
 
 import lilylib as ly
 
index 511bd87afd9e171118b73764c8ffc0c23228b090..cb3ef487d8984f4ca7df3c90c0394828d5b865db 100644 (file)
@@ -9,5 +9,6 @@ $(outdir)/%.pyo: $(outdir)/%.py
        $(PYTHON) -O -c 'import py_compile; py_compile.compile ("$<")'
 
 $(outdir)/%.py: %.py $(config_make)
-       cat $< | sed $(sed-atvariables) > $@
+       cat $< | sed $(sed-atfiles) $(sed-atvariables) > $@
        chmod 755 $@
+
index 02e99909ac114480cb848fbf7628c9e13ea33eb0..bf6589e15c3c1796d85f4141b858ee6867f7e0a6 100644 (file)
@@ -1,25 +1,25 @@
 
 $(outdir)/%: %.pl $(config_make)  $(depth)/VERSION
-       cat $< | sed $(sed-atvariables) > $@
+       cat $< | sed $(sed-atfiles) $(sed-atvariables) > $@
        chmod 755 $@
 
 $(outdir)/%: %.bash $(config_make) $(depth)/VERSION
-       cat $< | sed $(sed-atvariables) > $@
+       cat $< | sed $(sed-atfiles) $(sed-atvariables) > $@
        chmod 755 $@
 
 $(outdir)/%: %.scm $(config_make) $(depth)/VERSION
-       cat $< | sed $(sed-atvariables) > $@
+       cat $< | sed $(sed-atfiles) $(sed-atvariables) > $@
        chmod 755 $@
 
 $(outdir)/%: %.expect $(config_make) $(depth)/VERSION
-       cat $< | sed $(sed-atvariables) > $@
+       cat $< | sed $(sed-atfiles) $(sed-atvariables) > $@
        chmod 755 $@
 
 $(outdir)/%: %.sh $(config_make) $(depth)/VERSION
-       cat $< | sed $(sed-atvariables) > $@
+       cat $< | sed $(sed-atfiles)$(sed-atvariables) > $@
        chmod 755 $@
 
 $(outdir)/%: %.py $(config_make) $(depth)/VERSION
-       cat $< | sed $(sed-atvariables) > $@
+       cat $< | sed $(sed-atfiles) $(sed-atvariables) > $@
        chmod 755 $@
 
index eb45a465fc9b3ea1fe52ab34dc4599d61bfb4bf8..8d7fd6295bd8264c2de8854a43355beda0c29c56 100644 (file)
@@ -10,9 +10,10 @@ DATE = $(date)
 # for all FILE in AT_FILES:
 # substitute occurrences of @FILE@ with contents $(at-dir)BLA$(at-ext)
 sed-atfiles = -e '\#' $(foreach i, $(AT_FILES), \
-  -e '/@$i@/r $(at-dir)$i$(at-ext)' -e 's%@$i@%%g')
+  -e '/@$i@/r $(at-dir)/$i$(at-ext)' -e 's%@$i@%%g')
 
 # for all VAR in ATVARIABLES
 # substitute occurrences of @VAR@ with $(VAR)
 sed-atvariables = -e '\#' $(foreach i, $(ATVARIABLES), -e 's!@$i@!$($i)!g')
 
+