]> granicus.if.org Git - zfs/commitdiff
Canonicalize Python shebangs
authorRyan Moeller <ryan@freqlabs.com>
Thu, 12 Sep 2019 20:32:32 +0000 (16:32 -0400)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Thu, 12 Sep 2019 20:32:32 +0000 (13:32 -0700)
/usr/bin/env python3 is the suggested[1] shebang for Python in general
(likewise for python2) and is conventional across platforms. This eases
development on systems where python is not installed in /usr/bin
(FreeBSD for example) and makes it possible to develop in virtual
environments (venv) for isolating dependencies.

Many packaging guidelines discourage the use of /usr/bin/env, but since
this is the canonical way of writing shebangs in the Python community,
many packaging scripts are already equipped to handle substituting the
appropriate absolute path to python automatically.

Some RPM package builders lacking brp-mangle-shebangs need a small
fallback mechanism in the package spec to stamp the appropriate shebang
on installed Python scripts.

[1]: https://docs.python.org/3/using/unix.html?#miscellaneous

Reviewed-by: Richard Laager <rlaager@wiktel.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: George Melikov <mail@gmelikov.ru>
Signed-off-by: Ryan Moeller <ryan@ixsystems.com>
Closes #9314

cmd/arc_summary/arc_summary2
cmd/arc_summary/arc_summary3
cmd/arcstat/Makefile.am
cmd/arcstat/arcstat
cmd/dbufstat/Makefile.am
cmd/dbufstat/dbufstat
rpm/generic/zfs.spec.in
tests/test-runner/bin/Makefile.am
tests/test-runner/bin/test-runner.py
tests/test-runner/bin/zts-report.py

index 734fb708b960561d7572df5c582dd1c552e9423e..2946ee1957bffc5d352a8df17eaea4442714fd56 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/python2
+#!/usr/bin/env python2
 #
 # $Id: arc_summary.pl,v 388:e27800740aa2 2011-07-08 02:53:29Z jhell $
 #
index ebdf83218a7ddeec1e3e9cf8a1e25a766058f364..a32b2caeed6b586f48fe159863d5dca08fe1203b 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/env python3
 #
 # Copyright (c) 2008 Ben Rockwood <benr@cuddletech.com>,
 # Copyright (c) 2010 Martin Matuska <mm@FreeBSD.org>,
index 2d59faa9c87d4a2546188c2fa7c94ed513877651..8166778a13e37c7ceb5038489aa5e44af5f96a2a 100644 (file)
@@ -8,6 +8,6 @@ dist_bin_SCRIPTS = arcstat
 #
 if USING_PYTHON_2
 install-exec-hook:
-       sed --in-place 's|^#!/usr/bin/python3|#!/usr/bin/python2|' \
+       sed --in-place 's|^#!/usr/bin/env python3|#!/usr/bin/env python2|' \
            $(DESTDIR)$(bindir)/arcstat
 endif
index 57a2d621f34a6612ece04df0344fb33e28c581ba..003499928f32ce87b63a3ad2aac6abb8aed6c0aa 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/env python3
 #
 # Print out ZFS ARC Statistics exported via kstat(1)
 # For a definition of fields, or usage, use arctstat.pl -v
index 06923d38b2e8430ccdb10239e0c358ca9ed028e8..a3f0c6e50d734601b574022e8481cc5b0af0a477 100644 (file)
@@ -8,6 +8,6 @@ dist_bin_SCRIPTS = dbufstat
 #
 if USING_PYTHON_2
 install-exec-hook:
-       sed --in-place 's|^#!/usr/bin/python3|#!/usr/bin/python2|' \
+       sed --in-place 's|^#!/usr/bin/env python3|#!/usr/bin/env python2|' \
            $(DESTDIR)$(bindir)/dbufstat
 endif
index e6c947fbcbdba655e75227c47152dbe5efe70368..4a57d811301f80510f8a99b54dee6fb80c2c8769 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/env python3
 #
 # Print out statistics for all cached dmu buffers.  This information
 # is available through the dbufs kstat and may be post-processed as
index 5ef6f7bcfa3952e710310ab863b01d02826858d3..545627d4bfba94c99d16ba7efced4501de2a67bd 100644 (file)
 %bcond_with    asan
 %bcond_with    systemd
 
-# Exclude test-runner.py from the rpmbuild shebang check to allow it to run
-# under Python 2 and 3.
-%global __brp_mangle_shebangs_exclude_from test-runner.py
-
 # Generic enable switch for systemd
 %if %{with systemd}
 %define _systemd 1
@@ -354,6 +350,14 @@ make %{?_smp_mflags}
 %{__rm} -rf $RPM_BUILD_ROOT
 make install DESTDIR=%{?buildroot}
 find %{?buildroot}%{_libdir} -name '*.la' -exec rm -f {} \;
+%if 0%{!?__brp_mangle_shebangs:1}
+find %{?buildroot}%{_bindir} \
+    \( -name arc_summary -or -name arcstat -or -name dbufstat \) \
+    -exec %{__sed} -i 's|^#!.*|#!%{__python}|' {} \;
+find %{?buildroot}%{_datadir} \
+    \( -name test-runner.py -or -name zts-report.py \) \
+    -exec %{__sed} -i 's|^#!.*|#!%{__python}|' {} \;
+%endif
 
 %post
 %if 0%{?_systemd}
index e1ae21548e987293f3fe67c4367ce6d97d759733..2c031f7455039b7d2f3dbff437322f4dd2e78558 100644 (file)
@@ -9,7 +9,7 @@ dist_pkgdata_SCRIPTS = \
 #
 if USING_PYTHON_2
 install-data-hook:
-       sed --in-place 's|^#!/usr/bin/python3|#!/usr/bin/python2|' \
+       sed --in-place 's|^#!/usr/bin/env python3|#!/usr/bin/env python2|' \
            $(DESTDIR)$(pkgdatadir)/test-runner.py \
            $(DESTDIR)$(pkgdatadir)/zts-report.py
 endif
index bf2c77c18a9355f8b491e5299b407ef253728776..ca08b3754115a1cceb44d58b56080d166111bef5 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/env python3
 
 #
 # This file and its contents are supplied under the terms of the
index b6f3cf22ca1e9a5825aa20d10706df03da417f49..65233c41b938f56bb6d6cd5b3126a7d4f0170a88 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/env python3
 
 #
 # This file and its contents are supplied under the terms of the