Skip to content

Commit 676e0a3

Browse files
colinjcr4victor
andauthored
Migrate to uv for development and CI (#2455)
* Migrate to pyproject.toml * Include server extras in backends extras * Use uv for release workflow * Mention uv sync --all-extras --active * Remove --frozen * Use uv to publish to pypi * Replace pip with uv in actions * Require httpbin to be compatible with Werkzeug 3 --------- Co-authored-by: Victor Skvortsov <vds003@gmail.com>
1 parent 89da219 commit 676e0a3

File tree

10 files changed

+301
-315
lines changed

10 files changed

+301
-315
lines changed

.github/workflows/build.yml

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ name: Build
33
on:
44
push:
55
branches:
6-
- 'master'
6+
- "master"
77
paths-ignore:
8-
- 'docs/**'
9-
- 'mkdocs.yml'
8+
- "docs/**"
9+
- "mkdocs.yml"
1010
pull_request:
1111
branches:
12-
- 'master'
12+
- "master"
1313
workflow_dispatch:
1414
inputs:
1515
intergation-tests:
@@ -56,20 +56,20 @@ jobs:
5656
path: frontend/build
5757

5858
python-test:
59-
needs: [ python-lint, frontend-build ]
59+
needs: [python-lint, frontend-build]
6060
runs-on: ${{ matrix.os }}
6161
strategy:
6262
matrix:
63-
os: [ macos-latest, ubuntu-latest, windows-latest ]
64-
python-version: [ "3.9", "3.10", "3.11", "3.12", "3.13" ]
63+
os: [macos-latest, ubuntu-latest, windows-latest]
64+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
6565
steps:
6666
- uses: actions/checkout@v4
6767
- name: Set up Python ${{ matrix.python-version }}
68-
uses: actions/setup-python@v5
68+
uses: astral-sh/setup-uv@v5
6969
with:
7070
python-version: ${{ matrix.python-version }}
7171
- name: Install dependencies
72-
run: pip install -U '.[all]' -r requirements_dev.txt
72+
run: uv sync --all-extras
7373
- name: Download frontend build
7474
uses: actions/download-artifact@v4
7575
with:
@@ -83,22 +83,26 @@ jobs:
8383
if [ "${{ matrix.os }}" != "macos-latest" ]; then
8484
RUNPOSTGRES="--runpostgres"
8585
fi
86-
pytest src/tests --runui $RUNPOSTGRES
86+
uv run pytest src/tests --runui $RUNPOSTGRES
8787
- name: Run pytest on Windows
8888
if: matrix.os == 'windows-latest'
8989
run: |
90-
pytest src/tests --runui --runpostgres
90+
uv run pytest src/tests --runui --runpostgres
9191
9292
update-get-dstack:
9393
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
94-
needs: [ python-test ]
94+
needs: [python-test]
9595
runs-on: ubuntu-latest
9696
env:
9797
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
9898
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
9999
steps:
100+
- name: Set up uv
101+
uses: astral-sh/setup-uv@v5
102+
with:
103+
python-version: 3.11
100104
- name: Install AWS
101-
run: pip install awscli
105+
run: uv tool install awscli
102106
- run: |
103107
VERSION=$((${{ github.run_number }} + ${{ env.BUILD_INCREMENT }}))
104108
echo $VERSION | aws s3 cp - s3://get-dstack/stgn-cli/latest-version --acl public-read
@@ -181,8 +185,12 @@ jobs:
181185
needs: [runner-compile]
182186
runs-on: ubuntu-latest
183187
steps:
188+
- name: Set up uv
189+
uses: astral-sh/setup-uv@v5
190+
with:
191+
python-version: 3.11
184192
- name: Install AWS
185-
run: pip install awscli
193+
run: uv tool install awscli
186194
- name: Download Runner
187195
uses: actions/download-artifact@v4
188196
with:
@@ -201,24 +209,24 @@ jobs:
201209
202210
generate-json-schema:
203211
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
204-
needs: [ python-test ]
212+
needs: [python-test]
205213
env:
206214
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
207215
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
208216
runs-on: ubuntu-latest
209217
steps:
210218
- uses: actions/checkout@v4
211-
- uses: actions/setup-python@v5
219+
- uses: astral-sh/setup-uv@v5
212220
with:
213221
python-version: 3.11
214222
- name: Install AWS
215-
run: pip install awscli
223+
run: uv tool install awscli
216224
- name: Install dstack
217-
run: pip install .
225+
run: uv sync
218226
- name: Generate json schema
219227
run: |
220-
python -c "from dstack._internal.core.models.configurations import DstackConfiguration; print(DstackConfiguration.schema_json(indent=2))" > configuration.json
221-
python -c "from dstack._internal.core.models.profiles import ProfilesConfig; print(ProfilesConfig.schema_json(indent=2))" > profiles.json
228+
uv run python -c "from dstack._internal.core.models.configurations import DstackConfiguration; print(DstackConfiguration.schema_json(indent=2))" > configuration.json
229+
uv run python -c "from dstack._internal.core.models.profiles import ProfilesConfig; print(ProfilesConfig.schema_json(indent=2))" > profiles.json
222230
- name: Upload json schema to S3
223231
run: |
224232
VERSION=$((${{ github.run_number }} + ${{ env.BUILD_INCREMENT }}))
@@ -235,20 +243,18 @@ jobs:
235243
working-directory: gateway
236244
steps:
237245
- uses: actions/checkout@v4
238-
- name: Set up Python 3.11
239-
uses: actions/setup-python@v5
246+
- name: Set up uv
247+
uses: astral-sh/setup-uv@v5
240248
with:
241249
python-version: 3.11
242250
- name: Install AWS
243-
run: pip install awscli
244-
- name: Install dependencies
245-
run: pip install wheel build
251+
run: uv tool install awscli
246252
- name: Compute version
247253
run: echo VERSION=$((${{ github.run_number }} + ${{ env.BUILD_INCREMENT }})) > $GITHUB_ENV
248254
- name: Build package
249255
run: |
250256
echo "__version__ = \"${{ env.VERSION }}\"" > src/dstack/gateway/version.py
251-
python -m build .
257+
uv build
252258
- name: Upload to S3
253259
env:
254260
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
@@ -257,23 +263,24 @@ jobs:
257263
WHEEL=dstack_gateway-${{ env.VERSION }}-py3-none-any.whl
258264
aws s3 cp dist/$WHEEL "s3://dstack-gateway-downloads/stgn/$WHEEL"
259265
echo "${{ env.VERSION }}" | aws s3 cp - "s3://dstack-gateway-downloads/stgn/latest-version"
260-
266+
261267
docs-build:
262268
# Skip for PRs from forks since mkdocs-material-insiders is not available in forks
263269
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
264270
runs-on: ubuntu-latest
265271
steps:
266272
- uses: actions/checkout@v4
267-
- uses: actions/setup-python@v5
273+
- uses: astral-sh/setup-uv@v5
268274
with:
269275
python-version: 3.11
270276
- name: Install dstack
271277
run: |
272-
pip install -e .[server]
278+
uv sync --extra server
279+
# Move these deps into an extra and install that way
273280
- name: Build
274281
run: |
275-
pip install pillow cairosvg
282+
uv pip install pillow cairosvg
276283
sudo apt-get install -y libcairo2-dev libfreetype6-dev libffi-dev libjpeg-dev libpng-dev libz-dev
277-
pip install mkdocs-material "mkdocs-material[imaging]" mkdocs-material-extensions mkdocs-redirects mkdocs-gen-files "mkdocstrings[python]" mkdocs-render-swagger-plugin --upgrade
278-
pip install git+https://${{ secrets.GH_TOKEN }}@github.com/squidfunk/mkdocs-material-insiders.git
279-
mkdocs build -s
284+
uv pip install mkdocs-material "mkdocs-material[imaging]" mkdocs-material-extensions mkdocs-redirects mkdocs-gen-files "mkdocstrings[python]" mkdocs-render-swagger-plugin --upgrade
285+
uv pip install git+https://${{ secrets.GH_TOKEN }}@github.com/squidfunk/mkdocs-material-insiders.git
286+
uv mkdocs build -s

.github/workflows/docker.yml

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ on:
3434

3535
env:
3636
PACKER_VERSION: "1.9.2"
37-
BUILD_PREFIX: ${{ inputs.staging && format('stgn-{0}-', github.run_number) || '' }} # staging ? prefix : ''
37+
BUILD_PREFIX: ${{ inputs.staging && format('stgn-{0}-', github.run_number) || '' }} # staging ? prefix : ''
3838

3939
jobs:
4040
build-docker:
@@ -45,23 +45,23 @@ jobs:
4545
runs-on: ubuntu-latest
4646
strategy:
4747
matrix:
48-
python: [ "3.9", "3.10", "3.11", "3.12", "3.13" ]
48+
python: ["3.9", "3.10", "3.11", "3.12", "3.13"]
4949
steps:
50-
- name: Checkout repository
51-
uses: actions/checkout@v4
52-
- name: Set up Docker Buildx
53-
uses: docker/setup-buildx-action@v3
54-
- name: Login to DockerHub
55-
uses: docker/login-action@v3
56-
with:
57-
username: ${{ secrets.DOCKERHUB_USERNAME }}
58-
password: ${{ secrets.DOCKERHUB_TOKEN }}
59-
- name: Set up QEMU
60-
uses: docker/setup-qemu-action@v3
61-
- name: Build and upload to DockerHub
62-
run: |
63-
docker buildx build --platform linux/amd64 --build-arg PYTHON=${{ matrix.python }} --push --provenance=false --tag dstackai/base:py${{ matrix.python }}-${{ inputs.image_version }}-cuda-12.1 -f base/Dockerfile .
64-
docker buildx build --platform linux/amd64 --build-arg PYTHON=${{ matrix.python }} --build-arg VERSION=${{ inputs.image_version }} --push --provenance=false --tag dstackai/base:py${{ matrix.python }}-${{ inputs.image_version }}-cuda-12.1-devel -f base/devel.Dockerfile .
50+
- name: Checkout repository
51+
uses: actions/checkout@v4
52+
- name: Set up Docker Buildx
53+
uses: docker/setup-buildx-action@v3
54+
- name: Login to DockerHub
55+
uses: docker/login-action@v3
56+
with:
57+
username: ${{ secrets.DOCKERHUB_USERNAME }}
58+
password: ${{ secrets.DOCKERHUB_TOKEN }}
59+
- name: Set up QEMU
60+
uses: docker/setup-qemu-action@v3
61+
- name: Build and upload to DockerHub
62+
run: |
63+
docker buildx build --platform linux/amd64 --build-arg PYTHON=${{ matrix.python }} --push --provenance=false --tag dstackai/base:py${{ matrix.python }}-${{ inputs.image_version }}-cuda-12.1 -f base/Dockerfile .
64+
docker buildx build --platform linux/amd64 --build-arg PYTHON=${{ matrix.python }} --build-arg VERSION=${{ inputs.image_version }} --push --provenance=false --tag dstackai/base:py${{ matrix.python }}-${{ inputs.image_version }}-cuda-12.1-devel -f base/devel.Dockerfile .
6565
6666
build-aws-images:
6767
needs: build-docker
@@ -75,7 +75,7 @@ jobs:
7575
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
7676
strategy:
7777
matrix:
78-
variant: [ "", "-cuda" ]
78+
variant: ["", "-cuda"]
7979
steps:
8080
- uses: actions/checkout@v4
8181
- name: Download packer
@@ -87,7 +87,7 @@ jobs:
8787
run: |
8888
./packer build -var-file=versions.json $PROD_VARS -var image_version=${{ inputs.image_version }} -var build_prefix=$BUILD_PREFIX aws-image${{ matrix.variant }}.json
8989
env:
90-
PROD_VARS: ${{ !inputs.staging && '-var-file=aws-vars-prod.json' || '' }} # production ? var-file : ''
90+
PROD_VARS: ${{ !inputs.staging && '-var-file=aws-vars-prod.json' || '' }} # production ? var-file : ''
9191

9292
build-azure-images:
9393
needs: build-docker
@@ -104,7 +104,7 @@ jobs:
104104
VERSION: ${{ github.run_number }}
105105
strategy:
106106
matrix:
107-
variant: [ "", "-cuda", "-grid" ]
107+
variant: ["", "-cuda", "-grid"]
108108
steps:
109109
- uses: actions/checkout@v4
110110
- uses: Azure/login@v2
@@ -135,17 +135,17 @@ jobs:
135135
runs-on: ubuntu-latest
136136
strategy:
137137
matrix:
138-
variant: [ "", "-cuda" ]
138+
variant: ["", "-cuda"]
139139
permissions:
140-
contents: 'read'
141-
id-token: 'write'
140+
contents: "read"
141+
id-token: "write"
142142
steps:
143143
- uses: actions/checkout@v4
144144
- name: Authenticate to Google Cloud
145145
uses: google-github-actions/auth@v2
146146
with:
147-
workload_identity_provider: 'projects/531508670106/locations/global/workloadIdentityPools/github-identity-pool/providers/github-id-provider'
148-
service_account: 'github-actions@dstack.iam.gserviceaccount.com'
147+
workload_identity_provider: "projects/531508670106/locations/global/workloadIdentityPools/github-identity-pool/providers/github-id-provider"
148+
service_account: "github-actions@dstack.iam.gserviceaccount.com"
149149
create_credentials_file: true
150150
- name: Set up Cloud SDK
151151
uses: google-github-actions/setup-gcloud@v2
@@ -175,7 +175,7 @@ jobs:
175175
OCI_REGION: eu-frankfurt-1
176176
strategy:
177177
matrix:
178-
variant: [ "", "-cuda" ]
178+
variant: ["", "-cuda"]
179179
steps:
180180
- uses: actions/checkout@v4
181181
- name: Setup OCI config
@@ -211,23 +211,23 @@ jobs:
211211
-var oci_subnet_ocid=$OCI_SUBNET \
212212
-var oci_availability_domain=$OCI_AVAILABILITY_DOMAIN \
213213
oci-image${{ matrix.variant }}.json
214-
- uses: actions/setup-python@v5
214+
- uses: astral-sh/setup-uv@v5
215215
with:
216-
python-version: '3.12'
216+
python-version: "3.12"
217217
- name: Install dependencies for publishing
218218
run: |
219-
pip install .[oci]
219+
uv sync --extra oci
220220
- name: Copy image to target regions
221221
if: ${{ !inputs.staging }}
222222
run: |
223-
python scripts/oci_image_tools.py copy \
223+
uv run scripts/oci_image_tools.py copy \
224224
--image ${BUILD_PREFIX}dstack${{ matrix.variant }}-${{ inputs.image_version }} \
225225
--from $OCI_REGION \
226226
--compartment $OCI_COMPARTMENT
227227
- name: Publish image in OCI Marketplace
228228
if: ${{ !inputs.staging }}
229229
run: |
230-
python scripts/oci_image_tools.py publish \
230+
uv run scripts/oci_image_tools.py publish \
231231
--image ${BUILD_PREFIX}dstack${{ matrix.variant }}-${{ inputs.image_version }} \
232232
--compartment $OCI_COMPARTMENT \
233233
--version ${{ inputs.image_version }} \

.github/workflows/docs.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,23 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- uses: actions/checkout@v4
14-
- uses: actions/setup-python@v5
14+
- uses: astral-sh/setup-uv@v5
1515
with:
1616
python-version: 3.11
1717
- name: Install dstack
1818
run: |
1919
if [ -n "${{ inputs.release_tag }}" ]; then
20-
pip install "dstack[server]==${{ inputs.release_tag }}"
20+
uv pip install "dstack[server]==${{ inputs.release_tag }}"
2121
else
22-
pip install -e .[server]
22+
uv sync --extra server
2323
fi
2424
- name: Build
2525
run: |
26-
pip install pillow cairosvg
26+
uv pip install pillow cairosvg
2727
sudo apt-get install -y libcairo2-dev libfreetype6-dev libffi-dev libjpeg-dev libpng-dev libz-dev
28-
pip install mkdocs-material "mkdocs-material[imaging]" mkdocs-material-extensions mkdocs-redirects mkdocs-gen-files "mkdocstrings[python]" mkdocs-render-swagger-plugin --upgrade
29-
pip install git+https://${{ secrets.GH_TOKEN }}@github.com/squidfunk/mkdocs-material-insiders.git
30-
mkdocs build -s
28+
uv pip install mkdocs-material "mkdocs-material[imaging]" mkdocs-material-extensions mkdocs-redirects mkdocs-gen-files "mkdocstrings[python]" mkdocs-render-swagger-plugin --upgrade
29+
uv pip install git+https://${{ secrets.GH_TOKEN }}@github.com/squidfunk/mkdocs-material-insiders.git
30+
uv mkdocs build -s
3131
- name: Deploy
3232
uses: JamesIves/github-pages-deploy-action@v4.6.4
3333
with:

0 commit comments

Comments
 (0)