Skip to content

Commit 88fcec6

Browse files
Merge pull request #17 from kishaningithub/experiment-uv
Use uv to install desired python version
2 parents 6482e00 + b4caa0a commit 88fcec6

6 files changed

+56
-183
lines changed

.github/workflows/test.yml

+12-48
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@ on:
66
pull_request:
77
branches: [main]
88

9-
env:
10-
# This is required to support GLIB versions present in amazon linux 2. Can be removed once amazon linux 2 is 💀
11-
# More info
12-
# - https://github.com/actions/checkout/issues/1809#issuecomment-2208202462
13-
# - https://github.blog/changelog/2024-03-07-github-actions-all-actions-will-run-on-node20-instead-of-node16-by-default/
14-
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true
15-
169
jobs:
1710
test_python_installation:
1811
strategy:
@@ -30,9 +23,11 @@ jobs:
3023
steps:
3124
- name: Setup runner
3225
run: |
33-
yum install -y git tar gzip sudo which
26+
yum install -y git sudo tar gzip which
3427
35-
- uses: actions/checkout@v3
28+
- name: Checkout
29+
run: |
30+
git clone --depth 1 -b "${GITHUB_HEAD_REF:-$GITHUB_REF_NAME}" "https://github.com/${GITHUB_REPOSITORY}.git" .
3631
3732
- name: Install python
3833
uses: ./
@@ -56,41 +51,6 @@ jobs:
5651
python --version 2>&1 | grep -F "${{ matrix.python-version }}"
5752
test "$(python3 -m pip --version)" = "$(pip --version)"
5853
59-
test_abstract_version_specification:
60-
strategy:
61-
fail-fast: false
62-
matrix:
63-
include:
64-
- python-version: "3"
65-
installed-python-version: "3.12.4"
66-
- python-version: "3.12"
67-
installed-python-version: "3.12.4"
68-
- python-version: "3.11"
69-
installed-python-version: "3.11.9"
70-
- python-version: "3.10"
71-
installed-python-version: "3.10.14"
72-
- python-version: "3.9"
73-
installed-python-version: "3.9.19"
74-
- python-version: "3.8"
75-
installed-python-version: "3.8.19"
76-
runs-on: ubuntu-latest
77-
container: amazonlinux:2023
78-
steps:
79-
- name: Setup runner
80-
run: yum install -y git tar gzip sudo
81-
82-
- uses: actions/checkout@v3
83-
84-
- name: Install python
85-
uses: ./
86-
with:
87-
python-version: "${{ matrix.python-version }}"
88-
89-
- name: Test installation
90-
run: |
91-
set -x
92-
python3 --version 2>&1 | grep -F "${{ matrix.installed-python-version }}"
93-
9454
test_pip_installs:
9555
strategy:
9656
fail-fast: false
@@ -103,9 +63,11 @@ jobs:
10363
steps:
10464
- name: Setup runner
10565
run: |
106-
yum install -y git tar gzip sudo
66+
yum install -y git sudo tar gzip which
10767
108-
- uses: actions/checkout@v3
68+
- name: Checkout
69+
run: |
70+
git clone --depth 1 -b "${GITHUB_HEAD_REF:-$GITHUB_REF_NAME}" "https://github.com/${GITHUB_REPOSITORY}.git" .
10971
11072
- name: Install python
11173
uses: ./
@@ -127,9 +89,11 @@ jobs:
12789
steps:
12890
- name: Setup runner
12991
run: |
130-
yum install -y git tar gzip sudo
92+
yum install -y git sudo tar gzip which
13193
132-
- uses: actions/checkout@v3
94+
- name: Checkout
95+
run: |
96+
git clone --depth 1 -b "${GITHUB_HEAD_REF:-$GITHUB_REF_NAME}" "https://github.com/${GITHUB_REPOSITORY}.git" .
13397
13498
- name: Create python version file
13599
run: |

action.yml

+31-29
Original file line numberDiff line numberDiff line change
@@ -7,51 +7,48 @@ inputs:
77
description: 'Version of python to be installed'
88
default: '.python-version'
99
cache:
10-
description: Used to specify whether caching is needed. Set to true, if you'd like to enable caching.
11-
required: true
10+
description: >
11+
[Deprecated] Used to specify whether caching is needed. Set to true, if you'd like to enable caching.
12+
Current implementation uses uv which pulls in pre-compiled binaries of python thereby eliminating the
13+
need to cache compiled python artifacts.
1214
default: 'true'
15+
1316
runs:
1417
using: "composite"
1518
steps:
16-
- name: Ensure dependencies of python are installed
19+
- name: Ensure system dependencies are installed
20+
shell: bash
21+
run: |
22+
sudo yum install -y tar gzip which
23+
24+
- name: Install uv
1725
shell: bash
1826
run: |
19-
${GITHUB_ACTION_PATH}/install-system-dependencies.sh
27+
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/astral-sh/uv/releases/download/0.3.3/uv-installer.sh | sh
28+
source $HOME/.cargo/env
29+
uv self update
2030
21-
- name: Find exact python version
22-
id: find-exact-python-version
31+
- name: Find desired python version
32+
id: find-desired-python-version
2333
shell: bash
2434
run: |
25-
exact_python_version=$(${GITHUB_ACTION_PATH}/find-exact-python-version.sh "${{ inputs.python-version }}" "${{ inputs.python-version-file }}")
26-
echo "exact_python_version=${exact_python_version}" >> $GITHUB_OUTPUT
35+
desired_python_version=$(${GITHUB_ACTION_PATH}/find-desired-python-version.sh "${{ inputs.python-version }}" "${{ inputs.python-version-file }}")
36+
echo "desired_python_version=${desired_python_version}" | tee -a "${GITHUB_OUTPUT}"
2737
2838
- name: Set installation directory
2939
id: set-installation-directory
3040
shell: bash
3141
run: |
32-
exact_python_version="${{ steps.find-exact-python-version.outputs.exact_python_version }}"
33-
echo "installation_directory=${HOME}/.setup-python-amazon-linux/.python-versions/${exact_python_version}" >> $GITHUB_OUTPUT
34-
35-
- name: Cache
36-
id: cache-python
37-
uses: actions/cache@v3
38-
if: inputs.cache == 'true'
39-
with:
40-
path: ${{ steps.set-installation-directory.outputs.installation_directory }}
41-
key: python-${{ steps.find-exact-python-version.outputs.exact_python_version }}-${{ runner.arch }}
42+
desired_python_version="${{ steps.find-desired-python-version.outputs.desired_python_version }}"
43+
echo "installation_directory=${HOME}/.setup-python-amazon-linux/.python-versions/${desired_python_version}" | tee -a "${GITHUB_OUTPUT}"
4244
4345
- id: setup-python
4446
shell: bash
45-
if: inputs.cache == 'false' || (inputs.cache == 'true' && steps.cache-python.outputs.cache-hit != 'true')
4647
run: |
4748
installation_directory="${{ steps.set-installation-directory.outputs.installation_directory }}"
48-
exact_python_version="${{ steps.find-exact-python-version.outputs.exact_python_version }}"
49-
50-
# Using a separate tmp directory instead of /tmp because in some OS images set a noexec option for the mount
51-
# this is a better way compared to changing the mount options of /tmp
52-
tmp_directory="${HOME}/.setup-python-amazon-linux/tmp"
49+
desired_python_version="${{ steps.find-desired-python-version.outputs.desired_python_version }}"
5350
54-
${GITHUB_ACTION_PATH}/install-python.sh "${exact_python_version}" "${installation_directory}" "${tmp_directory}"
51+
uv venv --python "${desired_python_version}" "${installation_directory}"
5552
5653
- name: Add python to PATH
5754
shell: bash
@@ -61,10 +58,15 @@ runs:
6158
6259
echo "The following python binaries are now available in the PATH"
6360
ls "${installation_directory}/bin"
64-
65-
echo "Linking python libraries..."
66-
ls "${installation_directory}/lib"
67-
sudo ldconfig "${installation_directory}/lib"
61+
62+
- name: Install pip
63+
shell: bash
64+
run: |
65+
installation_directory="${{ steps.set-installation-directory.outputs.installation_directory }}"
66+
67+
python -m ensurepip --upgrade
68+
ln -sf "${installation_directory}/bin/pip3" "${installation_directory}/bin/pip"
69+
pip install --upgrade pip
6870
6971
branding:
7072
icon: 'code'

find-desired-python-version.sh

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
specified_version="$1"
6+
specified_version_file="$2"
7+
8+
desired_python_version="${specified_version}"
9+
if [ -f "${specified_version_file}" ]; then
10+
desired_python_version=$(cat "${specified_version_file}")
11+
fi
12+
13+
echo "${desired_python_version}"

find-exact-python-version.sh

-38
This file was deleted.

install-python.sh

-42
This file was deleted.

install-system-dependencies.sh

-26
This file was deleted.

0 commit comments

Comments
 (0)