Skip to content

Commit ab72f44

Browse files
authored
Sort imports (#491)
1 parent fafa463 commit ab72f44

File tree

13 files changed

+2983
-4100
lines changed

13 files changed

+2983
-4100
lines changed
Lines changed: 39 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,61 @@
1-
# An action for setting up poetry install with caching.
2-
# Using a custom action since the default action does not
3-
# take poetry install groups into account.
4-
# Action code from:
5-
# https://github.com/actions/setup-python/issues/505#issuecomment-1273013236
6-
name: poetry-install-with-caching
7-
description: Poetry install with support for caching of dependency groups.
1+
name: uv-sync-with-caching
2+
description: Install deps with uv, with cache for uv and .venv.
83

94
inputs:
105
python-version:
11-
description: Python version, supporting MAJOR.MINOR only
6+
description: Python version (MAJOR.MINOR)
127
required: true
13-
14-
poetry-version:
15-
description: Poetry version
16-
required: true
17-
8+
uv-version:
9+
description: uv version (optional; defaults to latest)
10+
required: false
11+
default: ""
1812
cache-key:
19-
description: Cache key to use for manual handling of caching
13+
description: Extra cache key salt (e.g., CI job name)
2014
required: true
15+
uv-sync-flags:
16+
description: Extra flags for `uv sync` (e.g., "--all-groups --all-extras")
17+
required: false
18+
default: ""
2119

2220
runs:
2321
using: composite
2422
steps:
2523
- uses: actions/setup-python@v5
26-
name: Setup python ${{ inputs.python-version }}
27-
id: setup-python
24+
name: Setup Python ${{ inputs.python-version }}
2825
with:
2926
python-version: ${{ inputs.python-version }}
3027

31-
- uses: actions/cache@v4
32-
id: cache-bin-poetry
33-
name: Cache Poetry binary - Python ${{ inputs.python-version }}
34-
env:
35-
SEGMENT_DOWNLOAD_TIMEOUT_MIN: "1"
28+
- name: Install uv
29+
uses: astral-sh/setup-uv@v6
3630
with:
37-
path: |
38-
/opt/pipx/venvs/poetry
39-
# This step caches the poetry installation, so make sure it's keyed on the poetry version as well.
40-
key: bin-poetry-${{ runner.os }}-${{ runner.arch }}-py-${{ inputs.python-version }}-${{ inputs.poetry-version }}
41-
42-
- name: Refresh shell hashtable and fixup softlinks
43-
if: steps.cache-bin-poetry.outputs.cache-hit == 'true'
44-
shell: bash
45-
env:
46-
POETRY_VERSION: ${{ inputs.poetry-version }}
47-
PYTHON_VERSION: ${{ inputs.python-version }}
48-
run: |
49-
set -eux
31+
version: ${{ inputs.uv-version }}
5032

51-
# Refresh the shell hashtable, to ensure correct `which` output.
52-
hash -r
53-
54-
# `actions/cache@v3` doesn't always seem able to correctly unpack softlinks.
55-
# Delete and recreate the softlinks pipx expects to have.
56-
rm /opt/pipx/venvs/poetry/bin/python
57-
cd /opt/pipx/venvs/poetry/bin
58-
ln -s "$(which "python$PYTHON_VERSION")" python
59-
chmod +x python
60-
cd /opt/pipx_bin/
61-
ln -s /opt/pipx/venvs/poetry/bin/poetry poetry
62-
chmod +x poetry
63-
64-
# Ensure everything got set up correctly.
65-
/opt/pipx/venvs/poetry/bin/python --version
66-
/opt/pipx_bin/poetry --version
67-
68-
- name: Install poetry
69-
if: steps.cache-bin-poetry.outputs.cache-hit != 'true'
33+
# Use a stable, repo-local cache dir so Actions cache works across runners.
34+
- name: Set uv cache dir
7035
shell: bash
71-
env:
72-
POETRY_VERSION: ${{ inputs.poetry-version }}
73-
PYTHON_VERSION: ${{ inputs.python-version }}
74-
# Install poetry using the python version installed by setup-python step.
75-
run: pipx install "poetry==$POETRY_VERSION" --python '${{ steps.setup-python.outputs.python-path }}' --verbose
36+
run: echo "UV_CACHE_DIR=$GITHUB_WORKSPACE/.uv_cache" >> "$GITHUB_ENV"
7637

77-
- name: Restore pip and poetry cached dependencies
38+
- name: Restore uv and venv caches
7839
uses: actions/cache@v4
79-
env:
80-
SEGMENT_DOWNLOAD_TIMEOUT_MIN: "4"
8140
with:
8241
path: |
83-
~/.cache/pip
84-
~/.cache/pypoetry/virtualenvs
85-
~/.cache/pypoetry/cache
86-
~/.cache/pypoetry/artifacts
42+
./.uv_cache
8743
./.venv
88-
key: py-deps-${{ runner.os }}-${{ runner.arch }}-py-${{ inputs.python-version }}-poetry-${{ inputs.poetry-version }}-${{ inputs.cache-key }}-${{ hashFiles('./poetry.lock') }}
44+
key: >
45+
uv-${{ runner.os }}-${{ runner.arch }}-py-${{ inputs.python-version }}-${{ inputs.cache-key }}-
46+
${{ hashFiles('pyproject.toml') }}-
47+
${{ hashFiles('uv.lock') }}
48+
restore-keys: |
49+
uv-${{ runner.os }}-${{ runner.arch }}-py-${{ inputs.python-version }}-${{ inputs.cache-key }}-
50+
uv-${{ runner.os }}-${{ runner.arch }}-py-${{ inputs.python-version }}-
51+
uv-${{ runner.os }}-${{ runner.arch }}-
52+
53+
- name: Sync dependencies with uv
54+
shell: bash
55+
run: uv sync ${{ inputs.uv-sync-flags }}
56+
57+
- name: Show env info
58+
shell: bash
59+
run: |
60+
uv --version
61+
uv pip list | head -n 50

.github/workflows/clear-and-update-index.yml

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,52 @@ jobs:
77
build:
88
runs-on: ubuntu-latest
99
environment: Indexing
10+
1011
steps:
11-
- uses: actions/checkout@v3
12+
- uses: actions/checkout@v4
1213

13-
- uses: actions/setup-python@v6
14+
- name: Setup Python
15+
uses: actions/setup-python@v5
1416
with:
15-
python-version: '3.11'
17+
python-version: "3.11"
18+
19+
- name: Install uv
20+
uses: astral-sh/setup-uv@v6
1621

17-
- name: Install Poetry
18-
uses: snok/install-poetry@v1
22+
- name: Pin uv cache dir
23+
shell: bash
24+
run: echo "UV_CACHE_DIR=$GITHUB_WORKSPACE/.uv_cache" >> "$GITHUB_ENV"
25+
26+
- name: Restore caches (.venv and uv)
27+
uses: actions/cache@v4
28+
with:
29+
path: |
30+
./.uv_cache
31+
./.venv
32+
key: >
33+
index-${{ runner.os }}-${{ runner.arch }}-py-3.11-
34+
${{ hashFiles('pyproject.toml') }}-
35+
${{ hashFiles('uv.lock') }}
36+
restore-keys: |
37+
index-${{ runner.os }}-${{ runner.arch }}-py-3.11-
38+
index-${{ runner.os }}-${{ runner.arch }}-
1939
20-
- name: Install dependencies
21-
run: poetry install
40+
- name: Sync dependencies
41+
shell: bash
42+
run: uv sync --all-groups --frozen
2243

2344
- name: Clear index
24-
run: poetry run python _scripts/clear_index.py
45+
shell: bash
46+
run: uv run python _scripts/clear_index.py
2547
env:
2648
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
2749
WEAVIATE_URL: ${{ secrets.WEAVIATE_URL }}
2850
WEAVIATE_API_KEY: ${{ secrets.WEAVIATE_API_KEY }}
2951
RECORD_MANAGER_DB_URL: ${{ secrets.RECORD_MANAGER_DB_URL }}
3052

3153
- name: Ingest docs
32-
run: poetry run python backend/ingest.py
54+
shell: bash
55+
run: uv run python backend/ingest.py
3356
env:
3457
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
3558
WEAVIATE_URL: ${{ secrets.WEAVIATE_URL }}

.github/workflows/eval.yml

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,37 @@ jobs:
1212
runs-on: ubuntu-latest
1313
environment: Evaluation
1414
steps:
15-
- name: Checkout repository
16-
uses: actions/checkout@v4
15+
- uses: actions/checkout@v4
1716

18-
- name: Set up Python + Poetry
19-
uses: "./.github/actions/poetry_setup"
17+
- name: Setup Python
18+
uses: actions/setup-python@v5
2019
with:
2120
python-version: "3.11"
22-
poetry-version: "1.7.1"
23-
cache-key: eval
2421

25-
- name: Install dependencies
26-
run: poetry install --with dev
22+
- name: Install uv
23+
uses: astral-sh/setup-uv@v6
24+
25+
- name: Pin uv cache dir
26+
shell: bash
27+
run: echo "UV_CACHE_DIR=$GITHUB_WORKSPACE/.uv_cache" >> "$GITHUB_ENV"
28+
29+
- name: Restore caches (.venv and uv)
30+
uses: actions/cache@v4
31+
with:
32+
path: |
33+
./.uv_cache
34+
./.venv
35+
key: >
36+
eval-${{ runner.os }}-${{ runner.arch }}-py-3.11-
37+
${{ hashFiles('pyproject.toml') }}-
38+
${{ hashFiles('uv.lock') }}
39+
restore-keys: |
40+
eval-${{ runner.os }}-${{ runner.arch }}-py-3.11-
41+
eval-${{ runner.os }}-${{ runner.arch }}-
42+
43+
- name: Sync dependencies (frozen)
44+
shell: bash
45+
run: uv sync --all-groups --frozen
2746

2847
- name: Evaluate
2948
env:
@@ -32,4 +51,4 @@ jobs:
3251
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
3352
WEAVIATE_URL: ${{ secrets.WEAVIATE_URL }}
3453
WEAVIATE_API_KEY: ${{ secrets.WEAVIATE_API_KEY }}
35-
run: poetry run pytest backend/tests/evals
54+
run: uv run pytest backend/tests/evals

.github/workflows/lint.yml

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ on:
66
pull_request:
77

88
env:
9-
POETRY_VERSION: "1.7.1"
10-
11-
# This env var allows us to get inline annotations when ruff has complaints.
9+
# For inline annotations from ruff
1210
RUFF_OUTPUT_FORMAT: github
1311

1412
jobs:
@@ -23,38 +21,48 @@ jobs:
2321
# GitHub rate-limits how many jobs can be running at any one time.
2422
# Starting new jobs is also relatively slow,
2523
# so linting on fewer versions makes CI faster.
26-
python-version:
27-
- "3.11"
24+
python-version: ["3.11"]
25+
2826
steps:
2927
- uses: actions/checkout@v4
3028

31-
- name: Set up Python ${{ matrix.python-version }} + Poetry ${{ env.POETRY_VERSION }}
32-
uses: "./.github/actions/poetry_setup"
29+
- name: Install uv
30+
uses: astral-sh/setup-uv@v6
3331
with:
34-
python-version: ${{ matrix.python-version }}
35-
poetry-version: ${{ env.POETRY_VERSION }}
36-
cache-key: lint
32+
version: "0.8.23"
3733

38-
- name: Check Poetry File
34+
- name: Pin uv cache dir
3935
shell: bash
40-
run: poetry check
41-
42-
- name: Check lock file
43-
shell: bash
44-
run: poetry lock --check
45-
46-
- name: Install dependencies
47-
run: poetry install --with dev
36+
run: echo "UV_CACHE_DIR=$GITHUB_WORKSPACE/.uv_cache" >> "$GITHUB_ENV"
4837

49-
- name: Get .mypy_cache to speed up mypy
50-
uses: actions/cache@v3
51-
env:
52-
SEGMENT_DOWNLOAD_TIMEOUT_MIN: "2"
38+
- name: Restore caches (.venv and uv)
39+
uses: actions/cache@v4
5340
with:
5441
path: |
42+
./.uv_cache
43+
./.venv
5544
./.mypy_cache
56-
key: mypy-lint-${{ runner.os }}-${{ runner.arch }}-py${{ matrix.python-version }}-${{ hashFiles('./poetry.lock') }}
45+
key: >
46+
lint-${{ runner.os }}-${{ runner.arch }}-py-${{ matrix.python-version }}-
47+
${{ hashFiles('pyproject.toml') }}-
48+
${{ hashFiles('uv.lock') }}
49+
restore-keys: |
50+
lint-${{ runner.os }}-${{ runner.arch }}-py-${{ matrix.python-version }}-
51+
lint-${{ runner.os }}-${{ runner.arch }}-
5752
58-
- name: Analysing the code with our lint
53+
# Ensure deps match the lock (fails if lock is stale)
54+
- name: Sync dependencies (frozen)
55+
shell: bash
56+
run: uv sync --all-groups --frozen
57+
58+
- name: Show tool versions
59+
shell: bash
5960
run: |
60-
make lint
61+
uv --version
62+
.venv/bin/python -V
63+
.venv/bin/ruff -V || true
64+
.venv/bin/mypy -V || true
65+
66+
- name: Lint
67+
shell: bash
68+
run: uv run make lint

.github/workflows/update-index.yml

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,48 @@ on:
99
default: false
1010
type: boolean
1111
schedule:
12-
- cron: '0 13 * * 1'
12+
- cron: '0 13 * * 1'
1313

1414
jobs:
1515
build:
1616
runs-on: ubuntu-latest
1717
environment: Indexing
1818
steps:
19-
- uses: actions/checkout@v3
20-
- uses: actions/setup-python@v6
19+
- uses: actions/checkout@v4
20+
21+
- name: Setup Python
22+
uses: actions/setup-python@v5
2123
with:
22-
python-version: '3.11'
23-
- name: Install Poetry
24-
uses: snok/install-poetry@v1
25-
- name: Install dependencies
26-
run: poetry install
24+
python-version: "3.11"
25+
26+
- name: Install uv
27+
uses: astral-sh/setup-uv@v6
28+
29+
- name: Pin uv cache dir
30+
shell: bash
31+
run: echo "UV_CACHE_DIR=$GITHUB_WORKSPACE/.uv_cache" >> "$GITHUB_ENV"
32+
33+
- name: Restore caches (.venv and uv)
34+
uses: actions/cache@v4
35+
with:
36+
path: |
37+
./.uv_cache
38+
./.venv
39+
key: >
40+
update-index-${{ runner.os }}-${{ runner.arch }}-py-3.11-
41+
${{ hashFiles('pyproject.toml') }}-
42+
${{ hashFiles('uv.lock') }}
43+
restore-keys: |
44+
update-index-${{ runner.os }}-${{ runner.arch }}-py-3.11-
45+
update-index-${{ runner.os }}-${{ runner.arch }}-
46+
47+
- name: Sync dependencies
48+
shell: bash
49+
run: uv sync --all-groups --frozen
50+
2751
- name: Ingest docs
28-
run: poetry run python backend/ingest.py
52+
shell: bash
53+
run: uv run python backend/ingest.py
2954
env:
3055
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
3156
WEAVIATE_URL: ${{ secrets.WEAVIATE_URL }}

0 commit comments

Comments
 (0)