Skip to content

Use uv to install desired python version #17

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
60 changes: 12 additions & 48 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ on:
pull_request:
branches: [main]

env:
# This is required to support GLIB versions present in amazon linux 2. Can be removed once amazon linux 2 is 💀
# More info
# - https://github.com/actions/checkout/issues/1809#issuecomment-2208202462
# - https://github.blog/changelog/2024-03-07-github-actions-all-actions-will-run-on-node20-instead-of-node16-by-default/
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true

jobs:
test_python_installation:
strategy:
Expand All @@ -30,9 +23,11 @@ jobs:
steps:
- name: Setup runner
run: |
yum install -y git tar gzip sudo which
yum install -y git sudo tar gzip which

- uses: actions/checkout@v3
- name: Checkout
run: |
git clone --depth 1 -b "${GITHUB_HEAD_REF:-$GITHUB_REF_NAME}" "https://github.com/${GITHUB_REPOSITORY}.git" .

- name: Install python
uses: ./
Expand All @@ -56,41 +51,6 @@ jobs:
python --version 2>&1 | grep -F "${{ matrix.python-version }}"
test "$(python3 -m pip --version)" = "$(pip --version)"

test_abstract_version_specification:
strategy:
fail-fast: false
matrix:
include:
- python-version: "3"
installed-python-version: "3.12.4"
- python-version: "3.12"
installed-python-version: "3.12.4"
- python-version: "3.11"
installed-python-version: "3.11.9"
- python-version: "3.10"
installed-python-version: "3.10.14"
- python-version: "3.9"
installed-python-version: "3.9.19"
- python-version: "3.8"
installed-python-version: "3.8.19"
runs-on: ubuntu-latest
container: amazonlinux:2023
steps:
- name: Setup runner
run: yum install -y git tar gzip sudo

- uses: actions/checkout@v3

- name: Install python
uses: ./
with:
python-version: "${{ matrix.python-version }}"

- name: Test installation
run: |
set -x
python3 --version 2>&1 | grep -F "${{ matrix.installed-python-version }}"

test_pip_installs:
strategy:
fail-fast: false
Expand All @@ -103,9 +63,11 @@ jobs:
steps:
- name: Setup runner
run: |
yum install -y git tar gzip sudo
yum install -y git sudo tar gzip which

- uses: actions/checkout@v3
- name: Checkout
run: |
git clone --depth 1 -b "${GITHUB_HEAD_REF:-$GITHUB_REF_NAME}" "https://github.com/${GITHUB_REPOSITORY}.git" .

- name: Install python
uses: ./
Expand All @@ -127,9 +89,11 @@ jobs:
steps:
- name: Setup runner
run: |
yum install -y git tar gzip sudo
yum install -y git sudo tar gzip which

- uses: actions/checkout@v3
- name: Checkout
run: |
git clone --depth 1 -b "${GITHUB_HEAD_REF:-$GITHUB_REF_NAME}" "https://github.com/${GITHUB_REPOSITORY}.git" .

- name: Create python version file
run: |
Expand Down
60 changes: 31 additions & 29 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,51 +7,48 @@ inputs:
description: 'Version of python to be installed'
default: '.python-version'
cache:
description: Used to specify whether caching is needed. Set to true, if you'd like to enable caching.
required: true
description: >
[Deprecated] Used to specify whether caching is needed. Set to true, if you'd like to enable caching.
Current implementation uses uv which pulls in pre-compiled binaries of python thereby eliminating the
need to cache compiled python artifacts.
default: 'true'

runs:
using: "composite"
steps:
- name: Ensure dependencies of python are installed
- name: Ensure system dependencies are installed
shell: bash
run: |
sudo yum install -y tar gzip which

- name: Install uv
shell: bash
run: |
${GITHUB_ACTION_PATH}/install-system-dependencies.sh
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/astral-sh/uv/releases/download/0.3.3/uv-installer.sh | sh
source $HOME/.cargo/env
uv self update

- name: Find exact python version
id: find-exact-python-version
- name: Find desired python version
id: find-desired-python-version
shell: bash
run: |
exact_python_version=$(${GITHUB_ACTION_PATH}/find-exact-python-version.sh "${{ inputs.python-version }}" "${{ inputs.python-version-file }}")
echo "exact_python_version=${exact_python_version}" >> $GITHUB_OUTPUT
desired_python_version=$(${GITHUB_ACTION_PATH}/find-desired-python-version.sh "${{ inputs.python-version }}" "${{ inputs.python-version-file }}")
echo "desired_python_version=${desired_python_version}" | tee -a "${GITHUB_OUTPUT}"

- name: Set installation directory
id: set-installation-directory
shell: bash
run: |
exact_python_version="${{ steps.find-exact-python-version.outputs.exact_python_version }}"
echo "installation_directory=${HOME}/.setup-python-amazon-linux/.python-versions/${exact_python_version}" >> $GITHUB_OUTPUT

- name: Cache
id: cache-python
uses: actions/cache@v3
if: inputs.cache == 'true'
with:
path: ${{ steps.set-installation-directory.outputs.installation_directory }}
key: python-${{ steps.find-exact-python-version.outputs.exact_python_version }}-${{ runner.arch }}
desired_python_version="${{ steps.find-desired-python-version.outputs.desired_python_version }}"
echo "installation_directory=${HOME}/.setup-python-amazon-linux/.python-versions/${desired_python_version}" | tee -a "${GITHUB_OUTPUT}"

- id: setup-python
shell: bash
if: inputs.cache == 'false' || (inputs.cache == 'true' && steps.cache-python.outputs.cache-hit != 'true')
run: |
installation_directory="${{ steps.set-installation-directory.outputs.installation_directory }}"
exact_python_version="${{ steps.find-exact-python-version.outputs.exact_python_version }}"

# Using a separate tmp directory instead of /tmp because in some OS images set a noexec option for the mount
# this is a better way compared to changing the mount options of /tmp
tmp_directory="${HOME}/.setup-python-amazon-linux/tmp"
desired_python_version="${{ steps.find-desired-python-version.outputs.desired_python_version }}"

${GITHUB_ACTION_PATH}/install-python.sh "${exact_python_version}" "${installation_directory}" "${tmp_directory}"
uv venv --python "${desired_python_version}" "${installation_directory}"

- name: Add python to PATH
shell: bash
Expand All @@ -61,10 +58,15 @@ runs:

echo "The following python binaries are now available in the PATH"
ls "${installation_directory}/bin"

echo "Linking python libraries..."
ls "${installation_directory}/lib"
sudo ldconfig "${installation_directory}/lib"

- name: Install pip
shell: bash
run: |
installation_directory="${{ steps.set-installation-directory.outputs.installation_directory }}"

python -m ensurepip --upgrade
ln -sf "${installation_directory}/bin/pip3" "${installation_directory}/bin/pip"
pip install --upgrade pip

branding:
icon: 'code'
Expand Down
13 changes: 13 additions & 0 deletions find-desired-python-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

set -euo pipefail

specified_version="$1"
specified_version_file="$2"

desired_python_version="${specified_version}"
if [ -f "${specified_version_file}" ]; then
desired_python_version=$(cat "${specified_version_file}")
fi

echo "${desired_python_version}"
38 changes: 0 additions & 38 deletions find-exact-python-version.sh

This file was deleted.

42 changes: 0 additions & 42 deletions install-python.sh

This file was deleted.

26 changes: 0 additions & 26 deletions install-system-dependencies.sh

This file was deleted.