Commit 4db619b5 authored by Karl Wette's avatar Karl Wette Committed by Jolien Creighton

Make "executable Python script" a shell wrapper which calls Python source file

- Avoid problem with #! line length limit, since #! no longer calls wrapper
- Avoid problems with Python documentation and __future__ imports, since
  Python source file is not modified (except by possibly adding #! line)
- Rename $(pybin_SCRIPTS) to $(pybin_scripts), since installation of Python
  scripts is now handled manually, not by Automake
- If installing into the same exec_prefix as Python, install the Python source
  script with a #!$(PYTHON) line; otherwise, install a modified shell wrapper
  script in $(bindir) and Python source script in $(pkglibexecdir)
Original: 288ba9dccf52397d77483eb7699da6db62c30bb0
parent 6bf54814
...@@ -2,18 +2,15 @@ SUFFIXES = .py ...@@ -2,18 +2,15 @@ SUFFIXES = .py
.PHONY: pymodule-all-local .PHONY: pymodule-all-local
.PHONY: pymodule-mostlyclean-local .PHONY: pymodule-mostlyclean-local
.PHONY: pybin-install-data-hook .PHONY: pybin-install-exec-local
.PHONY: pybin-uninstall-local .PHONY: pybin-uninstall-local
.PHONY: pybin-dist-hook .PHONY: pybin-dist-hook
if HAVE_PYTHON if HAVE_PYTHON
pybindir = $(bindir) BUILT_SOURCES += $(pymodule_PYTHON) $(pybin_scripts)
lalsuite_python_wrapper = $(top_srcdir)/gnuscripts/lalsuite_python_wrapper.sh.in MOSTLYCLEANFILES += $(pybin_scripts)
EXTRA_DIST +=
BUILT_SOURCES += $(pymodule_PYTHON) $(pybin_SCRIPTS)
MOSTLYCLEANFILES += .python_wrapper.sh $(pybin_SCRIPTS)
EXTRA_DIST += $(lalsuite_python_wrapper)
all-local: pymodule-all-local all-local: pymodule-all-local
pymodule-all-local: pymodule-mostlyclean-local pymodule-all-local: pymodule-mostlyclean-local
...@@ -35,87 +32,80 @@ pymodule-mostlyclean-local: ...@@ -35,87 +32,80 @@ pymodule-mostlyclean-local:
done; \ done; \
fi fi
.python_wrapper.sh: $(lalsuite_python_wrapper) $(pybin_scripts): Makefile
$(AM_V_at)pywrapregex='s|[@]SED[@]|$(SED)|g;s|[@]PYTHON[@]|$(PYTHON)|g;s|[@]lalsuite_pythonpath[@]'; \
pypath="$(abs_builddir):$(abs_srcdir):$(LAL_PYTHON_PATH)"; \
if $(SED) "$${pywrapregex}|$${pypath}|g" $< > $@; then \
: ; \
else \
rm -f $@; \
exit 1; \
fi
$(pybin_SCRIPTS): Makefile .python_wrapper.sh
.py: .py:
$(AM_V_GEN)shebang='#!'; \ $(AM_V_GEN)shebang='#!'; \
rm -f $@ $@.tmp || exit 1; \ rm -f $@ $@.tmp || exit 1; \
if test -x $<; then \ if test -x $(srcdir)/$@.py; then \
printf "\nERROR: $< must not be executable\n\n" >&2; \ printf "\nERROR: $(srcdir)/$@.py must not be executable\n\n" >&2; \
exit 1; \ exit 1; \
fi; \ fi; \
if test x`$(SED) -n -e "/^$${shebang}/p" $<` != x; then \ if test x`$(SED) -n -e "/^$${shebang}/p" $(srcdir)/$@.py` != x; then \
printf "\nERROR: $< must not contain a $${shebang} command line\n\n" >&2; \ printf "\nERROR: $(srcdir)/$@.py must not contain a $${shebang} command line\n\n" >&2; \
exit 1; \ exit 1; \
fi; \ fi; \
echo "$${shebang}/bin/sh $(abs_builddir)/.python_wrapper.sh" > $@.tmp; \ echo "$${shebang}/bin/sh" > $@.tmp; \
cat $< >> $@.tmp || exit 1; \ echo "pypath=\"$(abs_builddir):$(abs_srcdir):$(LAL_PYTHON_PATH)\"" >> $@.tmp; \
echo "pyscript=\"$(abs_srcdir)/$@.py\"" >> $@.tmp; \
echo "PYTHONPATH=\`echo \"\$${PYTHONPATH}\" | $(SED) -e \"s|\$${pypath}:||g;\"\`" >> $@.tmp; \
echo "PYTHONPATH=\"\$${pypath}:\$${PYTHONPATH}\"" >> $@.tmp; \
echo "export PYTHONPATH" >> $@.tmp; \
echo "exec $(PYTHON) \"\$${pyscript}\" \"\$$@\"" >> $@.tmp; \
echo "exit \$$?" >> $@.tmp; \
chmod +x $@.tmp || exit 1; \ chmod +x $@.tmp || exit 1; \
mv -f $@.tmp $@ mv -f $@.tmp $@
install-data-hook: pybin-install-data-hook install-exec-local: pybin-install-exec-local
pybin-install-data-hook: pybin-install-exec-local:
$(AM_V_GEN)shebang='#!'; \ $(AM_V_at)shebang='#!'; \
pywrapregex='s|[@]SED[@]|$(SED)|g;s|[@]PYTHON[@]|$(PYTHON)|g;s|[@]lalsuite_pythonpath[@]'; \ if test "x$(pybin_scripts)" != x; then \
if test "x$(pybin_SCRIPTS)" != x; then \ pypath="$(pyexecdir)"; \
if test "x$(prefix)" = "x$(python_exec_prefix)"; then \ if test "$(pythondir)" != "$(pyexecdir)"; then \
shebang_command="$${shebang}$(PYTHON)"; \ pypath="$${pypath}:$(pythondir)"; \
else \ fi; \
python_wrapper="$(pkglibexecdir)/python_wrapper.sh"; \ echo " $(MKDIR_P) '$(DESTDIR)$(bindir)'"; \
echo " $(MKDIR_P) $(DESTDIR)$(pkglibexecdir)"; \ $(MKDIR_P) "$(DESTDIR)$(bindir)" || exit 1; \
$(MKDIR_P) $(DESTDIR)$(pkglibexecdir) || exit 1; \ if test "x$(exec_prefix)" != "x$(python_exec_prefix)"; then \
echo "Generating $(DESTDIR)$${python_wrapper}..."; \ echo " $(MKDIR_P) '$(DESTDIR)$(pkglibexecdir)'"; \
pypath="$(pyexecdir)"; \ $(MKDIR_P) "$(DESTDIR)$(pkglibexecdir)" || exit 1; \
if test "$(pythondir)" != "$(pyexecdir)"; then \
pypath="$${pypath}:$(pythondir)"; \
fi; \
if $(SED) "$${pywrapregex}|$${pypath}|g" $(lalsuite_python_wrapper) > $(DESTDIR)$${python_wrapper}; then \
: ; \
else \
rm -f $(DESTDIR)$${python_wrapper}; \
printf "\nERROR: failed to generate $(DESTDIR)$${python_wrapper}\n\n" >&2; \
exit 1; \
fi; \
shebang_command="$${shebang}/bin/sh $${python_wrapper}"; \
fi; \ fi; \
echo "Fixing shebangs commands in $(DESTDIR)$(pybindir)..."; \ for file in $(pybin_scripts); do \
for file in $(pybin_SCRIPTS); do \ rm -f $${file}.tmp || exit 1; \
printf " $${file}"; \ if test "x$(exec_prefix)" = "x$(python_exec_prefix)"; then \
if $(SED) -i.tmp "s|^$${shebang}.*$$|$${shebang_command}|" $(DESTDIR)$(pybindir)/$${file}; then \ echo "$${shebang}$(PYTHON)" > $${file}.tmp; \
rm -f $(DESTDIR)$(pybindir)/$${file}.tmp; \ cat $(srcdir)/$${file}.py >> $${file}.tmp; \
else \ else \
printf "\n\nERROR: failed to fix shebang command of $(DESTDIR)$(pybindir)/$${file}\n\n" >&2; \ sed_regex="s|^pypath=.*$$|pypath=\"$${pypath}\"|;s|^pyscript=.*$$|pyscript=\"$(pkglibexecdir)/$${file}.py\"|"; \
exit 1; \ $(SED) -e "$${sed_regex}" $${file} > $${file}.tmp || exit 1; \
echo " $(INSTALL_DATA) $(srcdir)/$${file}.py '$(DESTDIR)$(pkglibexecdir)/$${file}.py'"; \
$(INSTALL_DATA) $(srcdir)/$${file}.py "$(DESTDIR)$(pkglibexecdir)/$${file}.py" || exit 1; \
fi; \ fi; \
echo " $(INSTALL_SCRIPT) $${file}.tmp '$(DESTDIR)$(bindir)/$${file}'"; \
$(INSTALL_SCRIPT) $${file}.tmp "$(DESTDIR)$(bindir)/$${file}" || exit 1; \
rm -f $${file}.tmp || exit 1; \
done; \ done; \
printf "\n"; \
fi fi
uninstall-local: pybin-uninstall-local uninstall-local: pybin-uninstall-local
pybin-uninstall-local: pybin-uninstall-local:
-rm -f "$(DESTDIR)$(pkglibexecdir)/python_wrapper.sh" -for file in $(pybin_scripts); do \
rm -f "$(DESTDIR)$(bindir)/$${file}"; \
if test "x$(exec_prefix)" != "x$(python_exec_prefix)"; then \
rm -f "$(DESTDIR)$(pkglibexecdir)/$${file}.py"; \
fi; \
done
dist-hook: pybin-dist-hook dist-hook: pybin-dist-hook
pybin-dist-hook: pybin-dist-hook:
for file in $(pybin_SCRIPTS); do \ for file in $(pybin_scripts); do \
cp "$(srcdir)/$${file}.py" "$(distdir)"; \ cp "$(srcdir)/$${file}.py" "$(distdir)/$${file}.py"; \
done done
else # !HAVE_PYTHON else # !HAVE_PYTHON
pkgpython_PYTHON =
pymoduledir = pymoduledir =
pymodule_PYTHON = pymodule_PYTHON =
pybindir = pybin_scripts =
pybin_SCRIPTS = pkgpython_PYTHON =
endif # HAVE_PYTHON endif # HAVE_PYTHON
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
.deps .deps
.dvi-dep .dvi-dep
.libs .libs
.python_wrapper.sh
/_build/ /_build/
/_inst/ /_inst/
/lal-*/ /lal-*/
......
../../gnuscripts/lalsuite_python_wrapper.sh.in
\ No newline at end of file
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
*.pyo *.pyo
.deps .deps
.libs .libs
.python_wrapper.sh
/_build/ /_build/
/_inst/ /_inst/
/lalapps-*/ /lalapps-*/
......
../../gnuscripts/lalsuite_python_wrapper.sh.in
\ No newline at end of file
...@@ -14,7 +14,7 @@ bin_PROGRAMS = \ ...@@ -14,7 +14,7 @@ bin_PROGRAMS = \
lalapps_NoiseComparison lalapps_NoiseComparison
if HAVE_PYTHON if HAVE_PYTHON
pybin_SCRIPTS = lalapps_strain_pipe lalapps_noise_comp_pipe pybin_scripts = lalapps_strain_pipe lalapps_noise_comp_pipe
pkgpython_PYTHON = strain.py pkgpython_PYTHON = strain.py
endif endif
......
...@@ -128,7 +128,7 @@ bin_PROGRAMS = \ ...@@ -128,7 +128,7 @@ bin_PROGRAMS = \
$(LALPULSAR_PROGS) $(LALPULSAR_PROGS)
if HAVE_PYTHON if HAVE_PYTHON
pybin_SCRIPTS = \ pybin_scripts = \
lalapps_inspiral_pipe \ lalapps_inspiral_pipe \
lalapps_inspiral_hipe \ lalapps_inspiral_hipe \
lalapps_inspiral_ssipe \ lalapps_inspiral_ssipe \
......
...@@ -62,7 +62,7 @@ noinst_PROGRAMS = \ ...@@ -62,7 +62,7 @@ noinst_PROGRAMS = \
$(td_test_progs) $(td_test_progs)
if HAVE_PYTHON if HAVE_PYTHON
pybin_SCRIPTS = \ pybin_scripts = \
lalapps_combine_evidence \ lalapps_combine_evidence \
lalapps_coherence_test \ lalapps_coherence_test \
lalapps_nest_pipe \ lalapps_nest_pipe \
......
...@@ -69,7 +69,7 @@ if HAVE_PYTHON ...@@ -69,7 +69,7 @@ if HAVE_PYTHON
pkgpython_PYTHON = \ pkgpython_PYTHON = \
__init__.py \ __init__.py \
git_version.py git_version.py
pybin_SCRIPTS = \ pybin_scripts = \
lalapps_path2cache \ lalapps_path2cache \
lalapps_searchsum2cache lalapps_searchsum2cache
endif endif
......
...@@ -23,7 +23,7 @@ noinst_PROGRAMS = sense_compare ...@@ -23,7 +23,7 @@ noinst_PROGRAMS = sense_compare
sense_compare_SOURCES = sense_compare.c sense_compare_SOURCES = sense_compare.c
if HAVE_PYTHON if HAVE_PYTHON
pybin_SCRIPTS = lalapps_power_pipe lalapps_power_online_pipe lalapps_power_likelihood_pipe pybin_scripts = lalapps_power_pipe lalapps_power_online_pipe lalapps_power_likelihood_pipe
pkgpython_PYTHON = power.py pkgpython_PYTHON = power.py
endif endif
......
...@@ -77,7 +77,7 @@ endif ...@@ -77,7 +77,7 @@ endif
if HAVE_PYTHON if HAVE_PYTHON
pkgpython_PYTHON = ring.py pkgpython_PYTHON = ring.py
pybin_SCRIPTS = \ pybin_scripts = \
lalapps_ring_pipe \ lalapps_ring_pipe \
lalapps_ringcorse lalapps_ringcorse
endif endif
......
...@@ -54,7 +54,7 @@ bin_PROGRAMS = ${STOCHASTICPROGRAMS} ${FRAMEPROGRAMS} ${METAIOPROGRAMS} ...@@ -54,7 +54,7 @@ bin_PROGRAMS = ${STOCHASTICPROGRAMS} ${FRAMEPROGRAMS} ${METAIOPROGRAMS}
if LALSTOCHASTIC if LALSTOCHASTIC
if HAVE_PYTHON if HAVE_PYTHON
pybin_SCRIPTS = lalapps_stochastic_pipe lalapps_stochastic_bayes pybin_scripts = lalapps_stochastic_pipe lalapps_stochastic_bayes
pkgpython_PYTHON = stochastic.py pkgpython_PYTHON = stochastic.py
endif endif
endif endif
......
...@@ -15,7 +15,7 @@ endif ...@@ -15,7 +15,7 @@ endif
endif endif
if HAVE_PYTHON if HAVE_PYTHON
pybin_SCRIPTS = \ pybin_scripts = \
lalapps_cosmicstring_pipe \ lalapps_cosmicstring_pipe \
lalapps_string_cs_gamma lalapps_string_cs_gamma
pkgpython_PYTHON = cosmicstring.py pkgpython_PYTHON = cosmicstring.py
......
...@@ -48,7 +48,7 @@ lalapps_tracksearch_dat2pgm_SOURCES = \ ...@@ -48,7 +48,7 @@ lalapps_tracksearch_dat2pgm_SOURCES = \
tracksearchToolbox.h tracksearchToolbox.h
if HAVE_PYTHON if HAVE_PYTHON
pybin_SCRIPTS = \ pybin_scripts = \
lalapps_tracksearch_handler \ lalapps_tracksearch_handler \
lalapps_tracksearch_pipe \ lalapps_tracksearch_pipe \
lalapps_tracksearch_housekeeper \ lalapps_tracksearch_housekeeper \
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
*.pyo *.pyo
.deps .deps
.libs .libs
.python_wrapper.sh
/_build/ /_build/
/_inst/ /_inst/
/lalburst-*/ /lalburst-*/
......
../../gnuscripts/lalsuite_python_wrapper.sh.in
\ No newline at end of file
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
*.pyo *.pyo
.deps .deps
.libs .libs
.python_wrapper.sh
/_build/ /_build/
/_inst/ /_inst/
/laldetchar-*/ /laldetchar-*/
......
../../gnuscripts/lalsuite_python_wrapper.sh.in
\ No newline at end of file
...@@ -7,7 +7,7 @@ SUBDIRS = laldetchar ...@@ -7,7 +7,7 @@ SUBDIRS = laldetchar
if HAVE_PYTHON if HAVE_PYTHON
pybin_SCRIPTS = \ pybin_scripts = \
laldetchar-hveto \ laldetchar-hveto \
laldetchar-hveto-summary-page \ laldetchar-hveto-summary-page \
laldetchar-segments-from-data \ laldetchar-segments-from-data \
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
*.pyo *.pyo
.deps .deps
.libs .libs
.python_wrapper.sh
/_build/ /_build/
/_inst/ /_inst/
/lalframe-*/ /lalframe-*/
......
../../gnuscripts/lalsuite_python_wrapper.sh.in
\ No newline at end of file
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
*.pyo *.pyo
.deps .deps
.libs .libs
.python_wrapper.sh
/_build/ /_build/
/_inst/ /_inst/
/lalinference-*/ /lalinference-*/
......
../../gnuscripts/lalsuite_python_wrapper.sh.in
\ No newline at end of file
...@@ -7,7 +7,7 @@ SUBDIRS = lalinference ...@@ -7,7 +7,7 @@ SUBDIRS = lalinference
if HAVE_PYTHON if HAVE_PYTHON
pybin_SCRIPTS = \ pybin_scripts = \
bayestar_aggregate_found_injections \ bayestar_aggregate_found_injections \
bayestar_bin_samples \ bayestar_bin_samples \
bayestar_lattice_tmpltbank \ bayestar_lattice_tmpltbank \
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
*.pyo *.pyo
.deps .deps
.libs .libs
.python_wrapper.sh
/_build/ /_build/
/_inst/ /_inst/
/lalinspiral-*/ /lalinspiral-*/
......
../../gnuscripts/lalsuite_python_wrapper.sh.in
\ No newline at end of file
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
*.pyo *.pyo
.deps .deps
.libs .libs
.python_wrapper.sh
/_build/ /_build/
/_inst/ /_inst/
/lalmetaio-*/ /lalmetaio-*/
......
../../gnuscripts/lalsuite_python_wrapper.sh.in
\ No newline at end of file
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
*.pyo *.pyo
.deps .deps
.libs .libs
.python_wrapper.sh
/_build/ /_build/
/_inst/ /_inst/
/lalpulsar-*/ /lalpulsar-*/
......
../../gnuscripts/lalsuite_python_wrapper.sh.in
\ No newline at end of file
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
*.pyo *.pyo
.deps .deps
.libs .libs
.python_wrapper.sh
/_build/ /_build/
/_inst/ /_inst/
/lalsimulation-*/ /lalsimulation-*/
......
../../gnuscripts/lalsuite_python_wrapper.sh.in
\ No newline at end of file
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
*.pyo *.pyo
.deps .deps
.libs .libs
.python_wrapper.sh
/_build/ /_build/
/_inst/ /_inst/
/lalstochastic-*/ /lalstochastic-*/
......
../../gnuscripts/lalsuite_python_wrapper.sh.in
\ No newline at end of file
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
*.pyo *.pyo
.deps .deps
.libs .libs
.python_wrapper.sh
/_build/ /_build/
/_inst/ /_inst/
/lalxml-*/ /lalxml-*/
......
../../gnuscripts/lalsuite_python_wrapper.sh.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