]> 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>
Fri, 26 Jan 2007 01:27:13 +0000 (02:27 +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 e28577fb1c88b9eaed15d91b6b3309c5f42fc616..9ee2804ddd574a9c91584cab6e41e2f7409256a5 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 549e82b69c2570579616592b74ae0f5c95d96277..a29773cb2a7b973ea8fb2aabd127213683462007 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 0e85317a2ee9791c25c6d238422f9c54cacab9c8..06a1433ed4577e0545f4c16187f155b7b60d512d 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 73d821be3a9dbaee0634d6ba687e47516e1a1cd6..42ace40b04741f7dd7ca9a10abb61bbba8bf73aa 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 4a0d956211a3b185a318ecd8c3f5626d4b51ad98..b561e87ab28e45010ea77a85e21a35be2677b0a8 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 cab011a9d91793d79cd1f35c973d29a7c5428f07..5ae7fff8c604ddf6f5e4762f813ad991a955bec5 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')
 
+