From a6add8f7837046f3ade063817de498d1835138cf Mon Sep 17 00:00:00 2001 From: Karl Wette Date: Thu, 7 Nov 2024 21:37:09 +1100 Subject: [PATCH 1/6] Fix Python wrapper scripts, require placeholder for shebang --- gnuscripts/lalsuite_build.m4 | 13 +++++++++++- gnuscripts/lalsuite_python.am | 39 ++++++++++++++++++----------------- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/gnuscripts/lalsuite_build.m4 b/gnuscripts/lalsuite_build.m4 index 790b7377f1..81ace7808d 100644 --- a/gnuscripts/lalsuite_build.m4 +++ b/gnuscripts/lalsuite_build.m4 @@ -1,7 +1,7 @@ # -*- mode: autoconf; -*- # lalsuite_build.m4 - top level build macros # -# serial 182 +# serial 183 # restrict which LALSUITE_... patterns can appearing in output (./configure); # useful for debugging problems with unexpanded LALSUITE_... Autoconf macros @@ -527,8 +527,19 @@ AC_DEFUN([LALSUITE_CHECK_PYTHON],[ ]) ]) # Always install Python files into the same prefix as the rest of LALSuite + # - These variables may be set by AM_PATH_PYTHON AC_SUBST([PYTHON_PREFIX], ['${prefix}']) AC_SUBST([PYTHON_EXEC_PREFIX], ['${exec_prefix}']) + # Prefix where Python executable is installed + AC_SUBST([LALSUITE_PYTHON_SYS_PREFIX],[`${PYTHON} -c 'import sys; print(sys.prefix)'`]) + AS_IF([test "x${LALSUITE_PYTHON_SYS_PREFIX}" = x],[ + AC_MSG_ERROR([could not determine ${PYTHON} sys.prefix]) + ]) + # Path to Python executable + AC_SUBST([LALSUITE_PYTHON_SYS_EXECUTABLE],[`${PYTHON} -c 'import sys; print(sys.executable)'`]) + AS_IF([test "x${LALSUITE_PYTHON_SYS_EXECUTABLE}" = x],[ + AC_MSG_ERROR([could not determine ${PYTHON} sys.executable]) + ]) ]) AS_IF([test "x${python}" = xfalse && test "x${lalsuite_require_pyvers}" = x],[ AC_SUBST([PYTHON],["${SHELL} -c 'echo ERROR: Python is missing >&2; exit 1' --"]) diff --git a/gnuscripts/lalsuite_python.am b/gnuscripts/lalsuite_python.am index 12fd92dc83..af87348e82 100644 --- a/gnuscripts/lalsuite_python.am +++ b/gnuscripts/lalsuite_python.am @@ -73,15 +73,15 @@ py-mostlyclean-local: $(pybin_scripts) $(noinst_pybin_scripts): Makefile .py: - $(AM_V_GEN)shebang='#!'; dummy_shebang='##(in place of shebang, for consistent line numbers)'; \ + $(AM_V_GEN)shebang='#!'; \ $(MKDIR_P) .libs || exit 1; \ rm -f $@ || exit 1; \ 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 $(srcdir)/$@.py`" != x; then \ - printf "\nERROR: $(srcdir)/$@.py must not contain a $${shebang} command line\n\n" >&2; \ + if test "x`$(SED) -n -e \"1{\|^##python$$|p;}\" $(srcdir)/$@.py`" = x; then \ + printf "\nERROR: $(srcdir)/$@.py must start with the line '##python' (which will be replaced with '$${shebang}$(LALSUITE_PYTHON_SYS_EXECUTABLE)' upon installation)\n\n" >&2; \ exit 1; \ fi; \ echo "$${shebang}/bin/sh" > .libs/$@.bin; \ @@ -90,40 +90,41 @@ $(pybin_scripts) $(noinst_pybin_scripts): Makefile echo "PYTHONPATH=\"$(abs_builddir):$(abs_srcdir):$(LAL_PYTHON_PATH):\$${PYTHONPATH}\"" | $(SED) 's|:::*|:|g' >> .libs/$@.bin; \ echo "export PYTHONPATH" >> .libs/$@.bin; \ echo "test -d '$(abs_builddir)/.libs' || mkdir '$(abs_builddir)/.libs' >/dev/null 2>&1" >> .libs/$@.bin; \ - echo "echo '$${dummy_shebang}' > '$(abs_builddir)/.libs/$@.py'" >> .libs/$@.bin; \ - echo "$(SED) -e 's|@LALSUITE_BINDIR@|$(abs_builddir)|g' '$(abs_srcdir)/$@.py' >> '$(abs_builddir)/.libs/$@.py' || exit 1" >> .libs/$@.bin; \ - echo "exec $(uninstalled_compiler) $(PYTHON) \$${PYBIN_SCRIPT_PY_FLAGS} '$(abs_builddir)/.libs/$@.py' \"\$$@\"" >> .libs/$@.bin; \ + echo "$(SED) -e 's|@LALSUITE_BINDIR@|$(abs_builddir)|g' '$(abs_srcdir)/$@.py' > '$(abs_builddir)/.libs/$@.py' || exit 1" >> .libs/$@.bin; \ + echo "exec $(uninstalled_compiler) $(LALSUITE_PYTHON_SYS_EXECUTABLE) \$${PYBIN_SCRIPT_PY_FLAGS} '$(abs_builddir)/.libs/$@.py' \"\$$@\"" >> .libs/$@.bin; \ echo "exit 1" >> .libs/$@.bin; \ chmod +x .libs/$@.bin || exit 1; \ mv -f .libs/$@.bin $@ pybin-install-exec-local: - $(AM_V_GEN)shebang='#!'; dummy_shebang='##(in place of shebang, for consistent line numbers)'; \ + $(AM_V_GEN)shebang='#!'; \ $(MKDIR_P) .libs || exit 1; \ if test "x$(pybin_scripts)" != x; then \ + relpkglibexecdir=`$(PYTHON) -c 'import os; print(os.path.relpath("$(pkglibexecdir)", "$(bindir)"))'`; \ pypath="$(pyexecdir)"; \ if test "$(pythondir)" != "$(pyexecdir)"; then \ pypath="$${pypath}:$(pythondir)"; \ fi; \ echo " $(MKDIR_P) '$(DESTDIR)$(bindir)'"; \ $(MKDIR_P) "$(DESTDIR)$(bindir)" || exit 1; \ - if test "x$(exec_prefix)" != "x$(PYTHON_EXEC_PREFIX)"; then \ + if test "x$(prefix)" != "x$(LALSUITE_PYTHON_SYS_PREFIX)"; then \ echo " $(MKDIR_P) '$(DESTDIR)$(pkglibexecdir)'"; \ $(MKDIR_P) "$(DESTDIR)$(pkglibexecdir)" || exit 1; \ fi; \ for file in $(pybin_scripts); do \ - if test "x$(exec_prefix)" = "x$(PYTHON_EXEC_PREFIX)"; then \ - echo "$${shebang}$(PYTHON)" > .libs/$${file}.bin; \ - $(SED) -e 's|@LALSUITE_BINDIR@|$(bindir)|g' "$(srcdir)/$${file}.py" >> .libs/$${file}.bin || exit 1; \ + if test "x$(prefix)" = "x$(LALSUITE_PYTHON_SYS_PREFIX)"; then \ + $(SED) -e "1{s|^##python$$|$${shebang}$(LALSUITE_PYTHON_SYS_EXECUTABLE)|;};s|@LALSUITE_BINDIR@|$(bindir)|g" "$(srcdir)/$${file}.py" > .libs/$${file}.bin || exit 1; \ else \ - echo "$${shebang}/bin/sh" > .libs/$${file}.bin; \ - echo "PYTHONPATH=\"$${pypath}:\$${PYTHONPATH}\"" >> .libs/$${file}.bin; \ - echo "export PYTHONPATH" >> .libs/$${file}.bin; \ - echo "exec $(PYTHON) '$(pkglibexecdir)/$${file}.py' \"\$$@\"" >> .libs/$${file}.bin; \ - echo "exit 1" >> .libs/$${file}.bin; \ + echo "$${shebang}$(LALSUITE_PYTHON_SYS_EXECUTABLE)" > .libs/$${file}.bin; \ + echo "import os, sys" >> .libs/$${file}.bin; \ + echo "if 'PYTHONPATH' in os.environ:" >> .libs/$${file}.bin; \ + echo " os.environ['PYTHONPATH'] = '$${pypath}:' + os.environ['PYTHONPATH']" >> .libs/$${file}.bin; \ + echo "else:" >> .libs/$${file}.bin; \ + echo " os.environ['PYTHONPATH'] = '$${pypath}'" >> .libs/$${file}.bin; \ + echo "os.execv(sys.executable, [sys.executable, os.path.join(os.path.dirname(__file__), '$${relpkglibexecdir}/$${file}.py')] + sys.argv[1:])" >> .libs/$${file}.bin; \ + echo "sys.exit(1)" >> .libs/$${file}.bin; \ $(MKDIR_P) "$(builddir)/.libs" || exit 1; \ - echo "$${dummy_shebang}" > "$(builddir)/.libs/$${file}.py"; \ - $(SED) -e 's|@LALSUITE_BINDIR@|$(bindir)|g' "$(srcdir)/$${file}.py" >> "$(builddir)/.libs/$${file}.py" || exit 1; \ + $(SED) -e 's|@LALSUITE_BINDIR@|$(bindir)|g' "$(srcdir)/$${file}.py" > "$(builddir)/.libs/$${file}.py" || exit 1; \ echo " $(INSTALL_DATA) $(builddir)/.libs/$${file}.py '$(DESTDIR)$(pkglibexecdir)/$${file}.py'"; \ $(INSTALL_DATA) "$(builddir)/.libs/$${file}.py" "$(DESTDIR)$(pkglibexecdir)/$${file}.py" || exit 1; \ fi; \ @@ -135,7 +136,7 @@ pybin-install-exec-local: pybin-uninstall-local: -for file in $(pybin_scripts); do \ rm -f "$(DESTDIR)$(bindir)/$${file}"; \ - if test "x$(exec_prefix)" != "x$(PYTHON_EXEC_PREFIX)"; then \ + if test "x$(prefix)" != "x$(LALSUITE_PYTHON_SYS_PREFIX)"; then \ rm -f "$(DESTDIR)$(pkglibexecdir)/$${file}.py"; \ fi; \ done From 270da7d0d1f54579ecac04fa4bd395604b86fa57 Mon Sep 17 00:00:00 2001 From: Karl Wette Date: Thu, 7 Nov 2024 21:37:56 +1100 Subject: [PATCH 2/6] SWIG: include NumPy flags first, so local installs override system installs --- gnuscripts/lalsuite_swig.m4 | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/gnuscripts/lalsuite_swig.m4 b/gnuscripts/lalsuite_swig.m4 index a5f389aaaf..4df0018b59 100644 --- a/gnuscripts/lalsuite_swig.m4 +++ b/gnuscripts/lalsuite_swig.m4 @@ -2,7 +2,7 @@ # lalsuite_swig.m4 - SWIG configuration # Author: Karl Wette, 2011--2017 # -# serial 121 +# serial 122 AC_DEFUN([_LALSUITE_MIN_SWIG_VERSION],[ # $0: minimum version of SWIG and other dependencies @@ -592,17 +592,19 @@ EOD`] # determine Python preprocessor flags AC_SUBST([SWIG_PYTHON_CPPFLAGS],["-ULAL_STRICT_DEFS_ENABLED"]) python_out=[`${PYTHON} - 2>/dev/null <= 3.11 import sysconfig - print('-I' + sysconfig.get_path('include'), end='') + print(' -I' + sysconfig.get_path('include'), end='') print(' -I' + sysconfig.get_path('platinclude'), end='') else: - print( '-I' + distutils.sysconfig.get_python_inc(), end='') + print(' -I' + distutils.sysconfig.get_python_inc(), end='') print(' -I' + distutils.sysconfig.get_python_inc(plat_specific=1), end='') -import numpy -print(' -I' + numpy.get_include(), end='') EOD`] AS_IF([test $? -ne 0],[ AC_MSG_ERROR([could not determine Python preprocessor flags]) From 0cec6fd4473a4961ea15eb302e6f5ca6f85aed12 Mon Sep 17 00:00:00 2001 From: Karl Wette Date: Thu, 7 Nov 2024 21:38:48 +1100 Subject: [PATCH 3/6] Add shebang placeholder to Python scripts --- lal/bin/lal_path2cache.py | 1 + lal/bin/lal_searchsum2cache.py | 1 + lalapps/src/power/lalapps_cafe.py | 1 + lalapps/src/power/lalapps_power_likelihood_pipe.py | 1 + lalapps/src/power/lalapps_power_pipe.py | 1 + lalapps/src/string/lalapps_cosmicstring_pipe.py | 1 + lalapps/src/string/lalapps_string_apply_vetoes.py | 1 + lalapps/src/string/lalapps_string_calc_likelihood.py | 1 + lalapps/src/string/lalapps_string_contour_plotter.py | 1 + lalapps/src/string/lalapps_string_contour_plotter_largeloops.py | 1 + lalapps/src/string/lalapps_string_cs_gamma.py | 1 + lalapps/src/string/lalapps_string_cs_gamma_largeloops.py | 1 + lalapps/src/string/lalapps_string_final.py | 1 + lalapps/src/string/lalapps_string_meas_likelihood.py | 1 + lalapps/src/string/lalapps_string_plot_binj.py | 1 + lalapps/src/string/lalapps_string_plot_likelihood.py | 1 + lalburst/bin/lalburst_cluster.py | 1 + lalburst/bin/lalburst_coinc.py | 1 + lalburst/bin/lalburst_cut.py | 1 + lalburst/bin/lalburst_gen_timeslides.py | 1 + lalburst/bin/lalburst_inj_pic.py | 1 + lalburst/bin/lalburst_injfind.py | 1 + lalburst/bin/lalburst_plot_tisi.py | 1 + lalburst/bin/lalburst_power_calc_likelihood.py | 1 + lalburst/bin/lalburst_power_final.py | 1 + lalburst/bin/lalburst_power_meas_likelihood.py | 1 + lalburst/bin/lalburst_power_plot_binj.py | 1 + lalburst/bin/lalburst_power_plot_binjtf.py | 1 + lalinference/bin/cbcBayesBurstPPAnalysis.py | 1 + lalinference/bin/cbcBayesBurstPostProc.py | 1 + lalinference/bin/cbcBayesCombinePTMCMCh5s.py | 1 + lalinference/bin/cbcBayesCombinePosteriors.py | 1 + lalinference/bin/cbcBayesCompPos.py | 1 + lalinference/bin/cbcBayesDIEvidence.py | 1 + lalinference/bin/cbcBayesGraceDBinfo.py | 1 + lalinference/bin/cbcBayesMCMC2pos.py | 1 + lalinference/bin/cbcBayesPPAnalysis.py | 1 + lalinference/bin/cbcBayesPlotSpinDisk.py | 1 + lalinference/bin/cbcBayesPosToSimBurst.py | 1 + lalinference/bin/cbcBayesPosToSimInspiral.py | 1 + lalinference/bin/cbcBayesPostProc.py | 1 + lalinference/bin/cbcBayesThermoInt.py | 1 + lalinference/bin/imrtgr_imr_consistency_test.py | 1 + lalinference/bin/lalinference_burst_pp_pipe.py | 1 + lalinference/bin/lalinference_coherence_test.py | 1 + lalinference/bin/lalinference_compute_roq_weights.py | 1 + lalinference/bin/lalinference_cpnest.py | 1 + lalinference/bin/lalinference_evolve_spins_and_append_samples.py | 1 + lalinference/bin/lalinference_merge_posteriors.py | 1 + lalinference/bin/lalinference_multi_pipe.py | 1 + lalinference/bin/lalinference_nest2pos.py | 1 + lalinference/bin/lalinference_pipe.py | 1 + lalinference/bin/lalinference_pp_pipe.py | 1 + lalinference/bin/lalinference_review_test.py | 1 + lalinspiral/bin/lalinspiral_injfind.py | 1 + lalinspiral/bin/lalinspiral_thinca.py | 1 + lalinspiral/test/python/thinca_brute_force_coinc.py | 1 + lalinspiral/test/python/thinca_compare_coinc_lists.py | 1 + lalpulsar/bin/HeterodyneSearch/lalpulsar_knope.py | 1 + .../bin/HeterodyneSearch/lalpulsar_knope_automation_script.py | 1 + .../bin/HeterodyneSearch/lalpulsar_knope_collate_results.py | 1 + lalpulsar/bin/HeterodyneSearch/lalpulsar_knope_result_page.py | 1 + lalpulsar/bin/MakeData/lalpulsar_CopyPublicSFTs.py | 1 + lalpulsar/bin/MakeData/lalpulsar_MakeSFTDAG.py | 1 + lalpulsar/bin/PiecewiseSearch/lalpulsar_PiecewiseSearch.py | 1 + .../bin/PiecewiseSearch/lalpulsar_PiecewiseSearchTemplateBank.py | 1 + 66 files changed, 66 insertions(+) diff --git a/lal/bin/lal_path2cache.py b/lal/bin/lal_path2cache.py index 859c6b1232..890a2760c0 100644 --- a/lal/bin/lal_path2cache.py +++ b/lal/bin/lal_path2cache.py @@ -1,3 +1,4 @@ +##python # # Copyright (C) 2006 Kipp Cannon # diff --git a/lal/bin/lal_searchsum2cache.py b/lal/bin/lal_searchsum2cache.py index 1fea4a1ff6..be05dc1e79 100644 --- a/lal/bin/lal_searchsum2cache.py +++ b/lal/bin/lal_searchsum2cache.py @@ -1,3 +1,4 @@ +##python # # Copyright (C) 2006 Kipp Cannon # diff --git a/lalapps/src/power/lalapps_cafe.py b/lalapps/src/power/lalapps_cafe.py index c26db1216f..34401c66cf 100644 --- a/lalapps/src/power/lalapps_cafe.py +++ b/lalapps/src/power/lalapps_cafe.py @@ -1,3 +1,4 @@ +##python # # Copyright (C) 2006 Kipp Cannon # diff --git a/lalapps/src/power/lalapps_power_likelihood_pipe.py b/lalapps/src/power/lalapps_power_likelihood_pipe.py index 9ea6c3b6fd..4eb5c760a5 100644 --- a/lalapps/src/power/lalapps_power_likelihood_pipe.py +++ b/lalapps/src/power/lalapps_power_likelihood_pipe.py @@ -1,3 +1,4 @@ +##python # # Copyright (C) 2007 Kipp C. Cannon # diff --git a/lalapps/src/power/lalapps_power_pipe.py b/lalapps/src/power/lalapps_power_pipe.py index 3eda32dc19..b4170bf2c3 100644 --- a/lalapps/src/power/lalapps_power_pipe.py +++ b/lalapps/src/power/lalapps_power_pipe.py @@ -1,3 +1,4 @@ +##python # # Copyright (C) 2005--2010,2013,2015,2016,2019 Kipp Cannon # Copyright (C) 2004--2006 Saikat Ray-Majumder diff --git a/lalapps/src/string/lalapps_cosmicstring_pipe.py b/lalapps/src/string/lalapps_cosmicstring_pipe.py index a4984c30cc..0190928a25 100644 --- a/lalapps/src/string/lalapps_cosmicstring_pipe.py +++ b/lalapps/src/string/lalapps_cosmicstring_pipe.py @@ -1,3 +1,4 @@ +##python # # ============================================================================= # diff --git a/lalapps/src/string/lalapps_string_apply_vetoes.py b/lalapps/src/string/lalapps_string_apply_vetoes.py index 3ec5885ca6..0d4ace358c 100644 --- a/lalapps/src/string/lalapps_string_apply_vetoes.py +++ b/lalapps/src/string/lalapps_string_apply_vetoes.py @@ -1,3 +1,4 @@ +##python # # Copyright (C) 2010 Kipp Cannon # diff --git a/lalapps/src/string/lalapps_string_calc_likelihood.py b/lalapps/src/string/lalapps_string_calc_likelihood.py index 4e6dd5da59..b584b031fc 100644 --- a/lalapps/src/string/lalapps_string_calc_likelihood.py +++ b/lalapps/src/string/lalapps_string_calc_likelihood.py @@ -1,3 +1,4 @@ +##python # # Copyright (C) 2010 Kipp Cannon # diff --git a/lalapps/src/string/lalapps_string_contour_plotter.py b/lalapps/src/string/lalapps_string_contour_plotter.py index 8abb135109..3848733588 100644 --- a/lalapps/src/string/lalapps_string_contour_plotter.py +++ b/lalapps/src/string/lalapps_string_contour_plotter.py @@ -1,3 +1,4 @@ +##python # # Copyright (C) 2010 Andrew Mergl # diff --git a/lalapps/src/string/lalapps_string_contour_plotter_largeloops.py b/lalapps/src/string/lalapps_string_contour_plotter_largeloops.py index 62942ad5f6..b347cffbab 100644 --- a/lalapps/src/string/lalapps_string_contour_plotter_largeloops.py +++ b/lalapps/src/string/lalapps_string_contour_plotter_largeloops.py @@ -1,3 +1,4 @@ +##python # # Copyright (C) 2018 Daichi Tsuna # diff --git a/lalapps/src/string/lalapps_string_cs_gamma.py b/lalapps/src/string/lalapps_string_cs_gamma.py index 72cad48d38..a1853624f5 100644 --- a/lalapps/src/string/lalapps_string_cs_gamma.py +++ b/lalapps/src/string/lalapps_string_cs_gamma.py @@ -1,3 +1,4 @@ +##python # # Copyright (C) 2007 Xavier Siemens # Copyright (C) 2010 Andrew Mergl diff --git a/lalapps/src/string/lalapps_string_cs_gamma_largeloops.py b/lalapps/src/string/lalapps_string_cs_gamma_largeloops.py index fe2b9cbd8a..a95604e251 100644 --- a/lalapps/src/string/lalapps_string_cs_gamma_largeloops.py +++ b/lalapps/src/string/lalapps_string_cs_gamma_largeloops.py @@ -1,3 +1,4 @@ +##python # # Copyright (C) 2007 Xavier Siemens # Copyright (C) 2018 Daichi Tsuna diff --git a/lalapps/src/string/lalapps_string_final.py b/lalapps/src/string/lalapps_string_final.py index 96e75033f7..345bb7a812 100644 --- a/lalapps/src/string/lalapps_string_final.py +++ b/lalapps/src/string/lalapps_string_final.py @@ -1,3 +1,4 @@ +##python # # Copyright (C) 2006--2010 Kipp Cannon # diff --git a/lalapps/src/string/lalapps_string_meas_likelihood.py b/lalapps/src/string/lalapps_string_meas_likelihood.py index c705c37d30..42eb5c4375 100644 --- a/lalapps/src/string/lalapps_string_meas_likelihood.py +++ b/lalapps/src/string/lalapps_string_meas_likelihood.py @@ -1,3 +1,4 @@ +##python # Copyright (C) 2010--2018 Kipp Cannon # # This program is free software; you can redistribute it and/or modify it diff --git a/lalapps/src/string/lalapps_string_plot_binj.py b/lalapps/src/string/lalapps_string_plot_binj.py index 606839a002..5c24c02be5 100644 --- a/lalapps/src/string/lalapps_string_plot_binj.py +++ b/lalapps/src/string/lalapps_string_plot_binj.py @@ -1,3 +1,4 @@ +##python # # Copyright (C) 2009 Kipp Cannon # diff --git a/lalapps/src/string/lalapps_string_plot_likelihood.py b/lalapps/src/string/lalapps_string_plot_likelihood.py index 74733a9eb9..17ad360f1c 100644 --- a/lalapps/src/string/lalapps_string_plot_likelihood.py +++ b/lalapps/src/string/lalapps_string_plot_likelihood.py @@ -1,3 +1,4 @@ +##python # # Copyright (C) 2009 Kipp Cannon # diff --git a/lalburst/bin/lalburst_cluster.py b/lalburst/bin/lalburst_cluster.py index 03638d8324..2f094be1a7 100644 --- a/lalburst/bin/lalburst_cluster.py +++ b/lalburst/bin/lalburst_cluster.py @@ -1,3 +1,4 @@ +##python # # Copyright (C) 2006,2012 Kipp Cannon # diff --git a/lalburst/bin/lalburst_coinc.py b/lalburst/bin/lalburst_coinc.py index eab9420dbe..730d65fca2 100644 --- a/lalburst/bin/lalburst_coinc.py +++ b/lalburst/bin/lalburst_coinc.py @@ -1,3 +1,4 @@ +##python # # Copyright (C) 2006--2017 Kipp Cannon # diff --git a/lalburst/bin/lalburst_cut.py b/lalburst/bin/lalburst_cut.py index d455657fd8..680ab26610 100644 --- a/lalburst/bin/lalburst_cut.py +++ b/lalburst/bin/lalburst_cut.py @@ -1,3 +1,4 @@ +##python # # Copyright (C) 2006,2013 Kipp Cannon # diff --git a/lalburst/bin/lalburst_gen_timeslides.py b/lalburst/bin/lalburst_gen_timeslides.py index 721fc9206a..d434f9aad6 100644 --- a/lalburst/bin/lalburst_gen_timeslides.py +++ b/lalburst/bin/lalburst_gen_timeslides.py @@ -1,3 +1,4 @@ +##python # # Copyright (C) 2006--2014 Kipp Cannon # diff --git a/lalburst/bin/lalburst_inj_pic.py b/lalburst/bin/lalburst_inj_pic.py index 81f336cf2b..1f1177d327 100644 --- a/lalburst/bin/lalburst_inj_pic.py +++ b/lalburst/bin/lalburst_inj_pic.py @@ -1,3 +1,4 @@ +##python # # Copyright (C) 2010,2013 Kipp Cannon # diff --git a/lalburst/bin/lalburst_injfind.py b/lalburst/bin/lalburst_injfind.py index 37302e523e..4f7ed33fab 100644 --- a/lalburst/bin/lalburst_injfind.py +++ b/lalburst/bin/lalburst_injfind.py @@ -1,3 +1,4 @@ +##python # # Copyright (C) 2006 Kipp Cannon # diff --git a/lalburst/bin/lalburst_plot_tisi.py b/lalburst/bin/lalburst_plot_tisi.py index c5a04a1c63..a8c6e0b4a3 100644 --- a/lalburst/bin/lalburst_plot_tisi.py +++ b/lalburst/bin/lalburst_plot_tisi.py @@ -1,3 +1,4 @@ +##python # # Copyright (C) 2006,2013 Kipp Cannon # diff --git a/lalburst/bin/lalburst_power_calc_likelihood.py b/lalburst/bin/lalburst_power_calc_likelihood.py index a2d460d29c..56664b1902 100644 --- a/lalburst/bin/lalburst_power_calc_likelihood.py +++ b/lalburst/bin/lalburst_power_calc_likelihood.py @@ -1,3 +1,4 @@ +##python # # Copyright (C) 2006--2010 Kipp Cannon # diff --git a/lalburst/bin/lalburst_power_final.py b/lalburst/bin/lalburst_power_final.py index 8a9e1503ed..e329c0b308 100644 --- a/lalburst/bin/lalburst_power_final.py +++ b/lalburst/bin/lalburst_power_final.py @@ -1,3 +1,4 @@ +##python # # Copyright (C) 2007 Kipp Cannon # diff --git a/lalburst/bin/lalburst_power_meas_likelihood.py b/lalburst/bin/lalburst_power_meas_likelihood.py index 1de2ed7ad0..2abc7130c3 100644 --- a/lalburst/bin/lalburst_power_meas_likelihood.py +++ b/lalburst/bin/lalburst_power_meas_likelihood.py @@ -1,3 +1,4 @@ +##python # # Copyright (C) 2007-2010 Kipp Cannon # diff --git a/lalburst/bin/lalburst_power_plot_binj.py b/lalburst/bin/lalburst_power_plot_binj.py index eebff6f560..680c6bceb8 100644 --- a/lalburst/bin/lalburst_power_plot_binj.py +++ b/lalburst/bin/lalburst_power_plot_binj.py @@ -1,3 +1,4 @@ +##python # # Copyright (C) 2006 Kipp Cannon # diff --git a/lalburst/bin/lalburst_power_plot_binjtf.py b/lalburst/bin/lalburst_power_plot_binjtf.py index 0e1a1e3f14..0b44d7a6d7 100644 --- a/lalburst/bin/lalburst_power_plot_binjtf.py +++ b/lalburst/bin/lalburst_power_plot_binjtf.py @@ -1,3 +1,4 @@ +##python # # Copyright (C) 2007 Kipp Cannon # diff --git a/lalinference/bin/cbcBayesBurstPPAnalysis.py b/lalinference/bin/cbcBayesBurstPPAnalysis.py index 7917b9907e..49f8e197e6 100644 --- a/lalinference/bin/cbcBayesBurstPPAnalysis.py +++ b/lalinference/bin/cbcBayesBurstPPAnalysis.py @@ -1,3 +1,4 @@ +##python # -*- coding: utf-8 -*- # # cbcBayesPostProc.py diff --git a/lalinference/bin/cbcBayesBurstPostProc.py b/lalinference/bin/cbcBayesBurstPostProc.py index 250b6bde3e..4640a6cf5a 100644 --- a/lalinference/bin/cbcBayesBurstPostProc.py +++ b/lalinference/bin/cbcBayesBurstPostProc.py @@ -1,3 +1,4 @@ +##python # -*- coding: utf-8 -*- # # cbcBayesBurstPostProc.py diff --git a/lalinference/bin/cbcBayesCombinePTMCMCh5s.py b/lalinference/bin/cbcBayesCombinePTMCMCh5s.py index c32d512617..8a825728ea 100644 --- a/lalinference/bin/cbcBayesCombinePTMCMCh5s.py +++ b/lalinference/bin/cbcBayesCombinePTMCMCh5s.py @@ -1,3 +1,4 @@ +##python # -*- coding: utf-8 -*- # # cbcBayesCombinePTMCMCh5s.py diff --git a/lalinference/bin/cbcBayesCombinePosteriors.py b/lalinference/bin/cbcBayesCombinePosteriors.py index ef8f98623c..6227b2dc2d 100644 --- a/lalinference/bin/cbcBayesCombinePosteriors.py +++ b/lalinference/bin/cbcBayesCombinePosteriors.py @@ -1,3 +1,4 @@ +##python # -*- coding: utf-8 -*- # cbcBayesCombinePosteriors.py # diff --git a/lalinference/bin/cbcBayesCompPos.py b/lalinference/bin/cbcBayesCompPos.py index 8d15712c94..4968afbe89 100644 --- a/lalinference/bin/cbcBayesCompPos.py +++ b/lalinference/bin/cbcBayesCompPos.py @@ -1,3 +1,4 @@ +##python # -*- coding: utf-8 -*- # # cbcBayesCompPos.py Copyright 2010--2012 Benjamin Aylott diff --git a/lalinference/bin/cbcBayesDIEvidence.py b/lalinference/bin/cbcBayesDIEvidence.py index f23ef22b82..d554595a46 100644 --- a/lalinference/bin/cbcBayesDIEvidence.py +++ b/lalinference/bin/cbcBayesDIEvidence.py @@ -1,3 +1,4 @@ +##python # -*- coding: utf-8 -*- # # cbcBayesDIEvidence.py: compute the direct-integration evidence diff --git a/lalinference/bin/cbcBayesGraceDBinfo.py b/lalinference/bin/cbcBayesGraceDBinfo.py index c7f6621f37..30832b2955 100644 --- a/lalinference/bin/cbcBayesGraceDBinfo.py +++ b/lalinference/bin/cbcBayesGraceDBinfo.py @@ -1,3 +1,4 @@ +##python # -*- coding: utf-8 -*- # # cbcBayesGraceDBinfo diff --git a/lalinference/bin/cbcBayesMCMC2pos.py b/lalinference/bin/cbcBayesMCMC2pos.py index 0cc9c69e3b..1d9d581c69 100644 --- a/lalinference/bin/cbcBayesMCMC2pos.py +++ b/lalinference/bin/cbcBayesMCMC2pos.py @@ -1,3 +1,4 @@ +##python # -*- coding: utf-8 -*- # # cbcBayesMCMC2pos.py diff --git a/lalinference/bin/cbcBayesPPAnalysis.py b/lalinference/bin/cbcBayesPPAnalysis.py index 3f98d9c270..dd4b7e0b85 100644 --- a/lalinference/bin/cbcBayesPPAnalysis.py +++ b/lalinference/bin/cbcBayesPPAnalysis.py @@ -1,3 +1,4 @@ +##python # -*- coding: utf-8 -*- # # cbcBayesPPAnalysis.py diff --git a/lalinference/bin/cbcBayesPlotSpinDisk.py b/lalinference/bin/cbcBayesPlotSpinDisk.py index eb024d8508..d70ab62316 100644 --- a/lalinference/bin/cbcBayesPlotSpinDisk.py +++ b/lalinference/bin/cbcBayesPlotSpinDisk.py @@ -1,3 +1,4 @@ +##python # Ben Farr 2016 import os diff --git a/lalinference/bin/cbcBayesPosToSimBurst.py b/lalinference/bin/cbcBayesPosToSimBurst.py index e724a3320d..22955f22e3 100644 --- a/lalinference/bin/cbcBayesPosToSimBurst.py +++ b/lalinference/bin/cbcBayesPosToSimBurst.py @@ -1,3 +1,4 @@ +##python # -*- coding: utf-8 -*- # cbcBayesPosToSimBurst.py # C2014 Salvatore Vitale diff --git a/lalinference/bin/cbcBayesPosToSimInspiral.py b/lalinference/bin/cbcBayesPosToSimInspiral.py index fab1e7fb6f..d2111f38db 100644 --- a/lalinference/bin/cbcBayesPosToSimInspiral.py +++ b/lalinference/bin/cbcBayesPosToSimInspiral.py @@ -1,3 +1,4 @@ +##python # -*- coding: utf-8 -*- # # cbcBayesPosToSimInspiral.py diff --git a/lalinference/bin/cbcBayesPostProc.py b/lalinference/bin/cbcBayesPostProc.py index 0c04061ba4..e078ff085f 100644 --- a/lalinference/bin/cbcBayesPostProc.py +++ b/lalinference/bin/cbcBayesPostProc.py @@ -1,3 +1,4 @@ +##python # -*- coding: utf-8 -*- # # cbcBayesPostProc.py diff --git a/lalinference/bin/cbcBayesThermoInt.py b/lalinference/bin/cbcBayesThermoInt.py index 24a816b276..c739f61684 100644 --- a/lalinference/bin/cbcBayesThermoInt.py +++ b/lalinference/bin/cbcBayesThermoInt.py @@ -1,3 +1,4 @@ +##python from optparse import OptionParser import sys diff --git a/lalinference/bin/imrtgr_imr_consistency_test.py b/lalinference/bin/imrtgr_imr_consistency_test.py index 57cc0910c3..d885c78d90 100644 --- a/lalinference/bin/imrtgr_imr_consistency_test.py +++ b/lalinference/bin/imrtgr_imr_consistency_test.py @@ -1,3 +1,4 @@ +##python """ Perform the consistency check between the inspiral and ringdown estimates of the mass and spin of the final black hole in a binary black hole merger. diff --git a/lalinference/bin/lalinference_burst_pp_pipe.py b/lalinference/bin/lalinference_burst_pp_pipe.py index af71627644..aebfcc5970 100644 --- a/lalinference/bin/lalinference_burst_pp_pipe.py +++ b/lalinference/bin/lalinference_burst_pp_pipe.py @@ -1,3 +1,4 @@ +##python # End-to-end LALInference test pipeline # (C) 2014 John Veitch diff --git a/lalinference/bin/lalinference_coherence_test.py b/lalinference/bin/lalinference_coherence_test.py index 381f240a3d..af1ad76d56 100644 --- a/lalinference/bin/lalinference_coherence_test.py +++ b/lalinference/bin/lalinference_coherence_test.py @@ -1,3 +1,4 @@ +##python ''' This program simply computes the bayes factor between the coherent and incoherent models given as input the B files for the run. diff --git a/lalinference/bin/lalinference_compute_roq_weights.py b/lalinference/bin/lalinference_compute_roq_weights.py index 9b351ecd66..e23c9c44de 100644 --- a/lalinference/bin/lalinference_compute_roq_weights.py +++ b/lalinference/bin/lalinference_compute_roq_weights.py @@ -1,3 +1,4 @@ +##python import numpy as np from math import ceil from optparse import OptionParser diff --git a/lalinference/bin/lalinference_cpnest.py b/lalinference/bin/lalinference_cpnest.py index 9c1dac4130..9a1f939374 100644 --- a/lalinference/bin/lalinference_cpnest.py +++ b/lalinference/bin/lalinference_cpnest.py @@ -1,3 +1,4 @@ +##python import sys import argparse from lalinference.wrapper import LALInferenceCBCWrapper diff --git a/lalinference/bin/lalinference_evolve_spins_and_append_samples.py b/lalinference/bin/lalinference_evolve_spins_and_append_samples.py index 1c3d1b4016..a4ef3c8e27 100644 --- a/lalinference/bin/lalinference_evolve_spins_and_append_samples.py +++ b/lalinference/bin/lalinference_evolve_spins_and_append_samples.py @@ -1,3 +1,4 @@ +##python ''' Code to read in LALInference HDF5 posterior samples, evolve the spins up to a specified value (default: Schwarzschild ISCO), and write the resulting evolved spin samples to the HDF5 file. diff --git a/lalinference/bin/lalinference_merge_posteriors.py b/lalinference/bin/lalinference_merge_posteriors.py index 573d6067c0..936f0fdd64 100644 --- a/lalinference/bin/lalinference_merge_posteriors.py +++ b/lalinference/bin/lalinference_merge_posteriors.py @@ -1,3 +1,4 @@ +##python # resample posteriors (C) John Veitch, 2015 diff --git a/lalinference/bin/lalinference_multi_pipe.py b/lalinference/bin/lalinference_multi_pipe.py index 618fc74ce6..9453e67937 100644 --- a/lalinference/bin/lalinference_multi_pipe.py +++ b/lalinference/bin/lalinference_multi_pipe.py @@ -1,3 +1,4 @@ +##python # DAG generation code for running LALInference pipeline # (C) 2012 John Veitch # 2013 Salvatore Vitale: extended to work with several ini files diff --git a/lalinference/bin/lalinference_nest2pos.py b/lalinference/bin/lalinference_nest2pos.py index 45735f2498..2a8ccdf438 100644 --- a/lalinference/bin/lalinference_nest2pos.py +++ b/lalinference/bin/lalinference_nest2pos.py @@ -1,3 +1,4 @@ +##python from numpy import loadtxt, logaddexp, log, mean from optparse import OptionParser import gzip diff --git a/lalinference/bin/lalinference_pipe.py b/lalinference/bin/lalinference_pipe.py index 5935d67b92..20371e440c 100644 --- a/lalinference/bin/lalinference_pipe.py +++ b/lalinference/bin/lalinference_pipe.py @@ -1,3 +1,4 @@ +##python # DAG generation code for running LALInference pipeline # (C) 2012 John Veitch, Vivien Raymond diff --git a/lalinference/bin/lalinference_pp_pipe.py b/lalinference/bin/lalinference_pp_pipe.py index 4bd98c4182..fb2f41c7be 100644 --- a/lalinference/bin/lalinference_pp_pipe.py +++ b/lalinference/bin/lalinference_pp_pipe.py @@ -1,3 +1,4 @@ +##python # End-to-end LALInference test pipeline # (C) 2014 John Veitch diff --git a/lalinference/bin/lalinference_review_test.py b/lalinference/bin/lalinference_review_test.py index f98ba0b8fd..02180e7cdc 100644 --- a/lalinference/bin/lalinference_review_test.py +++ b/lalinference/bin/lalinference_review_test.py @@ -1,3 +1,4 @@ +##python import argparse import shutil import os diff --git a/lalinspiral/bin/lalinspiral_injfind.py b/lalinspiral/bin/lalinspiral_injfind.py index 71c465ea4f..07a0aa9fc4 100644 --- a/lalinspiral/bin/lalinspiral_injfind.py +++ b/lalinspiral/bin/lalinspiral_injfind.py @@ -1,3 +1,4 @@ +##python # # Copyright (C) 2006--2009,2013,2014,2016,2017 Kipp Cannon # diff --git a/lalinspiral/bin/lalinspiral_thinca.py b/lalinspiral/bin/lalinspiral_thinca.py index c60ddd0ca1..6411f94c2e 100644 --- a/lalinspiral/bin/lalinspiral_thinca.py +++ b/lalinspiral/bin/lalinspiral_thinca.py @@ -1,3 +1,4 @@ +##python # # Copyright (C) 2008--2017 Kipp Cannon # diff --git a/lalinspiral/test/python/thinca_brute_force_coinc.py b/lalinspiral/test/python/thinca_brute_force_coinc.py index 3bb3790d02..e61ad1b948 100644 --- a/lalinspiral/test/python/thinca_brute_force_coinc.py +++ b/lalinspiral/test/python/thinca_brute_force_coinc.py @@ -1,3 +1,4 @@ +##python import itertools from optparse import OptionParser import sys diff --git a/lalinspiral/test/python/thinca_compare_coinc_lists.py b/lalinspiral/test/python/thinca_compare_coinc_lists.py index 878be88077..3763b10eca 100644 --- a/lalinspiral/test/python/thinca_compare_coinc_lists.py +++ b/lalinspiral/test/python/thinca_compare_coinc_lists.py @@ -1,3 +1,4 @@ +##python import itertools from optparse import OptionParser import sys diff --git a/lalpulsar/bin/HeterodyneSearch/lalpulsar_knope.py b/lalpulsar/bin/HeterodyneSearch/lalpulsar_knope.py index 699d77efea..3c956d2b88 100644 --- a/lalpulsar/bin/HeterodyneSearch/lalpulsar_knope.py +++ b/lalpulsar/bin/HeterodyneSearch/lalpulsar_knope.py @@ -1,3 +1,4 @@ +##python # -*- coding: utf-8 -*- # # lalpulsar_knope.py diff --git a/lalpulsar/bin/HeterodyneSearch/lalpulsar_knope_automation_script.py b/lalpulsar/bin/HeterodyneSearch/lalpulsar_knope_automation_script.py index 818099075c..1da1c8358a 100644 --- a/lalpulsar/bin/HeterodyneSearch/lalpulsar_knope_automation_script.py +++ b/lalpulsar/bin/HeterodyneSearch/lalpulsar_knope_automation_script.py @@ -1,3 +1,4 @@ +##python ## \file ## \ingroup lalpulsar_bin_HeterodyneSearch """ diff --git a/lalpulsar/bin/HeterodyneSearch/lalpulsar_knope_collate_results.py b/lalpulsar/bin/HeterodyneSearch/lalpulsar_knope_collate_results.py index 985dc23719..d00923a326 100644 --- a/lalpulsar/bin/HeterodyneSearch/lalpulsar_knope_collate_results.py +++ b/lalpulsar/bin/HeterodyneSearch/lalpulsar_knope_collate_results.py @@ -1,3 +1,4 @@ +##python # -*- coding: utf-8 -*- # # lalpulsar_knope_collate_results.py diff --git a/lalpulsar/bin/HeterodyneSearch/lalpulsar_knope_result_page.py b/lalpulsar/bin/HeterodyneSearch/lalpulsar_knope_result_page.py index cc45e39c26..402356c4ab 100644 --- a/lalpulsar/bin/HeterodyneSearch/lalpulsar_knope_result_page.py +++ b/lalpulsar/bin/HeterodyneSearch/lalpulsar_knope_result_page.py @@ -1,3 +1,4 @@ +##python # -*- coding: utf-8 -*- # # lalpulsar_knope_result_page.py diff --git a/lalpulsar/bin/MakeData/lalpulsar_CopyPublicSFTs.py b/lalpulsar/bin/MakeData/lalpulsar_CopyPublicSFTs.py index 76a3521bfb..bbf442e36c 100644 --- a/lalpulsar/bin/MakeData/lalpulsar_CopyPublicSFTs.py +++ b/lalpulsar/bin/MakeData/lalpulsar_CopyPublicSFTs.py @@ -1,3 +1,4 @@ +##python # Copyright (C) 2022 Karl Wette # # This program is free software; you can redistribute it and/or modify diff --git a/lalpulsar/bin/MakeData/lalpulsar_MakeSFTDAG.py b/lalpulsar/bin/MakeData/lalpulsar_MakeSFTDAG.py index d4f6d6ca77..05eb69cfed 100644 --- a/lalpulsar/bin/MakeData/lalpulsar_MakeSFTDAG.py +++ b/lalpulsar/bin/MakeData/lalpulsar_MakeSFTDAG.py @@ -1,3 +1,4 @@ +##python # Copyright (C) 2013, 2014, 2020--2024 Evan Goetz # Copyright (C) 2011, 2021, 2022 Karl Wette # Copyright (C) 2005, 2007 Gregory Mendell diff --git a/lalpulsar/bin/PiecewiseSearch/lalpulsar_PiecewiseSearch.py b/lalpulsar/bin/PiecewiseSearch/lalpulsar_PiecewiseSearch.py index 027c8f5f84..fed55c186a 100644 --- a/lalpulsar/bin/PiecewiseSearch/lalpulsar_PiecewiseSearch.py +++ b/lalpulsar/bin/PiecewiseSearch/lalpulsar_PiecewiseSearch.py @@ -1,3 +1,4 @@ +##python # Copyright (C) 2019--2023 Benjamin Grace # # This program is free software; you can redistribute it and/or modify it diff --git a/lalpulsar/bin/PiecewiseSearch/lalpulsar_PiecewiseSearchTemplateBank.py b/lalpulsar/bin/PiecewiseSearch/lalpulsar_PiecewiseSearchTemplateBank.py index 4ada16fdf8..cc96e2c0bd 100644 --- a/lalpulsar/bin/PiecewiseSearch/lalpulsar_PiecewiseSearchTemplateBank.py +++ b/lalpulsar/bin/PiecewiseSearch/lalpulsar_PiecewiseSearchTemplateBank.py @@ -1,3 +1,4 @@ +##python # Copyright (C) 2019--2023 Benjamin Grace # # This program is free software; you can redistribute it and/or modify it From f73484ecc715f38aa83fa7003c7a2623087c6f0b Mon Sep 17 00:00:00 2001 From: Karl Wette Date: Thu, 7 Nov 2024 21:39:17 +1100 Subject: [PATCH 4/6] Test installation of Python (wrapper) scripts --- lal/bin/Makefile.am | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lal/bin/Makefile.am b/lal/bin/Makefile.am index 8d0b1c76e4..a0eb4895ab 100644 --- a/lal/bin/Makefile.am +++ b/lal/bin/Makefile.am @@ -62,6 +62,9 @@ pybin_scripts = \ # Add shell, Python, etc. test scripts to this variable test_scripts += test_path2cache.sh +installcheck-local: + $(bindir)/lal_path2cache --help + endif # -- Manuals ---------------- From 3da62b2a7e65a618251e73946d85d4cdd1e6cc32 Mon Sep 17 00:00:00 2001 From: Karl Wette Date: Fri, 8 Nov 2024 23:55:34 +1100 Subject: [PATCH 5/6] Revert "wheel: fix bundling of Python scripts in wheels" This reverts commit d5682e25ebbd4c6231aeb587950ff62733dd1476. --- wheel/setup.py.in | 39 ++------------------------------------- 1 file changed, 2 insertions(+), 37 deletions(-) diff --git a/wheel/setup.py.in b/wheel/setup.py.in index 40939d418f..3a7661ce1b 100644 --- a/wheel/setup.py.in +++ b/wheel/setup.py.in @@ -67,20 +67,6 @@ else: SHLIB_SUFFIX = sysconfig.get_config_var("SHLIB_SUFFIX") -# magic bytes to identify compiled executables -MAGIC_BYTES_EXE = set(map(bytes.fromhex, ( - # linux - "7F 45 4C 46", # ELF - # macOS (note that this doesn't distinguish between executables and - # libraries, let's just hope that we don't get mixed up...) - "FE ED FA CE", # Mach-O 32-bit (big-endian) - "FE ED FA CF", # Mach-O 64-bit (big-endian) - "CE FA ED FE", # Mach-O 32-bit (little-endian) - "CF FA ED FE", # Mach-O 64-bit (little-endian) - "CA FE BA BE", # Mach-O fat (big-endian) - "BE BA FE CA", # Mach-O fat (little-endian) -))) - class build_ext(_build_ext): """Override setuptools build_ext: just copy pre-built modules. @@ -101,25 +87,6 @@ with as_file(files('lalapps') / 'bin' / '{}') as path: """ -def _exe_type(path): - """Determine what type of executable this is. - - Returns one of - - - "exe" : for compiled executables - - "python" : for python scripts - - "other" : for anything that isn't one of the above - """ - with open(path, "rb") as file: - magic = file.read(4) - if magic in MAGIC_BYTES_EXE: - return "exe" - head = magic + file.readline() - if b"#!" in head and b"python" in head: - return "python" - return "other" - - class build_scripts(_build_scripts): """Override setuptools install_scripts: strip the .py extensions and add the shebang lines. @@ -131,18 +98,16 @@ class build_scripts(_build_scripts): with tempfile.TemporaryDirectory(dir=self.build_dir) as tmpdir: tmpdir = Path(tmpdir) for old_script in map(Path, old_scripts): - ftype = _exe_type(old_script) basename = old_script.name base = old_script.with_suffix("").name - if ftype == "exe": + if LIBEXECDIR not in old_script.parents: # C executable new_script = tmpdir / basename new_script.write_text(stub.format(basename)) - elif ftype == "python": + elif old_script.suffix == '.py': # Python script new_script = tmpdir / base with open(new_script, 'wb') as outfile: outfile.write(b'#!python\n') with open(old_script, 'rb') as infile: - infile.readline() # dump current shebang shutil.copyfileobj(infile, outfile) else: new_script = old_script From 73ce06167d651c0b279213f0cac76b47aa3ca177 Mon Sep 17 00:00:00 2001 From: Karl Wette Date: Wed, 13 Nov 2024 13:57:50 +1100 Subject: [PATCH 6/6] wheel/: prevent Python script wrapper generation in gnuscripts/lalsuite_python.am --- wheel/Makefile.am | 14 ++++++++++++- wheel/setup.py.in | 50 ++++++++++++++++++++++++++++------------------- 2 files changed, 43 insertions(+), 21 deletions(-) diff --git a/wheel/Makefile.am b/wheel/Makefile.am index 4f99c57bbb..f1db2f0f77 100644 --- a/wheel/Makefile.am +++ b/wheel/Makefile.am @@ -2,8 +2,20 @@ # beforehand, you may need to run `make clean` for the wheel to build # successfully. +# NOTE: setting LALSUITE_PYTHON_SYS_PREFIX is required to install Python scripts +# directly into ${prefix}/bin without wrapper scripts; see the +# pybin-install-exec-local rule in gnuscripts/lalsuite_python.am. + wheel: setup.py - $(MAKE) prefix=$(abs_builddir)/build/inst PYTHON_PREFIX=$(abs_builddir)/build/inst PYTHON_EXEC_PREFIX=$(abs_builddir)/build/inst pkgdatadir=$(abs_builddir)/build/inst/share -C .. install-strip && \ + prefix="$(abs_builddir)/build/inst"; \ + $(MAKE) \ + prefix="$${prefix}" \ + pkgdatadir="$${prefix}/share" \ + PYTHON_PREFIX="$${prefix}" \ + PYTHON_EXEC_PREFIX="$${prefix}" \ + LALSUITE_PYTHON_SYS_PREFIX="$${prefix}" \ + -C .. install-strip \ + && \ $(PYTHON) setup.py bdist_wheel -d . clean-local: diff --git a/wheel/setup.py.in b/wheel/setup.py.in index 3a7661ce1b..16ab861e9f 100644 --- a/wheel/setup.py.in +++ b/wheel/setup.py.in @@ -47,6 +47,17 @@ from setuptools import ( ) from setuptools.command.build_ext import build_ext as _build_ext + +def is_py_script(script): + with open(script, 'rb') as scriptfile: + shebang = scriptfile.read(2) + if shebang == b"#!": + shebang_line = scriptfile.readline() + if b"python" in shebang_line: + return True + return False + + # These variables come from automake. subst = {} subst['prefix'] = subst['PYTHON_PREFIX'] = subst['PYTHON_EXEC_PREFIX'] = ( @@ -55,7 +66,6 @@ subst['prefix'] = subst['PYTHON_PREFIX'] = subst['PYTHON_EXEC_PREFIX'] = ( subst['exec_prefix'] = Template('@exec_prefix@').substitute(**subst) BINDIR = Path(Template('@bindir@').substitute(**subst)) DATADIR = Path(Template('$prefix/share').substitute(**subst)) -LIBEXECDIR = Path(Template('@libexecdir@').substitute(**subst)) PYTHONDIR = Path(Template('@pythondir@').substitute(**subst)) BASE_VERSION = '@BASE_VERSION@' NIGHTLY_VERSION = '@NIGHTLY_VERSION@' @@ -67,9 +77,13 @@ else: SHLIB_SUFFIX = sysconfig.get_config_var("SHLIB_SUFFIX") +SCRIPTS = list(BINDIR.glob("*")) + class build_ext(_build_ext): - """Override setuptools build_ext: just copy pre-built modules. + """Override setuptools build_ext. + + Just copy pre-built modules. """ def build_extension(self, ext): src = PYTHONDIR / (ext.name.replace('.', os.path.sep) + SHLIB_SUFFIX) @@ -88,8 +102,14 @@ with as_file(files('lalapps') / 'bin' / '{}') as path: class build_scripts(_build_scripts): - """Override setuptools install_scripts: strip the .py extensions and - add the shebang lines. + """Override setuptools install_scripts. + + Python scripts (with a '#!...python' shebang line) are installed directly. + (The shebang will be replaced by the correct Python path upon installation.) + + For non-Python scripts (including C executables), a stub is generated which + executes the real script, which is packaged under 'lib/.../lalapps/bin'. + """ def run(self): old_scripts = self.scripts[:] @@ -98,19 +118,12 @@ class build_scripts(_build_scripts): with tempfile.TemporaryDirectory(dir=self.build_dir) as tmpdir: tmpdir = Path(tmpdir) for old_script in map(Path, old_scripts): - basename = old_script.name - base = old_script.with_suffix("").name - if LIBEXECDIR not in old_script.parents: # C executable + if is_py_script(old_script): + new_script = old_script + else: + basename = old_script.name new_script = tmpdir / basename new_script.write_text(stub.format(basename)) - elif old_script.suffix == '.py': # Python script - new_script = tmpdir / base - with open(new_script, 'wb') as outfile: - outfile.write(b'#!python\n') - with open(old_script, 'rb') as infile: - shutil.copyfileobj(infile, outfile) - else: - new_script = old_script new_scripts.add(new_script) self.scripts = list(new_scripts) _build_scripts.run(self) @@ -164,7 +177,7 @@ setup( 'lalapps.data': str(DATADIR), }, package_data={ - 'lalapps.bin': ['*'], + 'lalapps.bin': [script.name for script in SCRIPTS if not is_py_script(script)], 'lalapps.data': ['*'], '': ['*.csv'], }, @@ -172,10 +185,7 @@ setup( 'lalapps.bin', 'lalapps.data', ], - scripts=list(map(str, ( - list(BINDIR.glob("*")) - + list(LIBEXECDIR.glob('**/*.py')) - ))), + scripts=list(map(str, SCRIPTS)), ext_modules=[ Extension( str(path.relative_to(PYTHONDIR).with_suffix("")).replace('/', '.'),