Commit 93c8c17b authored by Karl Wette's avatar Karl Wette

Use Python wrapper scripts instead of self-executing headers

- Python wrapper sets PYTHONPATH as appropriate, then executes PYTHON
- Wrapper is then used as a #! command, which avoids interfering with
  Python code (e.g. module-level documentation in """ strings)
- Wrapper $(builddir)/.python_wrapper used for uninstalled scripts; when
  installed, wrapper substituted with $(pkgdatadir)/python_wrapper
- Except if LAL package is installed into same executable prefix as Python;
  then $(PYTHON) is used directly and no wrapper is installed
Original: f2995a5f5066289bf7409dc12711f61b5e53f946
parent a99edbc0
......@@ -2,19 +2,18 @@ SUFFIXES = .py
.PHONY: pymodule-all-local
.PHONY: pymodule-mostlyclean-local
.PHONY: pybin-clean-local
.PHONY: pybin-install-data-hook
.PHONY: pybin-uninstall-local
.PHONY: pybin-dist-hook
if HAVE_PYTHON
pybindir = $(bindir)
lalsuite_python_wrapper = $(top_srcdir)/gnuscripts/lalsuite_python_wrapper.in
BUILT_SOURCES += $(pymodule_PYTHON) $(pybin_SCRIPTS)
MOSTLYCLEANFILES += $(pybin_SCRIPTS)
python_install_script = $(top_srcdir)/gnuscripts/lalsuite_python_install_script
INSTALL_SCRIPT = $(python_install_script) $(INSTALL)
EXTRA_DIST += $(python_install_script)
MOSTLYCLEANFILES += .python_wrapper $(pybin_SCRIPTS)
EXTRA_DIST += $(lalsuite_python_wrapper)
all-local: pymodule-all-local
pymodule-all-local: pymodule-mostlyclean-local
......@@ -36,35 +35,62 @@ pymodule-mostlyclean-local:
done; \
fi
$(pybin_SCRIPTS): Makefile
.python_wrapper: $(lalsuite_python_wrapper)
$(AM_V_at)if $(SED) 's|[@]PYTHON[@]|$(PYTHON)|g;s|[@]lalsuite_pythonpath[@]|$(abs_builddir):$(abs_srcdir):$(LAL_PYTHON_PATH)|g' $< > $@; then \
chmod +x $@ || exit 1; \
exit 0; \
else \
rm -f $@; \
exit 1; \
fi
$(pybin_SCRIPTS): Makefile .python_wrapper
.py:
$(AM_V_GEN)if test -x $<; then \
echo "" >&2; \
echo "ERROR: $< must not be executable" >&2; \
echo "" >&2; \
printf "\nERROR: $< must not be executable\n\n" >&2; \
exit 1; \
fi; \
$(MKDIR_P) .pybin/ || exit 1; \
rm -f $@ $@.tmp .pybin/$@ || exit 1; \
echo "#!/bin/sh" > $@.tmp; \
echo "### SHELL SELF-EXECUTING HEADER SCRIPT" >> $@.tmp; \
echo "''':'" >> $@.tmp; \
echo "PYTHONPATH=\"$(abs_builddir):$(abs_srcdir):$(LAL_PYTHON_PATH):\$${PYTHONPATH}\"" >> $@.tmp; \
echo "export PYTHONPATH" >> $@.tmp; \
echo "exec $(PYTHON) \"\$$0\" \"\$$@\"" >> $@.tmp; \
echo "exit \$$?" >> $@.tmp; \
echo "fi" >> $@.tmp; \
echo "'''" >> $@.tmp; \
echo "### PYTHON SCRIPT" >> $@.tmp; \
$(SED) -e "s|^PYTHONPATH=.*|PYTHONPATH=\"$(pyexecdir):$(pythondir):\$${PYTHONPATH}\"|" $@.tmp > .pybin/$@ || exit 1; \
cat $< >> .pybin/$@ || exit 1; \
rm -f $@ $@.tmp || exit 1; \
echo "#!$(abs_builddir)/.python_wrapper" > $@.tmp; \
cat $< >> $@.tmp || exit 1; \
chmod +x $@.tmp || exit 1; \
mv -f $@.tmp $@
clean-local: pybin-clean-local
pybin-clean-local:
-rm -rf .pybin/
install-data-hook: pybin-install-data-hook
pybin-install-data-hook:
$(AM_V_at)if test "x$(pybin_SCRIPTS)" != x; then \
if test "x$(prefix)" = "x$(python_exec_prefix)"; then \
python_wrapper="$(PYTHON)"; \
else \
python_wrapper="$(pkgdatadir)/python_wrapper"; \
if test ! -x "$${python_wrapper}"; then \
echo " $(MKDIR_P) $(DESTDIR)$(pkgdatadir)"; \
$(MKDIR_P) $(DESTDIR)$(pkgdatadir) || exit 1; \
echo "Generating $(DESTDIR)$${python_wrapper}..."; \
sed_regex='s|[@]PYTHON[@]|$(PYTHON)|g;s|[@]lalsuite_pythonpath[@]|$(pyexecdir):$(pythondir)|g'; \
if $(SED) "$${sed_regex}" $(lalsuite_python_wrapper) > $(DESTDIR)$${python_wrapper}; then \
chmod 0755 $(DESTDIR)$${python_wrapper} || exit 1; \
else \
rm -f $(DESTDIR)$${python_wrapper}; \
printf "\nERROR: failed to generate $(DESTDIR)$${python_wrapper}\n\n" >&2; \
exit 1; \
fi; \
fi; \
fi; \
echo "Fixing shebangs commands in $(DESTDIR)$(pybindir)..."; \
for file in $(pybin_SCRIPTS); do \
printf " $${file}"; \
if $(SED) -i "s|^#!.*$$|#!$${python_wrapper}|" "$(DESTDIR)$(pybindir)/$${file}"; then : ; else \
printf "\n\nERROR: failed to fix shebang command of $(DESTDIR)$(pybindir)/$${file}\n\n" >&2; \
exit 1; \
fi; \
done; \
printf "\n"; \
fi
uninstall-local: pybin-uninstall-local
pybin-uninstall-local:
-rm -f "$(DESTDIR)$(pkgdatadir)/python_wrapper"
dist-hook: pybin-dist-hook
pybin-dist-hook:
......
#!/bin/sh
# Install Python scripts from .pybin/, which have the correct PYTHONPATH
# Author: Karl Wette, 2014
# first command line argument is 'install' command
cmd="$1"
if test "x${cmd}" = x; then
echo "$0: insufficient arguments" >&2
exit 1
fi
shift
# iterate over 'install' arguments
while test "x$1" != x; do
arg="$1"
if test -f "${arg}" && test -f ".pybin/${arg}"; then
arg=".pybin/${arg}"
fi
cmd="${cmd} '${arg}'"
shift
done
# print and execute 'install' command
echo " ${cmd}"
eval "${cmd}"
exit $?
#!/bin/sh
lalsuite_pythonpath="@lalsuite_pythonpath@"
case "${PYTHONPATH}:" in
"${lalsuite_pythonpath}:"*)
;;
*)
PYTHONPATH="${lalsuite_pythonpath}:${PYTHONPATH}"
;;
esac
export PYTHONPATH
exec "@PYTHON@" "$@"
exit $?
......@@ -11,7 +11,7 @@
.deps
.dvi-dep
.libs
.pybin
.python_wrapper
/_build/
/_inst/
/lal-*/
......
../../gnuscripts/lalsuite_python_install_script
\ No newline at end of file
../../gnuscripts/lalsuite_python_wrapper.in
\ No newline at end of file
......@@ -7,7 +7,7 @@
*.pyo
.deps
.libs
.pybin
.python_wrapper
/_build/
/_inst/
/lalapps-*/
......
../../gnuscripts/lalsuite_python_install_script
\ No newline at end of file
../../gnuscripts/lalsuite_python_wrapper.in
\ No newline at end of file
......@@ -7,7 +7,7 @@
*.pyo
.deps
.libs
.pybin
.python_wrapper
/_build/
/_inst/
/lalburst-*/
......
../../gnuscripts/lalsuite_python_install_script
\ No newline at end of file
../../gnuscripts/lalsuite_python_wrapper.in
\ No newline at end of file
......@@ -7,7 +7,7 @@
*.pyo
.deps
.libs
.pybin
.python_wrapper
/_build/
/_inst/
/laldetchar-*/
......
../../gnuscripts/lalsuite_python_install_script
\ No newline at end of file
../../gnuscripts/lalsuite_python_wrapper.in
\ No newline at end of file
......@@ -17,7 +17,7 @@
# MA 02111-1307 USA
#
# Based on the reference implementation in MATLAB by Josh Smith, et al.
__doc__ = """trigger based hierarchical veto"""
"""trigger based hierarchical veto"""
import sys
......
......@@ -14,7 +14,7 @@
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
__doc__ = """Generate segments from thresholding data"""
"""Generate segments from thresholding data"""
import sys
......
......@@ -7,7 +7,7 @@
*.pyo
.deps
.libs
.pybin
.python_wrapper
/_build/
/_inst/
/lalframe-*/
......
../../gnuscripts/lalsuite_python_install_script
\ No newline at end of file
../../gnuscripts/lalsuite_python_wrapper.in
\ No newline at end of file
......@@ -7,7 +7,7 @@
*.pyo
.deps
.libs
.pybin
.python_wrapper
/_build/
/_inst/
/lalinference-*/
......
../../gnuscripts/lalsuite_python_install_script
\ No newline at end of file
../../gnuscripts/lalsuite_python_wrapper.in
\ No newline at end of file
......@@ -7,7 +7,7 @@
*.pyo
.deps
.libs
.pybin
.python_wrapper
/_build/
/_inst/
/lalinspiral-*/
......
../../gnuscripts/lalsuite_python_install_script
\ No newline at end of file
../../gnuscripts/lalsuite_python_wrapper.in
\ No newline at end of file
......@@ -7,7 +7,7 @@
*.pyo
.deps
.libs
.pybin
.python_wrapper
/_build/
/_inst/
/lalmetaio-*/
......
../../gnuscripts/lalsuite_python_install_script
\ No newline at end of file
../../gnuscripts/lalsuite_python_wrapper.in
\ No newline at end of file
......@@ -7,7 +7,7 @@
*.pyo
.deps
.libs
.pybin
.python_wrapper
/_build/
/_inst/
/lalpulsar-*/
......
../../gnuscripts/lalsuite_python_install_script
\ No newline at end of file
../../gnuscripts/lalsuite_python_wrapper.in
\ No newline at end of file
......@@ -7,7 +7,7 @@
*.pyo
.deps
.libs
.pybin
.python_wrapper
/_build/
/_inst/
/lalsimulation-*/
......
../../gnuscripts/lalsuite_python_install_script
\ No newline at end of file
../../gnuscripts/lalsuite_python_wrapper.in
\ No newline at end of file
......@@ -7,7 +7,7 @@
*.pyo
.deps
.libs
.pybin
.python_wrapper
/_build/
/_inst/
/lalstochastic-*/
......
../../gnuscripts/lalsuite_python_install_script
\ No newline at end of file
../../gnuscripts/lalsuite_python_wrapper.in
\ No newline at end of file
......@@ -7,7 +7,7 @@
*.pyo
.deps
.libs
.pybin
.python_wrapper
/_build/
/_inst/
/lalxml-*/
......
../../gnuscripts/lalsuite_python_install_script
\ No newline at end of file
../../gnuscripts/lalsuite_python_wrapper.in
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment