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
.PHONY: pymodule-all-local
.PHONY: pymodule-mostlyclean-local
.PHONY: pybin-install-data-hook
.PHONY: pybin-install-exec-local
.PHONY: pybin-uninstall-local
.PHONY: pybin-dist-hook
if HAVE_PYTHON
pybindir = $(bindir)
lalsuite_python_wrapper = $(top_srcdir)/gnuscripts/lalsuite_python_wrapper.sh.in
BUILT_SOURCES += $(pymodule_PYTHON) $(pybin_SCRIPTS)
MOSTLYCLEANFILES += .python_wrapper.sh $(pybin_SCRIPTS)
EXTRA_DIST += $(lalsuite_python_wrapper)
BUILT_SOURCES += $(pymodule_PYTHON) $(pybin_scripts)
MOSTLYCLEANFILES += $(pybin_scripts)
EXTRA_DIST +=
all-local: pymodule-all-local
pymodule-all-local: pymodule-mostlyclean-local
......@@ -35,87 +32,80 @@ pymodule-mostlyclean-local:
done; \
fi
.python_wrapper.sh: $(lalsuite_python_wrapper)
$(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
$(pybin_scripts): Makefile
.py:
$(AM_V_GEN)shebang='#!'; \
rm -f $@ $@.tmp || exit 1; \
if test -x $<; then \
printf "\nERROR: $< must not be executable\n\n" >&2; \
if test -x $(srcdir)/$@.py; then \
printf "\nERROR: $(srcdir)/$@.py must not be executable\n\n" >&2; \
exit 1; \
fi; \
if test x`$(SED) -n -e "/^$${shebang}/p" $<` != x; then \
printf "\nERROR: $< must not contain a $${shebang} command line\n\n" >&2; \
if test x`$(SED) -n -e "/^$${shebang}/p" $(srcdir)/$@.py` != x; then \
printf "\nERROR: $(srcdir)/$@.py must not contain a $${shebang} command line\n\n" >&2; \
exit 1; \
fi; \
echo "$${shebang}/bin/sh $(abs_builddir)/.python_wrapper.sh" > $@.tmp; \
cat $< >> $@.tmp || exit 1; \
echo "$${shebang}/bin/sh" > $@.tmp; \
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; \
mv -f $@.tmp $@
install-data-hook: pybin-install-data-hook
pybin-install-data-hook:
$(AM_V_GEN)shebang='#!'; \
pywrapregex='s|[@]SED[@]|$(SED)|g;s|[@]PYTHON[@]|$(PYTHON)|g;s|[@]lalsuite_pythonpath[@]'; \
if test "x$(pybin_SCRIPTS)" != x; then \
if test "x$(prefix)" = "x$(python_exec_prefix)"; then \
shebang_command="$${shebang}$(PYTHON)"; \
else \
python_wrapper="$(pkglibexecdir)/python_wrapper.sh"; \
echo " $(MKDIR_P) $(DESTDIR)$(pkglibexecdir)"; \
$(MKDIR_P) $(DESTDIR)$(pkglibexecdir) || exit 1; \
echo "Generating $(DESTDIR)$${python_wrapper}..."; \
install-exec-local: pybin-install-exec-local
pybin-install-exec-local:
$(AM_V_at)shebang='#!'; \
if test "x$(pybin_scripts)" != x; then \
pypath="$(pyexecdir)"; \
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}"; \
echo " $(MKDIR_P) '$(DESTDIR)$(bindir)'"; \
$(MKDIR_P) "$(DESTDIR)$(bindir)" || exit 1; \
if test "x$(exec_prefix)" != "x$(python_exec_prefix)"; then \
echo " $(MKDIR_P) '$(DESTDIR)$(pkglibexecdir)'"; \
$(MKDIR_P) "$(DESTDIR)$(pkglibexecdir)" || exit 1; \
fi; \
echo "Fixing shebangs commands in $(DESTDIR)$(pybindir)..."; \
for file in $(pybin_SCRIPTS); do \
printf " $${file}"; \
if $(SED) -i.tmp "s|^$${shebang}.*$$|$${shebang_command}|" $(DESTDIR)$(pybindir)/$${file}; then \
rm -f $(DESTDIR)$(pybindir)/$${file}.tmp; \
for file in $(pybin_scripts); do \
rm -f $${file}.tmp || exit 1; \
if test "x$(exec_prefix)" = "x$(python_exec_prefix)"; then \
echo "$${shebang}$(PYTHON)" > $${file}.tmp; \
cat $(srcdir)/$${file}.py >> $${file}.tmp; \
else \
printf "\n\nERROR: failed to fix shebang command of $(DESTDIR)$(pybindir)/$${file}\n\n" >&2; \
exit 1; \
sed_regex="s|^pypath=.*$$|pypath=\"$${pypath}\"|;s|^pyscript=.*$$|pyscript=\"$(pkglibexecdir)/$${file}.py\"|"; \
$(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; \
echo " $(INSTALL_SCRIPT) $${file}.tmp '$(DESTDIR)$(bindir)/$${file}'"; \
$(INSTALL_SCRIPT) $${file}.tmp "$(DESTDIR)$(bindir)/$${file}" || exit 1; \
rm -f $${file}.tmp || exit 1; \
done; \
printf "\n"; \
fi
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
pybin-dist-hook:
for file in $(pybin_SCRIPTS); do \
cp "$(srcdir)/$${file}.py" "$(distdir)"; \
for file in $(pybin_scripts); do \
cp "$(srcdir)/$${file}.py" "$(distdir)/$${file}.py"; \
done
else # !HAVE_PYTHON
pkgpython_PYTHON =
pymoduledir =
pymodule_PYTHON =
pybindir =
pybin_SCRIPTS =
pybin_scripts =
pkgpython_PYTHON =
endif # HAVE_PYTHON
......@@ -11,7 +11,6 @@
.deps
.dvi-dep
.libs
.python_wrapper.sh
/_build/
/_inst/
/lal-*/
......
../../gnuscripts/lalsuite_python_wrapper.sh.in
\ No newline at end of file
......@@ -7,7 +7,6 @@
*.pyo
.deps
.libs
.python_wrapper.sh
/_build/
/_inst/
/lalapps-*/
......
../../gnuscripts/lalsuite_python_wrapper.sh.in
\ No newline at end of file
......@@ -14,7 +14,7 @@ bin_PROGRAMS = \
lalapps_NoiseComparison
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
endif
......
......@@ -128,7 +128,7 @@ bin_PROGRAMS = \
$(LALPULSAR_PROGS)
if HAVE_PYTHON
pybin_SCRIPTS = \
pybin_scripts = \
lalapps_inspiral_pipe \
lalapps_inspiral_hipe \
lalapps_inspiral_ssipe \
......
......@@ -62,7 +62,7 @@ noinst_PROGRAMS = \
$(td_test_progs)
if HAVE_PYTHON
pybin_SCRIPTS = \
pybin_scripts = \
lalapps_combine_evidence \
lalapps_coherence_test \
lalapps_nest_pipe \
......
......@@ -69,7 +69,7 @@ if HAVE_PYTHON
pkgpython_PYTHON = \
__init__.py \
git_version.py
pybin_SCRIPTS = \
pybin_scripts = \
lalapps_path2cache \
lalapps_searchsum2cache
endif
......
......@@ -23,7 +23,7 @@ noinst_PROGRAMS = sense_compare
sense_compare_SOURCES = sense_compare.c
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
endif
......
......@@ -77,7 +77,7 @@ endif
if HAVE_PYTHON
pkgpython_PYTHON = ring.py
pybin_SCRIPTS = \
pybin_scripts = \
lalapps_ring_pipe \
lalapps_ringcorse
endif
......
......@@ -54,7 +54,7 @@ bin_PROGRAMS = ${STOCHASTICPROGRAMS} ${FRAMEPROGRAMS} ${METAIOPROGRAMS}
if LALSTOCHASTIC
if HAVE_PYTHON
pybin_SCRIPTS = lalapps_stochastic_pipe lalapps_stochastic_bayes
pybin_scripts = lalapps_stochastic_pipe lalapps_stochastic_bayes
pkgpython_PYTHON = stochastic.py
endif
endif
......
......@@ -15,7 +15,7 @@ endif
endif
if HAVE_PYTHON
pybin_SCRIPTS = \
pybin_scripts = \
lalapps_cosmicstring_pipe \
lalapps_string_cs_gamma
pkgpython_PYTHON = cosmicstring.py
......
......@@ -48,7 +48,7 @@ lalapps_tracksearch_dat2pgm_SOURCES = \
tracksearchToolbox.h
if HAVE_PYTHON
pybin_SCRIPTS = \
pybin_scripts = \
lalapps_tracksearch_handler \
lalapps_tracksearch_pipe \
lalapps_tracksearch_housekeeper \
......
......@@ -7,7 +7,6 @@
*.pyo
.deps
.libs
.python_wrapper.sh
/_build/
/_inst/
/lalburst-*/
......
../../gnuscripts/lalsuite_python_wrapper.sh.in
\ No newline at end of file
......@@ -7,7 +7,6 @@
*.pyo
.deps
.libs
.python_wrapper.sh
/_build/
/_inst/
/laldetchar-*/
......
../../gnuscripts/lalsuite_python_wrapper.sh.in
\ No newline at end of file
......@@ -7,7 +7,7 @@ SUBDIRS = laldetchar
if HAVE_PYTHON
pybin_SCRIPTS = \
pybin_scripts = \
laldetchar-hveto \
laldetchar-hveto-summary-page \
laldetchar-segments-from-data \
......
......@@ -7,7 +7,6 @@
*.pyo
.deps
.libs
.python_wrapper.sh
/_build/
/_inst/
/lalframe-*/
......
../../gnuscripts/lalsuite_python_wrapper.sh.in
\ No newline at end of file
......@@ -7,7 +7,6 @@
*.pyo
.deps
.libs
.python_wrapper.sh
/_build/
/_inst/
/lalinference-*/
......
../../gnuscripts/lalsuite_python_wrapper.sh.in
\ No newline at end of file
......@@ -7,7 +7,7 @@ SUBDIRS = lalinference
if HAVE_PYTHON
pybin_SCRIPTS = \
pybin_scripts = \
bayestar_aggregate_found_injections \
bayestar_bin_samples \
bayestar_lattice_tmpltbank \
......
......@@ -7,7 +7,6 @@
*.pyo
.deps
.libs
.python_wrapper.sh
/_build/
/_inst/
/lalinspiral-*/
......
../../gnuscripts/lalsuite_python_wrapper.sh.in
\ No newline at end of file
......@@ -7,7 +7,6 @@
*.pyo
.deps
.libs
.python_wrapper.sh
/_build/
/_inst/
/lalmetaio-*/
......
../../gnuscripts/lalsuite_python_wrapper.sh.in
\ No newline at end of file
......@@ -7,7 +7,6 @@
*.pyo
.deps
.libs
.python_wrapper.sh
/_build/
/_inst/
/lalpulsar-*/
......
../../gnuscripts/lalsuite_python_wrapper.sh.in
\ No newline at end of file
......@@ -7,7 +7,6 @@
*.pyo
.deps
.libs
.python_wrapper.sh
/_build/
/_inst/
/lalsimulation-*/
......
../../gnuscripts/lalsuite_python_wrapper.sh.in
\ No newline at end of file
......@@ -7,7 +7,6 @@
*.pyo
.deps
.libs
.python_wrapper.sh
/_build/
/_inst/
/lalstochastic-*/
......
../../gnuscripts/lalsuite_python_wrapper.sh.in
\ No newline at end of file
......@@ -7,7 +7,6 @@
*.pyo
.deps
.libs
.python_wrapper.sh
/_build/
/_inst/
/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