Skip to content

Commit

Permalink
Showing 6 changed files with 38 additions and 162 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-deps-windows.yml
@@ -49,7 +49,7 @@ jobs:
powershell -File $cmd
cd $Env:GITHUB_WORKSPACE\\${{ matrix.test_dir }}
py -3 $Env:GITHUB_WORKSPACE\\python-setup\\auto_install_packages_windows.py C:\\hostedtoolcache\\windows\\CodeQL\\0.0.0-20200826\\x64\\codeql
py -3 $Env:GITHUB_WORKSPACE\\python-setup\\auto_install_packages.py C:\\hostedtoolcache\\windows\\CodeQL\\0.0.0-20200826\\x64\\codeql
- name: Setup for extractor
run: |
echo $Env:CODEQL_PYTHON
3 changes: 1 addition & 2 deletions lib/init.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/init.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 34 additions & 6 deletions python-setup/auto_install_packages.py
@@ -23,6 +23,8 @@ def _check_output(command):


def install_packages_with_poetry():
if sys.platform.startswith('win32'):
os.environ['POETRY_VIRTUALENVS_PATH'] = os.environ['RUNNER_WORKSPACE'] + '\\virtualenvs'
try:
_check_call(['poetry', 'install', '--no-root'])
except subprocess.CalledProcessError:
@@ -36,10 +38,14 @@ def install_packages_with_poetry():
poetry_out = _check_output(['poetry', 'run', 'which', 'python'])
python_executable_path = poetry_out.decode('utf-8').splitlines()[-1]

if sys.platform.startswith('win32'):
python_executable_path = python_executable_path[2:]
return python_executable_path


def install_packages_with_pipenv():
if sys.platform.startswith('win32'):
os.environ['WORKON_HOME'] = os.environ['RUNNER_WORKSPACE'] + '\\virtualenvs'
try:
_check_call(['pipenv', 'install', '--keep-outdated', '--ignore-pipfile'])
except subprocess.CalledProcessError:
@@ -48,29 +54,43 @@ def install_packages_with_pipenv():
pipenv_out = _check_output(['pipenv', 'run', 'which', 'python'])
python_executable_path = pipenv_out.decode('utf-8').splitlines()[-1]

if sys.platform.startswith('win32'):
python_executable_path = python_executable_path[2:]
return python_executable_path


def _create_venv(version: int):
# create temporary directory ... that just lives "forever"
venv_path = mkdtemp(prefix='codeql-action-python-autoinstall-')
venv_path = os.environ['RUNNER_WORKSPACE']+'/codeql-action-python-autoinstall'
print ("Creating venv in "+venv_path, flush = True)

# virtualenv is a bit nicer for setting up virtual environment, since it will provide
# up-to-date versions of pip/setuptools/wheel which basic `python3 -m venv venv` won't

if version == 2:
_check_call(['python2', '-m', 'virtualenv', venv_path])
elif version == 3:
_check_call(['python3', '-m', 'virtualenv', venv_path])
if sys.platform.startswith('win32'):
if version == 2:
_check_call(['py', '-2', '-m', 'virtualenv', venv_path])
elif version == 3:
_check_call(['py', '-3', '-m', 'virtualenv', venv_path])
else:
if version == 2:
_check_call(['python2', '-m', 'virtualenv', venv_path])
elif version == 3:
_check_call(['python3', '-m', 'virtualenv', venv_path])

return venv_path


def install_requirements_txt_packages(version: int):
venv_path = _create_venv(version)

venv_pip = os.path.join(venv_path, 'bin', 'pip')
venv_python = os.path.join(venv_path, 'bin', 'python')

if sys.platform.startswith('win32'):
venv_pip = os.path.join(venv_path, 'Scripts', 'pip')
venv_python = os.path.join(venv_path, 'Scripts', 'python')

try:
_check_call([venv_pip, 'install', '-r', 'requirements.txt'])
except subprocess.CalledProcessError:
@@ -81,9 +101,14 @@ def install_requirements_txt_packages(version: int):

def install_with_setup_py(version: int):
venv_path = _create_venv(version)

venv_pip = os.path.join(venv_path, 'bin', 'pip')
venv_python = os.path.join(venv_path, 'bin', 'python')

if sys.platform.startswith('win32'):
venv_pip = os.path.join(venv_path, 'Scripts', 'pip')
venv_python = os.path.join(venv_path, 'Scripts', 'python')

try:
# We have to choose between `python setup.py develop` and `pip install -e .`.
# Modern projects use `pip install -e .` and I wasn't able to see any downsides
@@ -137,7 +162,10 @@ def install_packages(codeql_base_dir) -> Optional[str]:

# The binaries for packages installed with `pip install --user` are not available on
# PATH by default, so we need to manually add them.
os.environ['PATH'] = os.path.expanduser('~/.local/bin') + os.pathsep + os.environ['PATH']
if sys.platform.startswith('win32'):
os.environ['PATH'] = os.path.expandvars('%APPDATA%\Python\\Python38\\scripts') + os.pathsep + os.environ['PATH']
else:
os.environ['PATH'] = os.path.expanduser('~/.local/bin') + os.pathsep + os.environ['PATH']

python_executable_path = install_packages(codeql_base_dir)

150 changes: 0 additions & 150 deletions python-setup/auto_install_packages_windows.py

This file was deleted.

3 changes: 1 addition & 2 deletions src/init.ts
@@ -195,11 +195,10 @@ export async function installPythonDeps(codeql: CodeQL, logger: Logger) {
}

let install_tools_script = "install_tools.sh";
let auto_install_packages_script = "auto_install_packages.py";
const auto_install_packages_script = "auto_install_packages.py";

if (process.platform === "win32") {
install_tools_script = "install_tools.ps1";
auto_install_packages_script = "auto_install_packages_windows.py";
}

const scriptsFolder = path.resolve(__dirname, "../python-setup");

0 comments on commit e97bdbd

Please sign in to comment.