Skip to content

Commit

Permalink
[wpt] Reject python versions <3.6 (#27426)
Browse files Browse the repository at this point in the history
This commit changes the entrypoint to reject any Python version that is
not 3.6 or higher. It also removes the --py2 and --py3 flags.

We are deliberately doing a rejection rather than a fallback to Python 3
to quickly find any remaining entrypoints using Py2.
  • Loading branch information
stephenmcgruer committed Feb 2, 2021
1 parent c134161 commit 92b1c27
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 34 deletions.
3 changes: 3 additions & 0 deletions .azure-pipelines.yml
Expand Up @@ -77,6 +77,9 @@ jobs:
pool:
vmImage: 'ubuntu-18.04'
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '3.8.x'
- template: tools/ci/azure/checkout.yml
- script: |
set -euo pipefail
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/manifest.yml
Expand Up @@ -10,6 +10,10 @@ jobs:
build-and-tag:
runs-on: ubuntu-18.04
steps:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Checkout
uses: actions/checkout@v1
with:
Expand Down
4 changes: 0 additions & 4 deletions tools/wpt/wpt.py
Expand Up @@ -50,10 +50,6 @@ def parse_args(argv, commands=load_commands()):
dest="skip_venv_setup",
help="Whether to use the virtualenv as-is. Must set --venv as well")
parser.add_argument("--debug", action="store_true", help="Run the debugger in case of an exception")
parser.add_argument("--py3", action="store_true",
help="Run with Python 3 (requires a `python3` binary on the PATH)")
parser.add_argument("--py2", action="store_true",
help="Run with Python 2 (requires a `python2` binary on the PATH)")
subparsers = parser.add_subparsers(dest="command")
for command, props in iteritems(commands):
subparsers.add_parser(command, help=props["help"], add_help=False)
Expand Down
37 changes: 7 additions & 30 deletions wpt
@@ -1,34 +1,11 @@
#!/usr/bin/env python
#!/usr/bin/env python3

if __name__ == "__main__":
import sys
from tools.wpt import wpt
args, extra = wpt.parse_args(sys.argv[1:])
commands = wpt.load_commands()
py3only = commands[args.command]["py3only"]
if (sys.version_info.major < 3 or
(sys.version_info.major == 3 and sys.version_info.minor < 6)):
sys.stderr.write("wpt requires Python 3.6 or higher\n")
sys.exit(1)

if (args.py2) and sys.version_info.major > 2:
if py3only:
sys.stderr.write("This command only works with Python 3\n")
sys.exit(1)
from subprocess import call
try:
sys.exit(call(['python2'] + sys.argv))
except OSError as e:
if e.errno == 2:
sys.stderr.write("python2 is needed to run this command\n")
sys.exit(1)
else:
raise
elif (not args.py2) and sys.version_info.major < 3:
from subprocess import call
try:
sys.exit(call(['python3'] + sys.argv))
except OSError as e:
if e.errno == 2:
sys.stderr.write("python3 is needed to run this command\n")
sys.exit(1)
else:
raise
else:
wpt.main()
from tools.wpt import wpt
wpt.main()

0 comments on commit 92b1c27

Please sign in to comment.