From: Han-Wen Nienhuys Date: Thu, 25 Jan 2007 14:37:30 +0000 (+0100) Subject: use sed-atfiles to put relocation handling in python scripts. X-Git-Tag: release/2.11.14-1~28 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=9a6392ad41c7cd1d811971b20b613129c65e10a6;p=lilypond.git use sed-atfiles to put relocation handling in python scripts. --- diff --git a/python/relocate-preamble.py.in b/python/relocate-preamble.py.in new file mode 100644 index 0000000000..23db6d86a6 --- /dev/null +++ b/python/relocate-preamble.py.in @@ -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) +""" diff --git a/scripts/GNUmakefile b/scripts/GNUmakefile index ce7b006479..2a683a8975 100644 --- a/scripts/GNUmakefile +++ b/scripts/GNUmakefile @@ -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 - diff --git a/scripts/abc2ly.py b/scripts/abc2ly.py index 83dc1f79ae..570846c4ac 100644 --- a/scripts/abc2ly.py +++ b/scripts/abc2ly.py @@ -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._ diff --git a/scripts/convert-ly.py b/scripts/convert-ly.py index 474144c3ce..cf67f9f240 100644 --- a/scripts/convert-ly.py +++ b/scripts/convert-ly.py @@ -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._ diff --git a/scripts/etf2ly.py b/scripts/etf2ly.py index 126288f676..f87778d9d4 100644 --- a/scripts/etf2ly.py +++ b/scripts/etf2ly.py @@ -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@ +""" ################################################################ diff --git a/scripts/lilypond-book.py b/scripts/lilypond-book.py index dd495fc750..09eefff340 100644 --- a/scripts/lilypond-book.py +++ b/scripts/lilypond-book.py @@ -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 diff --git a/scripts/midi2ly.py b/scripts/midi2ly.py index f1db678cfb..35b10f3987 100644 --- a/scripts/midi2ly.py +++ b/scripts/midi2ly.py @@ -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 = '' diff --git a/scripts/musicxml2ly.py b/scripts/musicxml2ly.py index 665cc1d02f..7a8e8c4071 100644 --- a/scripts/musicxml2ly.py +++ b/scripts/musicxml2ly.py @@ -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 diff --git a/stepmake/stepmake/python-module-rules.make b/stepmake/stepmake/python-module-rules.make index 511bd87afd..cb3ef487d8 100644 --- a/stepmake/stepmake/python-module-rules.make +++ b/stepmake/stepmake/python-module-rules.make @@ -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 $@ + diff --git a/stepmake/stepmake/script-rules.make b/stepmake/stepmake/script-rules.make index 02e99909ac..bf6589e15c 100644 --- a/stepmake/stepmake/script-rules.make +++ b/stepmake/stepmake/script-rules.make @@ -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 $@ diff --git a/stepmake/stepmake/substitute-vars.make b/stepmake/stepmake/substitute-vars.make index eb45a465fc..8d7fd6295b 100644 --- a/stepmake/stepmake/substitute-vars.make +++ b/stepmake/stepmake/substitute-vars.make @@ -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') +