Skip to content

Commit 67ddca1

Browse files
committed
Add workflow for testing python setup
1 parent 1831270 commit 67ddca1

33 files changed

Lines changed: 495 additions & 0 deletions

File tree

.github/workflows/python-deps.yml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: Test Python Package Installation
2+
3+
on:
4+
push:
5+
branches: [main, v1]
6+
pull_request:
7+
8+
jobs:
9+
10+
test-setup-python-scripts:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
include:
16+
- test_dir: python-setup/tests/pipenv/requests-2
17+
test_script: $GITHUB_WORKSPACE/python-setup/tests/check_requests_123.sh 2
18+
- test_dir: python-setup/tests/pipenv/requests-3
19+
test_script: $GITHUB_WORKSPACE/python-setup/tests/check_requests_123.sh 3
20+
21+
- test_dir: python-setup/tests/poetry/requests-2
22+
test_script: $GITHUB_WORKSPACE/python-setup/tests/check_requests_123.sh 2
23+
- test_dir: python-setup/tests/poetry/requests-3
24+
test_script: $GITHUB_WORKSPACE/python-setup/tests/check_requests_123.sh 3
25+
26+
- test_dir: python-setup/tests/requirements/requests-2
27+
test_script: $GITHUB_WORKSPACE/python-setup/tests/check_requests_123.sh 2
28+
- test_dir: python-setup/tests/requirements/requests-3
29+
test_script: $GITHUB_WORKSPACE/python-setup/tests/check_requests_123.sh 3
30+
31+
- test_dir: python-setup/tests/setup_py/requests-2
32+
test_script: $GITHUB_WORKSPACE/python-setup/tests/check_requests_123.sh 2
33+
- test_dir: python-setup/tests/setup_py/requests-3
34+
test_script: $GITHUB_WORKSPACE/python-setup/tests/check_requests_123.sh 3
35+
36+
# This one shouldn't fail, but also won't install packages
37+
- test_dir: python-setup/tests/requirements/non-standard-location
38+
test_script: test -z $LGTM_INDEX_IMPORT_PATH
39+
40+
# All of these should fail
41+
- test_dir: python-setup/tests/pipenv/python-version-not-available
42+
test_script: /bin/false
43+
- test_dir: python-setup/tests/poetry/python-version-not-available
44+
test_script: /bin/false
45+
- test_dir: python-setup/tests/requirements/invalid-package
46+
test_script: /bin/false
47+
- test_dir: python-setup/tests/requirements/invalid-version
48+
test_script: /bin/false
49+
- test_dir: python-setup/tests/setup_py/invalid-version
50+
test_script: /bin/false
51+
- test_dir: python-setup/tests/setup_py/invalid-file
52+
test_script: /bin/false
53+
- test_dir: python-setup/tests/setup_py/extra-require-not-installed
54+
test_script: $GITHUB_WORKSPACE/python-setup/tests/check_requests_123.sh 3
55+
- test_dir: python-setup/tests/setup_py/wrong-python-version
56+
test_script: /bin/false
57+
58+
steps:
59+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
60+
- uses: actions/checkout@v2
61+
62+
- name: Initialize CodeQL
63+
uses: github/codeql-action/init@v1
64+
with:
65+
languages: python
66+
67+
- name: Test Auto Package Installation
68+
run: |
69+
set -x
70+
$GITHUB_WORKSPACE/python-setup/install_tools.sh
71+
echo -e '\n\n\n\n\n' && sleep 0.5
72+
cd $GITHUB_WORKSPACE/${{ matrix.test_dir }}
73+
$GITHUB_WORKSPACE/python-setup/auto_install_packages.py /opt/hostedtoolcache/CodeQL/0.0.0-20200826/x64/codeql/
74+
- name: Setup for extractor
75+
run: |
76+
echo $CODEQL_PYTHON
77+
# only run if $CODEQL_PYTHON is set
78+
test ! -z $CODEQL_PYTHON && $GITHUB_WORKSPACE/python-setup/tests/from_python_exe.py $CODEQL_PYTHON || /bin/true
79+
- name: Verify packages installed
80+
run: |
81+
${{ matrix.test_script }}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
6+
7+
EXPECTED_VERSION=$1
8+
9+
FOUND_VERSION="$LGTM_PYTHON_SETUP_VERSION"
10+
FOUND_PYTHONPATH="$LGTM_INDEX_IMPORT_PATH"
11+
12+
echo "FOUND_VERSION=${FOUND_VERSION} FOUND_PYTHONPATH=${FOUND_PYTHONPATH} "
13+
14+
if [[ $FOUND_VERSION != $EXPECTED_VERSION ]]; then
15+
echo "Script told us to use Python ${FOUND_VERSION}, but expected ${EXPECTED_VERSION}"
16+
exit 1
17+
else
18+
echo "Script told us to use Python ${FOUND_VERSION}, which was expected"
19+
fi
20+
21+
PYTHON_EXE="python${EXPECTED_VERSION}"
22+
23+
INSTALLED_REQUESTS_VERSION=$(PYTHONPATH="${FOUND_PYTHONPATH}" "${PYTHON_EXE}" -c 'import requests; print(requests.__version__)')
24+
25+
EXPECTED_REQUESTS="1.2.3"
26+
27+
if [[ "$INSTALLED_REQUESTS_VERSION" != "$EXPECTED_REQUESTS" ]]; then
28+
echo "Using ${FOUND_PYTHONPATH} as PYTHONPATH, we found version $INSTALLED_REQUESTS_VERSION of requests, but expected $EXPECTED_REQUESTS"
29+
exit 1
30+
else
31+
echo "Using ${FOUND_PYTHONPATH} as PYTHONPATH, we found version $INSTALLED_REQUESTS_VERSION of requests, which was expected"
32+
fi
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env python3
2+
3+
import sys
4+
import subprocess
5+
from typing import Tuple
6+
7+
def get_details(path_to_python_exe: str) -> Tuple[str, str]:
8+
import_path = subprocess.check_output(
9+
[
10+
path_to_python_exe,
11+
"-c",
12+
"import os; import pip; print(os.path.dirname(os.path.dirname(pip.__file__)))",
13+
],
14+
stdin=subprocess.DEVNULL,
15+
)
16+
version = subprocess.check_output(
17+
[path_to_python_exe, "-c", "import sys; print(sys.version_info[0])"],
18+
stdin=subprocess.DEVNULL,
19+
)
20+
21+
return version.decode("utf-8").strip(), import_path.decode("utf-8").strip()
22+
23+
24+
if __name__ == "__main__":
25+
version, import_path = get_details(sys.argv[1])
26+
27+
print("Setting LGTM_PYTHON_SETUP_VERSION={}".format(version))
28+
print("::set-env name=LGTM_PYTHON_SETUP_VERSION::{}".format(version))
29+
30+
print("Setting LGTM_INDEX_IMPORT_PATH={}".format(import_path))
31+
print("::set-env name=LGTM_INDEX_IMPORT_PATH::{}".format(import_path))
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[[source]]
2+
name = "pypi"
3+
url = "https://pypi.org/simple"
4+
verify_ssl = true
5+
6+
[dev-packages]
7+
8+
[packages]
9+
requests = "*"
10+
11+
[requires]
12+
python_version = "3.8"

python-setup/tests/pipenv/python-3.8/Pipfile.lock

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[[source]]
2+
name = "pypi"
3+
url = "https://pypi.org/simple"
4+
verify_ssl = true
5+
6+
[dev-packages]
7+
8+
[packages]
9+
requests = "*"
10+
11+
[requires]
12+
python_version = "3.100"

python-setup/tests/pipenv/python-version-not-available/Pipfile.lock

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[[source]]
2+
name = "pypi"
3+
url = "https://pypi.org/simple"
4+
verify_ssl = true
5+
6+
[dev-packages]
7+
8+
[packages]
9+
requests = "*"
10+
11+
[requires]
12+
python_version = "2.7"

python-setup/tests/pipenv/requests-2/Pipfile.lock

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[[source]]
2+
name = "pypi"
3+
url = "https://pypi.org/simple"
4+
verify_ssl = true
5+
6+
[dev-packages]
7+
8+
[packages]
9+
requests = "*"
10+
11+
[requires]

0 commit comments

Comments
 (0)