D9273: global: use python3 in shebangs

indygreg (Gregory Szorc) phabricator at mercurial-scm.org
Fri Nov 6 22:30:25 UTC 2020


indygreg created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Python 3 is the future. We want Python scripts to be using Python 3
  by default.
  
  This change updates all `#!/usr/bin/env python` shebangs to use
  `python3`.
  
  Does this mean all scripts use or require Python 3: no.
  
  In the test environment, the `PATH` environment variable in tests is
  updated to guarantee that the Python executable used to run
  run-tests.py is used. Since test scripts all now use
  `#!/usr/bin/env python3`, we had to update this code to install
  a `python3` symlink instead of `python`.
  
  It is possible there are some random scripts now executed with the
  incorrect Python interpreter in some contexts. However, I would argue
  that this was a pre-existing bug: we should almost always be executing
  new Python processes using the `sys.executable` from the originating
  Python script, as `python` or `python3` won't guarantee we'll use the
  same interpreter.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D9273

AFFECTED FILES
  contrib/check-code.py
  contrib/check-commit
  contrib/check-config.py
  contrib/check-py3-compat.py
  contrib/debugcmdserver.py
  contrib/dumprevlog
  contrib/hg-ssh
  contrib/hgperf
  contrib/hgweb.fcgi
  contrib/import-checker.py
  contrib/perf-utils/perf-revlog-write-plot.py
  contrib/phab-clean.py
  contrib/revsetbenchmarks.py
  contrib/simplemerge
  contrib/undumprevlog
  doc/check-seclevel.py
  doc/docchecker
  doc/gendoc.py
  doc/runrst
  hg
  hgweb.cgi
  i18n/check-translation.py
  i18n/hggettext
  i18n/posplit
  tests/artifacts/scripts/generate-churning-bundle.py
  tests/check-perf-code.py
  tests/dumbhttp.py
  tests/dummysmtpd.py
  tests/dummyssh
  tests/f
  tests/filterpyflakes.py
  tests/filtertraceback.py
  tests/fsmonitor-run-tests.py
  tests/get-with-headers.py
  tests/hghave
  tests/killdaemons.py
  tests/ls-l.py
  tests/md5sum.py
  tests/printenv.py
  tests/readlink.py
  tests/revlog-formatv0.py
  tests/run-tests.py
  tests/seq.py
  tests/svn-safe-append.py
  tests/test-filelog.py
  tests/test-remotefilelog-datapack.py
  tests/test-remotefilelog-histpack.py
  tests/test-run-tests.t
  tests/test-status-inprocess.py
  tests/test-stdio.py
  tests/tinyproxy.py

CHANGE DETAILS

diff --git a/tests/tinyproxy.py b/tests/tinyproxy.py
--- a/tests/tinyproxy.py
+++ b/tests/tinyproxy.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 from __future__ import absolute_import, print_function
 
diff --git a/tests/test-stdio.py b/tests/test-stdio.py
--- a/tests/test-stdio.py
+++ b/tests/test-stdio.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 """
 Tests the buffering behavior of stdio streams in `mercurial.utils.procutil`.
 """
diff --git a/tests/test-status-inprocess.py b/tests/test-status-inprocess.py
--- a/tests/test-status-inprocess.py
+++ b/tests/test-status-inprocess.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 from __future__ import absolute_import, print_function
 
 import sys
diff --git a/tests/test-run-tests.t b/tests/test-run-tests.t
--- a/tests/test-run-tests.t
+++ b/tests/test-run-tests.t
@@ -1412,7 +1412,7 @@
   > This should print the start of check-code. If this passes but the
   > previous check failed, that means we found a copy of check-code at whatever
   > RUNTESTSDIR ended up containing, even though it doesn't match TESTDIR.
-  >   $ head -n 3 "\$RUNTESTDIR"/../contrib/check-code.py | sed 's at .!.*python@#!USRBINENVPY@'
+  >   $ head -n 3 "\$RUNTESTDIR"/../contrib/check-code.py | sed 's at .!.*python3@#!USRBINENVPY@'
   >   #!USRBINENVPY
   >   #
   >   # check-code - a style and portability checker for Mercurial
diff --git a/tests/test-remotefilelog-histpack.py b/tests/test-remotefilelog-histpack.py
--- a/tests/test-remotefilelog-histpack.py
+++ b/tests/test-remotefilelog-histpack.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 from __future__ import absolute_import
 
 import hashlib
diff --git a/tests/test-remotefilelog-datapack.py b/tests/test-remotefilelog-datapack.py
--- a/tests/test-remotefilelog-datapack.py
+++ b/tests/test-remotefilelog-datapack.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 from __future__ import absolute_import, print_function
 
 import hashlib
diff --git a/tests/test-filelog.py b/tests/test-filelog.py
--- a/tests/test-filelog.py
+++ b/tests/test-filelog.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 """
 Tests the behavior of filelog w.r.t. data starting with '\1\n'
 """
diff --git a/tests/svn-safe-append.py b/tests/svn-safe-append.py
--- a/tests/svn-safe-append.py
+++ b/tests/svn-safe-append.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 from __future__ import absolute_import
 
diff --git a/tests/seq.py b/tests/seq.py
--- a/tests/seq.py
+++ b/tests/seq.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # A portable replacement for 'seq'
 #
diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # run-tests.py - Run a set of tests on Mercurial
 #
@@ -3433,7 +3433,7 @@
     def _usecorrectpython(self):
         """Configure the environment to use the appropriate Python in tests."""
         # Tests must use the same interpreter as us or bad things will happen.
-        pyexename = sys.platform == 'win32' and b'python.exe' or b'python'
+        pyexename = sys.platform == 'win32' and b'python.exe' or b'python3'
 
         # os.symlink() is a thing with py3 on Windows, but it requires
         # Administrator rights.
diff --git a/tests/revlog-formatv0.py b/tests/revlog-formatv0.py
--- a/tests/revlog-formatv0.py
+++ b/tests/revlog-formatv0.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # Copyright 2010 Intevation GmbH
 # Author(s):
 # Thomas Arendsen Hein <thomas at intevation.de>
diff --git a/tests/readlink.py b/tests/readlink.py
--- a/tests/readlink.py
+++ b/tests/readlink.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 from __future__ import absolute_import, print_function
 
diff --git a/tests/printenv.py b/tests/printenv.py
--- a/tests/printenv.py
+++ b/tests/printenv.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # simple script to be used in hooks
 #
diff --git a/tests/md5sum.py b/tests/md5sum.py
--- a/tests/md5sum.py
+++ b/tests/md5sum.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # Based on python's Tools/scripts/md5sum.py
 #
diff --git a/tests/ls-l.py b/tests/ls-l.py
--- a/tests/ls-l.py
+++ b/tests/ls-l.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 # like ls -l, but do not print date, user, or non-common mode bit, to avoid
 # using globs in tests.
diff --git a/tests/killdaemons.py b/tests/killdaemons.py
--- a/tests/killdaemons.py
+++ b/tests/killdaemons.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 from __future__ import absolute_import
 import errno
diff --git a/tests/hghave b/tests/hghave
--- a/tests/hghave
+++ b/tests/hghave
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 """Test the running system for features availability. Exit with zero
 if all features are there, non-zero otherwise. If a feature name is
 prefixed with "no-", the absence of feature is tested.
diff --git a/tests/get-with-headers.py b/tests/get-with-headers.py
--- a/tests/get-with-headers.py
+++ b/tests/get-with-headers.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 """This does HTTP GET requests given a host:port and path and returns
 a subset of the headers plus the body of the result."""
diff --git a/tests/fsmonitor-run-tests.py b/tests/fsmonitor-run-tests.py
--- a/tests/fsmonitor-run-tests.py
+++ b/tests/fsmonitor-run-tests.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 # fsmonitor-run-tests.py - Run Mercurial tests with fsmonitor enabled
 #
diff --git a/tests/filtertraceback.py b/tests/filtertraceback.py
--- a/tests/filtertraceback.py
+++ b/tests/filtertraceback.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 # Filters traceback lines from stdin.
 
diff --git a/tests/filterpyflakes.py b/tests/filterpyflakes.py
--- a/tests/filterpyflakes.py
+++ b/tests/filterpyflakes.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 # Filter output by pyflakes to control which warnings we check
 
diff --git a/tests/f b/tests/f
--- a/tests/f
+++ b/tests/f
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 """
 Utility for inspecting files in various ways.
diff --git a/tests/dummyssh b/tests/dummyssh
--- a/tests/dummyssh
+++ b/tests/dummyssh
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 from __future__ import absolute_import
 
diff --git a/tests/dummysmtpd.py b/tests/dummysmtpd.py
--- a/tests/dummysmtpd.py
+++ b/tests/dummysmtpd.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 """dummy SMTP server for use in tests"""
 
diff --git a/tests/dumbhttp.py b/tests/dumbhttp.py
--- a/tests/dumbhttp.py
+++ b/tests/dumbhttp.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 from __future__ import absolute_import
 
diff --git a/tests/check-perf-code.py b/tests/check-perf-code.py
--- a/tests/check-perf-code.py
+++ b/tests/check-perf-code.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # check-perf-code - (historical) portability checker for contrib/perf.py
 
diff --git a/tests/artifacts/scripts/generate-churning-bundle.py b/tests/artifacts/scripts/generate-churning-bundle.py
--- a/tests/artifacts/scripts/generate-churning-bundle.py
+++ b/tests/artifacts/scripts/generate-churning-bundle.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # generate-branchy-bundle - generate a branch for a "large" branchy repository
 #
diff --git a/i18n/posplit b/i18n/posplit
--- a/i18n/posplit
+++ b/i18n/posplit
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # posplit - split messages in paragraphs on .po/.pot files
 #
diff --git a/i18n/hggettext b/i18n/hggettext
--- a/i18n/hggettext
+++ b/i18n/hggettext
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # hggettext - carefully extract docstrings for Mercurial
 #
diff --git a/i18n/check-translation.py b/i18n/check-translation.py
--- a/i18n/check-translation.py
+++ b/i18n/check-translation.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # check-translation.py - check Mercurial specific translation problems
 from __future__ import absolute_import
diff --git a/hgweb.cgi b/hgweb.cgi
--- a/hgweb.cgi
+++ b/hgweb.cgi
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # An example hgweb CGI script, edit as necessary
 # See also https://mercurial-scm.org/wiki/PublishingRepositories
diff --git a/hg b/hg
--- a/hg
+++ b/hg
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # mercurial - scalable distributed SCM
 #
diff --git a/doc/runrst b/doc/runrst
--- a/doc/runrst
+++ b/doc/runrst
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # runrst - register custom roles and run correct writer
 #
diff --git a/doc/gendoc.py b/doc/gendoc.py
--- a/doc/gendoc.py
+++ b/doc/gendoc.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 """usage: %s DOC ...
 
 where DOC is the name of a document
diff --git a/doc/docchecker b/doc/docchecker
--- a/doc/docchecker
+++ b/doc/docchecker
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # docchecker - look for problematic markup
 #
diff --git a/doc/check-seclevel.py b/doc/check-seclevel.py
--- a/doc/check-seclevel.py
+++ b/doc/check-seclevel.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # checkseclevel - checking section title levels in each online help document
 
diff --git a/contrib/undumprevlog b/contrib/undumprevlog
--- a/contrib/undumprevlog
+++ b/contrib/undumprevlog
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # Undump a dump from dumprevlog
 # $ hg init
 # $ undumprevlog < repo.dump
diff --git a/contrib/simplemerge b/contrib/simplemerge
--- a/contrib/simplemerge
+++ b/contrib/simplemerge
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 from __future__ import absolute_import
 
 import getopt
diff --git a/contrib/revsetbenchmarks.py b/contrib/revsetbenchmarks.py
--- a/contrib/revsetbenchmarks.py
+++ b/contrib/revsetbenchmarks.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 # Measure the performance of a list of revsets against multiple revisions
 # defined by parameter. Checkout one by one and run perfrevset with every
diff --git a/contrib/phab-clean.py b/contrib/phab-clean.py
--- a/contrib/phab-clean.py
+++ b/contrib/phab-clean.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # A small script to automatically reject idle Diffs
 #
diff --git a/contrib/perf-utils/perf-revlog-write-plot.py b/contrib/perf-utils/perf-revlog-write-plot.py
--- a/contrib/perf-utils/perf-revlog-write-plot.py
+++ b/contrib/perf-utils/perf-revlog-write-plot.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 #  Copyright 2018 Paul Morelle <Paul.Morelle at octobus.net>
 #
diff --git a/contrib/import-checker.py b/contrib/import-checker.py
--- a/contrib/import-checker.py
+++ b/contrib/import-checker.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 from __future__ import absolute_import, print_function
 
diff --git a/contrib/hgweb.fcgi b/contrib/hgweb.fcgi
--- a/contrib/hgweb.fcgi
+++ b/contrib/hgweb.fcgi
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # An example FastCGI script for use with flup, edit as necessary
 
diff --git a/contrib/hgperf b/contrib/hgperf
--- a/contrib/hgperf
+++ b/contrib/hgperf
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # hgperf - measure performance of Mercurial commands
 #
diff --git a/contrib/hg-ssh b/contrib/hg-ssh
--- a/contrib/hg-ssh
+++ b/contrib/hg-ssh
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # Copyright 2005-2007 by Intevation GmbH <intevation at intevation.de>
 #
diff --git a/contrib/dumprevlog b/contrib/dumprevlog
--- a/contrib/dumprevlog
+++ b/contrib/dumprevlog
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # Dump revlogs as raw data stream
 # $ find .hg/store/ -name "*.i" | xargs dumprevlog > repo.dump
 
diff --git a/contrib/debugcmdserver.py b/contrib/debugcmdserver.py
--- a/contrib/debugcmdserver.py
+++ b/contrib/debugcmdserver.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # Dumps output generated by Mercurial's command server in a formatted style to a
 # given file or stderr if '-' is specified. Output is also written in its raw
diff --git a/contrib/check-py3-compat.py b/contrib/check-py3-compat.py
--- a/contrib/check-py3-compat.py
+++ b/contrib/check-py3-compat.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # check-py3-compat - check Python 3 compatibility of Mercurial files
 #
diff --git a/contrib/check-config.py b/contrib/check-config.py
--- a/contrib/check-config.py
+++ b/contrib/check-config.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # check-config - a config flag documentation checker for Mercurial
 #
diff --git a/contrib/check-commit b/contrib/check-commit
--- a/contrib/check-commit
+++ b/contrib/check-commit
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # Copyright 2014 Matt Mackall <mpm at selenic.com>
 #
diff --git a/contrib/check-code.py b/contrib/check-code.py
--- a/contrib/check-code.py
+++ b/contrib/check-code.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # check-code - a style and portability checker for Mercurial
 #



To: indygreg, #hg-reviewers
Cc: mercurial-patches, mercurial-devel


More information about the Mercurial-devel mailing list