Skip to content

Commit

Permalink
Install extra Python versions required by integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsmith committed Jul 20, 2023
1 parent dc6fbf3 commit ca5fa21
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 40 deletions.
43 changes: 43 additions & 0 deletions .github/actions/setup-python/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Setup Python
description:

inputs:
extra-versions:
description: |
Additional versions to install, on top of the supported runtime versions. One
version per line, in the same syntax as the standard setup-python action.
runs:
using: composite
steps:
- name: List runtime versions
id: runtime-versions
shell: bash
run: |
(
echo "versions<<EOF"
target/list-versions.py --short
echo EOF
) >> $GITHUB_OUTPUT
- uses: actions/setup-python@v4.6.1
with:
python-version: |
${{ steps.runtime-versions.outputs.versions }}
${{ inputs.extra-versions }}
- name: Set default Python command
id: python-default
shell: bash
run: |
version=$(target/list-versions.py --default)
if [ $RUNNER_OS = Windows ]; then
echo "command=py -$version"
else
echo "command=python$version"
fi >> $GITHUB_OUTPUT
outputs:
python-default:
description: Command to run the default Python version
value: ${{ steps.python-default.outputs.command }}
51 changes: 23 additions & 28 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,14 @@ defaults:

jobs:
build-product:
runs-on: macos-latest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3.5.3

- name: List Python versions
id: python-versions
run: |
(
echo "versions<<EOF"
target/list-versions.py --short
echo EOF
) >> $GITHUB_OUTPUT
- name: List Android Gradle plugin versions
id: agp-versions
run: |
cd product/gradle-plugin/src/test/integration/data
(
echo -n versions=
echo base-* | sed 's/base-//g' | jq -cR 'split(" ")'
) >> $GITHUB_OUTPUT
- uses: ./.github/actions/setup-python
id: setup-python

- uses: actions/setup-python@v4.6.1
with:
python-version: ${{ steps.python-versions.outputs.versions }}

# This step is referenced from product/README.md.
# This step is referenced from product/README.md.
- name: Download Android Python builds
run: |
cd target
Expand All @@ -51,7 +32,7 @@ jobs:
- name: Install Python requirements
run: |
python$(target/list-versions.py --default) -m \
${{ steps.setup-python.outputs.python-default }} -m \
pip install -r product/runtime/requirements-build.txt
- uses: ./.github/actions/create-local-properties
Expand All @@ -74,8 +55,16 @@ jobs:
!**/*.sha512
if-no-files-found: error

- name: List Android Gradle plugin versions
id: agp-versions
run: |
cd product/gradle-plugin/src/test/integration/data
(
echo -n versions=
echo base-* | sed 's/base-//g' | jq -cR 'split(" ")'
) >> $GITHUB_OUTPUT
outputs:
python-versions: ${{ steps.python-versions.outputs.versions }}
agp-versions: ${{ steps.agp-versions.outputs.versions }}

test-integration:
Expand All @@ -90,9 +79,15 @@ jobs:
steps:
- uses: actions/checkout@v3.5.3

- uses: actions/setup-python@v4.6.1
- uses: ./.github/actions/setup-python
id: setup-python
with:
python-version: ${{ needs.build-product.outputs.python-versions }}
# This should match OLD_BUILD_PYTHON_VERSIONS and MIN_BUILD_PYTHON_VERSION
# in test_gradle_plugin.
extra-versions: |
2.7
3.6
3.7
- name: Download Maven repository
uses: actions/download-artifact@v3.0.2
Expand All @@ -102,7 +97,7 @@ jobs:

- name: Install Python requirements
run: |
python$(target/list-versions.py --default) -m \
${{ steps.setup-python.outputs.python-default }} -m \
pip install -r product/gradle-plugin/src/test/integration/requirements.txt
- uses: ./.github/actions/create-local-properties
Expand Down
5 changes: 3 additions & 2 deletions product/gradle-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ After stable release:

* Update gradle-plugin/src/main/python/chaquopy/util.py.
* Update `testPython` in gradle-plugin/build.gradle, and run the tests.
* Update `OLD_BUILD_PYTHON_VERSION` and `MIN_BUILD_PYTHON_VERSION` in test_gradle_plugin,
and run the tests which use them.
* In test_gradle_plugin, update `OLD_BUILD_PYTHON_VERSIONS` and
`MIN_BUILD_PYTHON_VERSION`, and run the tests which use them.
* In the ci.yml job `test-integration`, update `extra-versions`.
* Update android.rst.


Expand Down
13 changes: 8 additions & 5 deletions product/gradle-plugin/src/test/integration/test_gradle_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,13 @@ def run_build_python(args, **kwargs):
BUILD_PYTHON_VERSION_FULL = (run_build_python(["--version"]).stdout # e.g. "Python 3.7.1"
.split()[1])
BUILD_PYTHON_VERSION = BUILD_PYTHON_VERSION_FULL.rpartition(".")[0]
OLD_BUILD_PYTHON_VERSION = "3.6"

# These should match `extra-versions` in the ci.yml job `test-integration`. 2.7 is
# included to make sure we've kept valid Python 2 syntax, so we can produce a useful
# error message.
OLD_BUILD_PYTHON_VERSIONS = ["2.7", "3.6"]
MIN_BUILD_PYTHON_VERSION = "3.7"

MAX_BUILD_PYTHON_VERSION = "3.11"
EGG_INFO_SUFFIX = "py" + BUILD_PYTHON_VERSION + ".egg-info"
EGG_INFO_FILES = ["dependency_links.txt", "PKG-INFO", "SOURCES.txt", "top_level.txt"]
Expand Down Expand Up @@ -760,8 +765,7 @@ def test_buildpython(self):
"no_binary_sdist/__init__.py"],
pyc=["stdlib"])

# Make sure we've kept valid Python 2 syntax so we can produce a useful error message.
for version in ["2.7", OLD_BUILD_PYTHON_VERSION]:
for version in OLD_BUILD_PYTHON_VERSIONS:
with self.subTest(version=version):
run = self.RunGradle(*layers, env={"buildpython_version": version},
succeed=False)
Expand Down Expand Up @@ -1423,8 +1427,7 @@ def test_buildpython(self):
classes={"chaquopy_test.a": ["SrcA1"]},
pyc=["stdlib"])

# Make sure we've kept valid Python 2 syntax so we can produce a useful error message.
for version in ["2.7", OLD_BUILD_PYTHON_VERSION]:
for version in OLD_BUILD_PYTHON_VERSIONS:
with self.subTest(version=version):
run = self.RunGradle(*layers, env={"buildpython_version": version},
succeed=False)
Expand Down
10 changes: 5 additions & 5 deletions server/pypi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ First, clone this repository.
Then, go to [this Maven Central
page](https://repo.maven.apache.org/maven2/com/chaquo/python/target/) and select which
Python version you want to build for. Within a given Python minor version (e.g. 3.8),
you should usually use the newest version available. On that version's page, find
the .zip for the ABI you want to build for, and download it into a corresponding
subdirectory of `maven` in the root of this repository. For example, anything you download
from https://repo.maven.apache.org/maven2/com/chaquo/python/target/3.8.16-0/ should be
placed in `maven/com/chaquo/python/target/3.8.16-0`.
you should usually use the newest version available. Then use `download-target.sh` to
download it into `maven` in the root of this repository. For example, to download
version 3.8.16-0, run:

target/download-target.sh maven/com/chaquo/python/target/3.8.16-0

You'll also need a matching version of Python installed on your build machine. For
example, if you're building for Python 3.8, then `python3.8` must be on the PATH. You may
Expand Down

0 comments on commit ca5fa21

Please sign in to comment.