Skip to content
Permalink
Browse files

Hotfix Python 2 regression from #7366 using FileNotFoundError (#7381)

### Problem
The function `python_interpreter_path()` from `interpreter_selection_utils.py` was originally failing to execute on Py3 because it would encounter `FileNotFoundError`, which we weren't catching, so we added this to the except statement in #7366.

However, the exception apparently does not exist in Python 2, so the nightly cron job failed: https://travis-ci.org/pantsbuild/pants/jobs/506186166#L952.

### Solution
Alias the error `if PY2`. We use this idiom, rather than a try except, so that we can easily automatically delete this code once we drop Py2.

### Result
`PY=python2.7 ./build-support/bin/pre-commit.sh` now works again.
  • Loading branch information...
Eric-Arellano committed Mar 14, 2019
1 parent a88855c commit 552f6643d4cf36e5bf9ea96eee26127033b842f1
@@ -72,6 +72,7 @@ python_library(
name='interpreter_selection_utils',
sources=['interpreter_selection_utils.py'],
dependencies=[
'src/python/pants/util:process_handler'
'src/python/pants/util:process_handler',
'3rdparty/python:future',
]
)
@@ -7,6 +7,8 @@
import os
from unittest import skipIf

from future.utils import PY3

from pants.util.process_handler import subprocess


@@ -50,7 +52,7 @@ def python_interpreter_path(version):
command = ['python{}'.format(version), '-c', 'import sys; print(sys.executable)']
py_path = subprocess.check_output(command).decode('utf-8').strip()
return os.path.realpath(py_path)
except (subprocess.CalledProcessError, FileNotFoundError):
except (subprocess.CalledProcessError, FileNotFoundError if PY3 else IOError):
return None


0 comments on commit 552f664

Please sign in to comment.
You can’t perform that action at this time.