Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
74afd3c
Port python deps setup to windows
Daverlo Oct 6, 2020
2748e6c
Update python-deps-windows test_dir paths
Daverlo Oct 6, 2020
0f2fa46
Update installPythonDeps for windows
Daverlo Oct 6, 2020
526dac0
Only run tests on main and v1
Daverlo Oct 6, 2020
e97bdbd
Combine auto_install scripts
Daverlo Oct 7, 2020
da5edaf
Change time in template
Oct 7, 2020
424a9cf
Apply suggestions from code review
Daverlo Oct 8, 2020
735ec7d
Add powershell to call
Daverlo Oct 8, 2020
e3d2d4a
Add call to py
Daverlo Oct 8, 2020
9bc8c56
Add missing [
Daverlo Oct 8, 2020
2da5fbf
Update default CodeQL version to codeql-bundle-20201008
rneatherway Oct 8, 2020
72e430f
Merge branch 'main' into daverlo/python-windows
Daverlo Oct 8, 2020
64ebf10
Don't use ::set-env in python-setup
RasmusWL Oct 8, 2020
f79717f
Start analysing merge commit for PRs
rneatherway Oct 13, 2020
bc19613
Merge pull request #260 from github/rneatherway/codeql-bundle-20201008
rneatherway Oct 13, 2020
f813ad0
Merge branch 'main' into rneatherway-patch-1
rneatherway Oct 13, 2020
cdfffe8
Merge pull request #264 from github/rneatherway-patch-1
rneatherway Oct 13, 2020
0d97ea8
Call pipenv and poetry through python
Daverlo Oct 13, 2020
e63596e
Merge branch 'main' into daverlo/python-windows
Daverlo Oct 13, 2020
345bcba
Merge branch 'main' into patch-1
robertbrignull Oct 13, 2020
3f8927d
Merge pull request #259 from andymckay/patch-1
robertbrignull Oct 13, 2020
2c3dafc
Use sys.executable
Daverlo Oct 14, 2020
bc72944
Merge branch 'main' into rasmuswl/python-update-setenv
RasmusWL Oct 15, 2020
7d1f309
Address comments
Daverlo Oct 15, 2020
a41d1bd
Merge pull request #261 from github/rasmuswl/python-update-setenv
Daverlo Oct 15, 2020
e0f7838
Merge branch 'main' into daverlo/python-windows
Daverlo Oct 15, 2020
c8b8c04
Merge pull request #257 from github/daverlo/python-windows
Daverlo Oct 15, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,6 @@ jobs:

steps:
- uses: actions/checkout@v2
with:
# Must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head of the pull request.
fetch-depth: 2

# If this run was triggered by a pull request event then checkout
# the head of the pull request instead of the merge commit.
- run: git checkout HEAD^2
if: ${{ github.event_name == 'pull_request' }}

- uses: ./init
with:
languages: javascript
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test Python Package Installation
name: Test Python Package Installation on Linux

on:
push:
Expand Down
61 changes: 61 additions & 0 deletions .github/workflows/python-deps-windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Test Python Package Installation on Windows


on:
push:
branches: [main, v1]
pull_request:

jobs:

test-setup-python-scripts:
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
include:
- test_dir: python-setup/tests/pipenv/requests-2
python_version: 2
- test_dir: python-setup/tests/pipenv/requests-3
python_version: 3

- test_dir: python-setup/tests/poetry/requests-2
python_version: 2
- test_dir: python-setup/tests/poetry/requests-3
python_version: 3

- test_dir: python-setup/tests/requirements/requests-2
python_version: 2
- test_dir: python-setup/tests/requirements/requests-3
python_version: 3

- test_dir: python-setup/tests/setup_py/requests-2
python_version: 2
- test_dir: python-setup/tests/setup_py/requests-3
python_version: 3

steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: python

- name: Test Auto Package Installation
run: |
$cmd = $Env:GITHUB_WORKSPACE + "\\python-setup\\install_tools.ps1"
powershell -File $cmd

cd $Env:GITHUB_WORKSPACE\\${{ matrix.test_dir }}
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

py -3 $Env:GITHUB_WORKSPACE\\python-setup\\tests\\from_python_exe.py $Env:CODEQL_PYTHON
- name: Verify packages installed
run: |
$cmd = $Env:GITHUB_WORKSPACE + "\\python-setup\\tests\\check_requests_123.ps1"
powershell -File $cmd ${{ matrix.python_version }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ on:
# │ │ │ │ │
# │ │ │ │ │
# * * * * *
- cron: '0 0 * * 0'
- cron: '30 1 * * 0'

jobs:
CodeQL-Build:
Expand Down
2 changes: 1 addition & 1 deletion lib/defaults.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"bundleVersion": "codeql-bundle-20200826"
"bundleVersion": "codeql-bundle-20201008"
}
29 changes: 25 additions & 4 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.

62 changes: 48 additions & 14 deletions python-setup/auto_install_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,13 @@ def _check_output(command):


def install_packages_with_poetry():
command = [sys.executable, '-m', 'poetry']
if sys.platform.startswith('win32'):
# In windows the default path were the deps are installed gets wiped out between steps,
# so we have to set it up to a folder that will be kept
os.environ['POETRY_VIRTUALENVS_PATH'] = os.path.join(os.environ['RUNNER_WORKSPACE'], 'virtualenvs')
try:
_check_call(['poetry', 'install', '--no-root'])
_check_call(command + ['install', '--no-root'])
except subprocess.CalledProcessError:
sys.exit('package installation with poetry failed, see error above')

Expand All @@ -33,44 +38,69 @@ def install_packages_with_poetry():
# virtualenv for the package, which was the case for using poetry for Python 2 when
# default system interpreter was Python 3 :/

poetry_out = _check_output(['poetry', 'run', 'which', 'python'])
poetry_out = _check_output(command + ['run', 'which', 'python'])
python_executable_path = poetry_out.decode('utf-8').splitlines()[-1]

if sys.platform.startswith('win32'):
# Poetry produces a path that starts by /d instead of D:\ and Windows doesn't like that way of specifying the drive letter.
# We completely remove it because it is not needed as everything is in the same drive (We are installing the dependencies in the RUNNER_WORKSPACE)
python_executable_path = python_executable_path[2:]
return python_executable_path


def install_packages_with_pipenv():
command = [sys.executable, '-m', 'pipenv']
if sys.platform.startswith('win32'):
# In windows the default path were the deps are installed gets wiped out between steps,
# so we have to set it up to a folder that will be kept
os.environ['WORKON_HOME'] = os.path.join(os.environ['RUNNER_WORKSPACE'], 'virtualenvs')
try:
_check_call(['pipenv', 'install', '--keep-outdated', '--ignore-pipfile'])
_check_call(command + ['install', '--keep-outdated', '--ignore-pipfile'])
except subprocess.CalledProcessError:
sys.exit('package installation with pipenv failed, see error above')

pipenv_out = _check_output(['pipenv', 'run', 'which', 'python'])
pipenv_out = _check_output(command + ['run', 'which', 'python'])
python_executable_path = pipenv_out.decode('utf-8').splitlines()[-1]

if sys.platform.startswith('win32'):
# Pipenv produces a path that starts by /d instead of D:\ and Windows doesn't like that way of specifying the drive letter.
# We completely remove it because it is not needed as everything is in the same drive (We are installing the dependencies in the RUNNER_WORKSPACE)
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.path.join(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:
Expand All @@ -81,9 +111,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
Expand Down Expand Up @@ -135,12 +170,11 @@ def install_packages(codeql_base_dir) -> Optional[str]:

codeql_base_dir = sys.argv[1]

# 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']

python_executable_path = install_packages(codeql_base_dir)

if python_executable_path is not None:
# see https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable
env_file = open(os.environ["GITHUB_ENV"], mode="at")

print("Setting CODEQL_PYTHON={}".format(python_executable_path))
print("::set-env name=CODEQL_PYTHON::{}".format(python_executable_path))
print("CODEQL_PYTHON={}".format(python_executable_path), file=env_file)
13 changes: 13 additions & 0 deletions python-setup/install_tools.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#! /usr/bin/pwsh

py -2 -m pip install --user --upgrade pip setuptools wheel
py -3 -m pip install --user --upgrade pip setuptools wheel

# 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
py -2 -m pip install --user virtualenv
py -3 -m pip install --user virtualenv

# poetry 1.0.10 has error (https://github.com/python-poetry/poetry/issues/2711)
py -3 -m pip install --user poetry!=1.0.10
py -3 -m pip install --user pipenv
Loading