Repository navigation
Expand file tree
/
Copy pathaction.yml
More file actions
61 lines (57 loc) · 2.5 KB
/
Copy pathaction.yml
File metadata and controls
61 lines (57 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
name: Set up Python environment
description: >
Set up Python and install the given packages with uv.
Centralises the setup-python + package install pair that every job in this repo
repeats, and quotes requirement specifiers correctly (see below).
inputs:
python-version:
description: Python version for actions/setup-python.
required: false
default: "3.11"
packages:
description: >
Requirement specifiers, space- or newline-separated
(e.g. "yfinance>=0.2.40 openai>=1.0.0"). Leave empty for a job whose
scripts are pure-stdlib.
required: false
default: ""
runs:
using: composite
steps:
# No `cache: pip`. Installs go through uv below, so pip's cache was never
# read — and setup-python keyed it on pyproject.toml, which says nothing
# about the per-job package lists this action actually installs.
- name: Set up Python ${{ inputs.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}
# uv resolves and installs the same PyPI specifiers as pip, several times
# faster: it downloads in parallel and links from its own store instead of
# unpacking every wheel (the pip step was ~20-27s of every job, and the
# generators run ~100 times a day). No uv cache either. Every job installs
# a different package list, so a shared key would only hold whichever job
# saved first, and a cold PyPI download is already about as fast as a
# cache restore.
- name: Set up uv
if: inputs.packages != ''
uses: astral-sh/setup-uv@v6
with:
enable-cache: false
- name: Install ${{ inputs.packages }}
if: inputs.packages != ''
shell: bash
env:
PACKAGES: ${{ inputs.packages }}
run: |
set -euo pipefail
# Piped through xargs rather than interpolated into the command line:
# unquoted `pip install pytest>=7.0` makes the shell read `>=7.0` as a
# redirect, so the package installs UNPINNED and the runner grows a
# junk file named `=7.0`. xargs hands each specifier to uv as one
# argv entry, with no redirection or globbing.
#
# --system installs into the setup-python interpreter above (first
# `python` on PATH), so every later `python …` / `mkdocs` step sees the
# packages exactly as it did with pip. No `pip install --upgrade pip`
# either: nothing calls pip any more.
printf '%s\n' "$PACKAGES" | xargs --no-run-if-empty uv pip install --system