python-setup: Fail early if installing for Python 2, and python2 not available
This commit is contained in:
parent
3f97671248
commit
1fa5d72846
1 changed files with 12 additions and 0 deletions
|
|
@ -5,6 +5,7 @@ import os
|
||||||
import subprocess
|
import subprocess
|
||||||
from tempfile import mkdtemp
|
from tempfile import mkdtemp
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
import shutil
|
||||||
|
|
||||||
import extractor_version
|
import extractor_version
|
||||||
|
|
||||||
|
|
@ -154,6 +155,17 @@ def install_packages(codeql_base_dir) -> Optional[str]:
|
||||||
# get_extractor_version returns the Python version the extractor thinks this repo is using
|
# get_extractor_version returns the Python version the extractor thinks this repo is using
|
||||||
version = extractor_version.get_extractor_version(codeql_base_dir, quiet=False)
|
version = extractor_version.get_extractor_version(codeql_base_dir, quiet=False)
|
||||||
|
|
||||||
|
if version == 2 and not sys.platform.startswith('win32'):
|
||||||
|
# On Ubuntu 22.04 'python2' is not available by default. We want to give a slightly better
|
||||||
|
# error message than a traceback + `No such file or directory: 'python2'`
|
||||||
|
if shutil.which("python2") is None:
|
||||||
|
sys.exit(
|
||||||
|
"package installation failed: we detected this code as Python 2, but 'python2' executable was not available."
|
||||||
|
"To enable automatic package installation, please install 'python2' before the 'github/codeql-action/init' step, "
|
||||||
|
"such as running 'sudo apt install python2' (Ubuntu 22.04)."
|
||||||
|
"If your code is not Python 2, but actually Python 3, please file a bug report at https://github.com/github/codeql-action/issues/new"
|
||||||
|
)
|
||||||
|
|
||||||
if os.path.exists('requirements.txt'):
|
if os.path.exists('requirements.txt'):
|
||||||
print('Found requirements.txt, will install packages with pip', flush=True)
|
print('Found requirements.txt, will install packages with pip', flush=True)
|
||||||
return install_requirements_txt_packages(version)
|
return install_requirements_txt_packages(version)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue