Skip to content

Commit 1496ebe

Browse files
committed
feat: Replace ppa/deadsnakes with uv
1 parent e25f814 commit 1496ebe

File tree

4 files changed

+65
-50
lines changed

4 files changed

+65
-50
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,8 @@ jobs:
271271
| `python-version` | Python version to use for building | `"3.13"` | `"3.12"` |
272272
| `pyinstaller-version` | PyInstaller version to install | `6.11.1` | `""` (use latest) |
273273
| `additional-args` | Additional PyInstaller arguments | `""` | `"--hidden-import=module"` |
274-
| `pip-extra-index-url` | Extra pip index URL | `https://dl.espressif.com/pypi` | `""` |
275-
| `install-deps-command` | Command to install project dependencies | `"pip install --user --prefer-binary -e ."` | `"pip install -r requirements.txt"` |
274+
| `pip-extra-index-url` | Extra Python package index URL | `https://dl.espressif.com/pypi` | `""` |
275+
| `install-deps-command` | Command to install project dependencies | `"uv pip install -e ."` | `"uv pip install -r requirements.txt"` |
276276
| `additional-arm-packages` | ARMv7 ONLY: Additional system packages | `""` | `"openssl libffi-dev"` |
277277
| `test-command-args` | Command arguments to test executables | `"--help"` | `"--version"` |
278278
| `certificate` | Certificate to use for signing binaries | `""` | `${{ secrets.CERTIFICATE }}` |

action.yml

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ inputs:
4343
required: false
4444
default: ''
4545
pip-extra-index-url:
46-
description: Extra pip index URL
46+
description: Extra Python Package Index URL
4747
required: false
4848
default: https://dl.espressif.com/pypi
4949
install-deps-command:
5050
description: Command to install project dependencies. Command will be executed
51-
like `python -m {install-deps-command}`
51+
like `uv pip install {install-deps-command}`
5252
required: false
53-
default: pip install --user --prefer-binary -e .
53+
default: uv pip install -e .
5454
additional-arm-packages:
5555
description: 'ARMv7 ONLY: Additional system packages to install (space-separated).
5656
e.g. for cryptography: openssl libffi-dev libffi7 libssl-dev'
@@ -137,22 +137,24 @@ runs:
137137
export DEBIAN_FRONTEND=noninteractive
138138
export TZ=UTC
139139
apt-get update -y
140-
apt-get install -y software-properties-common
141-
add-apt-repository -y ppa:deadsnakes/ppa
142-
apt-get update -y
143-
apt-get install --ignore-missing -y curl python${{ inputs.python-version }} python${{ inputs.python-version }}-dev pkg-config gcc g++ patchelf binutils zlib1g-dev ${{ inputs.additional-arm-packages }}
144-
# Install pip for requested Python version using get-pip.py as ensurepip does not work here
145-
curl -sS https://bootstrap.pypa.io/get-pip.py | python${{ inputs.python-version }}
146-
python${{ inputs.python-version }} -m pip install --upgrade pip setuptools wheel
140+
apt-get install -y curl git build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev pkg-config gcc g++ patchelf binutils ${{ inputs.additional-arm-packages }}
147141
run: |
148142
adduser --disabled-password --gecos "" builder
149143
chmod -R a+rwx /home/runner/work
150144
su builder <<'EOF'
145+
curl -LsSf https://astral.sh/uv/install.sh | sh
146+
source $HOME/.local/bin/env
147+
# Install Python version using uv
148+
uv python install ${{ inputs.python-version }}
149+
# Create and activate virtual environment
150+
uv venv
151+
source .venv/bin/activate
152+
# Install UV and upgrade tools
153+
uv pip install --upgrade setuptools wheel
151154
export PATH=$PATH:/home/builder/.local/bin
152155
153156
# Setup environment using helper script
154157
/github/action/setup_environment.sh \
155-
"python${{ inputs.python-version }}" \
156158
"${{ inputs.pyinstaller-version }}" \
157159
"${{ inputs.pip-extra-index-url }}" \
158160
"${{ inputs.install-deps-command }}"
@@ -163,7 +165,6 @@ runs:
163165
# Build each file using the script
164166
export GITHUB_ACTION_PATH=/github/action
165167
/github/action/build_with_pyinstaller.sh \
166-
"python${{ inputs.python-version }}" \
167168
"${{ inputs.target-platform }}" \
168169
"${{ inputs.output-dir }}" \
169170
"${{ inputs.scripts }}" \
@@ -197,31 +198,48 @@ runs:
197198
export DEBIAN_FRONTEND=noninteractive &&
198199
export TZ=UTC &&
199200
apt-get update -y &&
200-
apt-get install -y software-properties-common curl &&
201-
add-apt-repository -y ppa:deadsnakes/ppa &&
202-
apt-get update -y &&
203-
apt-get install -y python${{ inputs.python-version }} python${{ inputs.python-version }}-dev pkg-config gcc g++ patchelf binutils zlib1g-dev &&
204-
curl -sS https://bootstrap.pypa.io/get-pip.py | python${{ inputs.python-version }} &&
205-
python${{ inputs.python-version }} -m pip install --upgrade pip setuptools wheel &&
201+
apt-get install -y curl git build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev pkg-config gcc g++ patchelf binutils &&
202+
curl -LsSf https://astral.sh/uv/install.sh | sh &&
203+
source /root/.local/bin/env &&
204+
# Install Python version using uv
205+
uv python install ${{ inputs.python-version }} &&
206+
# Create and activate virtual environment
207+
uv venv &&
208+
source .venv/bin/activate &&
209+
# Install UV and upgrade tools
210+
uv pip install --upgrade setuptools wheel &&
206211
207212
export GITHUB_ACTION_PATH=/github/action &&
208213
/github/action/setup_environment.sh \
209-
'python${{ inputs.python-version }}' \
210214
'${{ inputs.pyinstaller-version }}' \
211215
'${{ inputs.pip-extra-index-url }}' \
212216
'${{ inputs.install-deps-command }}' &&
213217
214218
# Execute the build script
215-
/github/action/build_with_pyinstaller.sh 'python${{ inputs.python-version }}' '${{ inputs.target-platform }}' '${{ inputs.output-dir }}' '${{ inputs.scripts }}' '${{ inputs.script-name }}' '${{ inputs.icon-file }}' '/github/action/include_data_dirs.json' '${{ steps.setup-platform.outputs.data-separator }}' '${{ inputs.additional-args }}'
219+
/github/action/build_with_pyinstaller.sh '${{ inputs.target-platform }}' '${{ inputs.output-dir }}' '${{ inputs.scripts }}' '${{ inputs.script-name }}' '${{ inputs.icon-file }}' '/github/action/include_data_dirs.json' '${{ steps.setup-platform.outputs.data-separator }}' '${{ inputs.additional-args }}'
216220
"
217221
222+
- name: Install UV
223+
if: |
224+
steps.setup-platform.outputs.needs-docker == 'false' && steps.setup-platform.outputs.needs-arm-emulation == 'false'
225+
uses: astral-sh/setup-uv@v6
226+
with:
227+
enable-cache: true
228+
218229
- name: Setup environment (Native platforms)
219230
if: |
220231
steps.setup-platform.outputs.needs-docker == 'false' && steps.setup-platform.outputs.needs-arm-emulation == 'false'
221232
shell: bash
222233
run: |
234+
# Create and activate virtual environment
235+
uv venv
236+
if [ "${{ inputs.target-platform }}" == 'windows-amd64' ]; then
237+
source .venv\\Scripts\\activate
238+
else
239+
source .venv/bin/activate
240+
fi
241+
223242
$GITHUB_ACTION_PATH/setup_environment.sh \
224-
'python' \
225243
'${{ inputs.pyinstaller-version }}' \
226244
'${{ inputs.pip-extra-index-url }}' \
227245
'${{ inputs.install-deps-command }}'
@@ -232,7 +250,7 @@ runs:
232250
id: build
233251
shell: bash
234252
run: |
235-
$GITHUB_ACTION_PATH/build_with_pyinstaller.sh 'python' '${{ inputs.target-platform }}' '${{ inputs.output-dir }}' '${{ inputs.scripts }}' '${{ inputs.script-name }}' '${{ inputs.icon-file }}' '${{ inputs.include-data-dirs }}' '${{ steps.setup-platform.outputs.data-separator }}' '${{ inputs.additional-args }}'
253+
$GITHUB_ACTION_PATH/build_with_pyinstaller.sh '${{ inputs.target-platform }}' '${{ inputs.output-dir }}' '${{ inputs.scripts }}' '${{ inputs.script-name }}' '${{ inputs.icon-file }}' '${{ inputs.include-data-dirs }}' '${{ steps.setup-platform.outputs.data-separator }}' '${{ inputs.additional-args }}'
236254
237255
echo "success=true" >> $GITHUB_OUTPUT
238256

build_with_pyinstaller.sh

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
#!/bin/bash
22

33
# Build Python scripts with PyInstaller
4-
# Usage: ./build_with_pyinstaller.sh [python_version] [target_platform] [output_dir] [scripts] [script_names] [icon_file] [include_data_dirs] [data_separator] [additional_args]
4+
# Usage: ./build_with_pyinstaller.sh [target_platform] [output_dir] [scripts] [script_names] [icon_file] [include_data_dirs] [data_separator] [additional_args]
55

66
set -e
77

88
# Parse arguments
9-
PYTHON_VERSION="${1:-python}"
10-
TARGET_PLATFORM="${2}"
11-
OUTPUT_DIR="${3}"
12-
SCRIPTS="${4}"
13-
SCRIPT_NAMES="${5}"
14-
ICON_FILE="${6}"
15-
INCLUDE_DATA_DIRS="${7}"
16-
DATA_SEPARATOR="${8}"
17-
ADDITIONAL_ARGS="${9}"
9+
TARGET_PLATFORM="${1}"
10+
OUTPUT_DIR="${2}"
11+
SCRIPTS="${3}"
12+
SCRIPT_NAMES="${4}"
13+
ICON_FILE="${5}"
14+
INCLUDE_DATA_DIRS="${6}"
15+
DATA_SEPARATOR="${7}"
16+
ADDITIONAL_ARGS="${8}"
1817

1918
echo "Building with PyInstaller..."
20-
echo "Python version: $PYTHON_VERSION"
2119
echo "Target platform: $TARGET_PLATFORM"
2220
echo "Output directory: $OUTPUT_DIR"
2321
echo "Scripts: $SCRIPTS"
@@ -32,7 +30,7 @@ for i in "${!PYTHON_FILES[@]}"; do
3230
echo "Building $file for $TARGET_PLATFORM..."
3331

3432
# Start building the command
35-
cmd="$PYTHON_VERSION -m PyInstaller --onefile --distpath=$OUTPUT_DIR"
33+
cmd="uv run pyinstaller --onefile --distpath=$OUTPUT_DIR"
3634

3735
# Add custom name if provided
3836
if [ -n "$SCRIPT_NAMES" ] && [ $i -lt ${#SCRIPT_NAMES_ARRAY[@]} ]; then
@@ -51,7 +49,7 @@ for i in "${!PYTHON_FILES[@]}"; do
5149
# Add include-data-dirs using Python script
5250
if [ -n "$INCLUDE_DATA_DIRS" ]; then
5351
echo "Processing include-data-dirs for $file..."
54-
include_flags=$($PYTHON_VERSION $GITHUB_ACTION_PATH/process_include_dirs.py "$INCLUDE_DATA_DIRS" "$DATA_SEPARATOR" "$file")
52+
include_flags=$(uv run python $GITHUB_ACTION_PATH/process_include_dirs.py "$INCLUDE_DATA_DIRS" "$DATA_SEPARATOR" "$file")
5553
echo "Include flags result: '$include_flags'"
5654
if [ -n "$include_flags" ]; then
5755
cmd="$cmd $include_flags"

setup_environment.sh

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,33 @@
11
#!/bin/bash
22

33
# Setup Python environment for PyInstaller builds
4-
# Usage: ./setup_environment.sh [python_version] [pyinstaller_version] [pip_extra_index_url] [install_deps_command]
4+
# Usage: ./setup_environment.sh [pyinstaller_version] [extra_index_url] [install_deps_command]
55

66
set -e
77

8-
PYTHON_VERSION="${1:-python}"
9-
PYINSTALLER_VERSION="${2:-6.11.1}"
10-
PIP_EXTRA_INDEX_URL="${3:-}"
11-
INSTALL_DEPS_COMMAND="${4:-pip install --user --prefer-binary -e .}"
8+
PYINSTALLER_VERSION="${1:-6.11.1}"
9+
EXTRA_INDEX_URL="${2:-}"
10+
INSTALL_DEPS_COMMAND="${3:-uv pip install -e .}"
1211

1312
echo "Setting up Python environment..."
14-
echo "Python version: $PYTHON_VERSION"
1513
echo "PyInstaller version: $PYINSTALLER_VERSION"
1614

17-
# Set pip extra index if provided
18-
if [ -n "$PIP_EXTRA_INDEX_URL" ]; then
19-
export PIP_EXTRA_INDEX_URL="$PIP_EXTRA_INDEX_URL"
20-
echo "Using extra pip index: $PIP_EXTRA_INDEX_URL"
15+
# Set Python package extra index if provided
16+
if [ -n "$EXTRA_INDEX_URL" ]; then
17+
export UV_INDEX="$EXTRA_INDEX_URL"
18+
export UV_INDEX_STRATEGY="unsafe-best-match"
19+
echo "Using extra Python package index: $EXTRA_INDEX_URL"
2120
fi
2221

2322
# Install PyInstaller
2423
if [ -z "$PYINSTALLER_VERSION" ]; then
25-
$PYTHON_VERSION -m pip install pyinstaller
24+
uv pip install pyinstaller
2625
else
27-
$PYTHON_VERSION -m pip install pyinstaller==$PYINSTALLER_VERSION
26+
uv pip install pyinstaller==$PYINSTALLER_VERSION
2827
fi
2928

3029
# Install dependencies
3130
echo "Installing project dependencies..."
32-
$PYTHON_VERSION -m $INSTALL_DEPS_COMMAND
31+
$INSTALL_DEPS_COMMAND
3332

3433
echo "Environment setup completed successfully"

0 commit comments

Comments
 (0)