Skip to content

Commit b8550b0

Browse files
authored
Merge pull request #815 from mlco2/feat/switch_to_uv
Switch from Hatch to UV
2 parents 9722956 + 7f3c3ce commit b8550b0

9 files changed

Lines changed: 8014 additions & 283 deletions

File tree

.github/workflows/build-server.yml

Lines changed: 31 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
name: build server
2-
32
on:
43
pull_request:
54
paths:
@@ -10,27 +9,21 @@ on:
109
- "carbonserver/**"
1110
- "pyproject.toml"
1211
branches: [master]
13-
1412
jobs:
1513
build_server:
1614
runs-on: ubuntu-latest
1715
steps:
1816
- uses: actions/checkout@v4
19-
- name: Set up Python
20-
uses: actions/setup-python@v5
17+
- name: Install uv
18+
uses: astral-sh/setup-uv@v3
2119
with:
22-
python-version: 3.12
23-
- name: Clean pip cache
24-
run: pip cache purge
20+
version: "latest"
21+
- name: Set up Python
22+
run: uv python install 3.12
2523
- name: Install dependencies
26-
run: |
27-
python -m pip install --upgrade pip
28-
24+
run: uv sync --extra api
2925
- name: Unit tests on api
30-
run: |
31-
pip install hatch==1.13.0 hatchling==1.25.0
32-
hatch run api:test-unit
33-
26+
run: uv run task test-api-unit
3427
test_api_server:
3528
runs-on: ubuntu-latest
3629
# Service containers to run with `container-job`
@@ -52,39 +45,29 @@ jobs:
5245
--health-timeout 5s
5346
--health-retries 5
5447
ports:
48+
# Maps tcp port 5432 on service container to the host
5549
- 5480:5432
56-
5750
steps:
58-
# Downloads a copy of the code in your repository before running CI tests
59-
- name: Check out repository code
60-
uses: actions/checkout@v4
61-
62-
# Performs a clean installation of all dependencies
63-
- name: Set up Python
64-
uses: actions/setup-python@v5
65-
with:
66-
python-version: 3.12
67-
- name: Install dependencies
68-
run: |
69-
python -m pip install --upgrade pip
70-
pip install hatch==1.13.0 hatchling==1.25.0
71-
72-
- name: Setup PostgreSQL
73-
# Runs a script that creates a PostgreSQL table, populates
74-
# the table with data, and then retrieves the data.
75-
run: hatch run api:setup-db
76-
77-
env:
78-
# The hostname used to communicate with the PostgreSQL service container
79-
DATABASE_URL: postgresql://codecarbon-user:supersecret@localhost:5480/codecarbon_db
80-
81-
- name: Run API tests
82-
env:
83-
CODECARBON_API_URL: http://localhost:8008
84-
# The hostname used to communicate with the PostgreSQL service container
85-
DATABASE_URL: postgresql://codecarbon-user:supersecret@localhost:5480/codecarbon_db
86-
run: |
87-
# hatch run api:server-ci &
88-
sleep 2
89-
# netstat -o -n -a | grep 8008
90-
# hatch run api:test-integ
51+
- uses: actions/checkout@v4
52+
- name: Install uv
53+
uses: astral-sh/setup-uv@v3
54+
with:
55+
version: "latest"
56+
- name: Set up Python
57+
run: uv python install 3.12
58+
- name: Install dependencies
59+
run: uv sync --extra api
60+
- name: Setup database
61+
env:
62+
DATABASE_URL: postgresql://codecarbon-user:supersecret@localhost:5480/codecarbon_db
63+
run: uv run task setup-db
64+
- name: Integration tests on api
65+
env:
66+
CODECARBON_API_URL: http://localhost:8008
67+
DATABASE_URL: postgresql://codecarbon-user:supersecret@localhost:5480/codecarbon_db
68+
run: |
69+
# uv run task dashboard-ci &
70+
# sleep 10 # wait for server to start
71+
# netstat -o -n -a | grep 8008
72+
# uv run task test-api-integ
73+
echo "Integration tests temporarily disabled - need to fix server startup"

.github/workflows/package.yml

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,52 @@
11
name: package
2-
32
on:
43
push:
54
paths:
65
- "codecarbon/**"
76
- "pyproject.toml"
87
branches: [master]
9-
108
jobs:
119
build-package:
1210
runs-on: ubuntu-latest
1311
steps:
1412
- uses: actions/checkout@v4
15-
- name: Set up Python
16-
uses: actions/setup-python@v5
13+
- name: Install uv
14+
uses: astral-sh/setup-uv@v3
1715
with:
18-
python-version: 3.12
16+
version: "latest"
17+
- name: Set up Python
18+
run: uv python install 3.12
1919
- name: Check versions
2020
run: |
21-
pip install -U pip requests
21+
uv pip install --system requests
2222
python3 .github/check_version.py -o
2323
- name: Build pip package
2424
run: |
25-
pip install -U pip build
26-
python3 -m build
25+
uv build
2726
- name: Archive Pypi artifacts
2827
uses: actions/upload-artifact@v4
2928
with:
3029
name: pypi_dist
3130
path: dist
32-
3331
python-test:
3432
runs-on: ubuntu-24.04
3533
strategy:
3634
matrix:
3735
python-version: ["3.9", "3.12", "3.13"]
3836
steps:
3937
- uses: actions/checkout@v4
38+
- name: Install uv
39+
uses: astral-sh/setup-uv@v3
40+
with:
41+
version: "latest"
4042
- name: Set up Python ${{ matrix.python-version }}
4143
uses: actions/setup-python@v5
4244
with:
4345
python-version: ${{ matrix.python-version }}
4446
- name: Install dependencies
45-
run: |
46-
python -m pip install --upgrade pip
47-
pip install hatch==1.13.0 hatchling==1.25.0
47+
run: uv sync
4848
- name: Test package
49-
run: |
50-
hatch run +py=${{ matrix.python-version }} test:package
51-
49+
run: uv run task test-package
5250
build-conda:
5351
runs-on: ubuntu-24.04
5452
steps:
@@ -68,7 +66,6 @@ jobs:
6866
build-args: --channel codecarbon --channel conda-forge --output-dir /tmp/conda-bld
6967
recipe-path: .conda/recipe.yaml
7068
upload-artifact: false
71-
7269
test-conda:
7370
runs-on: ubuntu-24.04
7471
needs: [ build-conda ]
Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,37 @@
11
# This workflow will upload a Python Package using Twine when a release is created
22
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
3-
43
# This workflow uses actions that are not certified by GitHub.
54
# They are provided by a third-party and are governed by
65
# separate terms of service, privacy policy, and support
76
# documentation.
8-
97
name: Upload Python Package
10-
118
on:
129
release:
1310
types: [published]
14-
1511
permissions:
1612
contents: read
17-
1813
jobs:
1914
deploy-pypi:
2015
runs-on: ubuntu-latest
2116
steps:
2217
- uses: actions/checkout@v4
23-
- name: Set up Python
24-
uses: actions/setup-python@v5
18+
- name: Install uv
19+
uses: astral-sh/setup-uv@v3
2520
with:
26-
python-version: 3.12
21+
version: "latest"
22+
- name: Set up Python
23+
run: uv python install 3.12
2724
- name: Check versions
2825
run: |
29-
pip install -U pip requests
26+
uv pip install --system requests
3027
python3 .github/check_version.py
31-
- name: Install dependencies
32-
run: |
33-
python -m pip install --upgrade pip
34-
pip install hatch==1.13.0 hatchling==1.25.0
3528
- name: Build package
36-
run: hatch build -c
29+
run: uv build
3730
- name: Publish package
3831
uses: pypa/gh-action-pypi-publish@release/v1
3932
with:
4033
user: __token__
4134
password: ${{ secrets.PYPI_TOKEN }}
42-
4335
publish-to-conda:
4436
runs-on: ubuntu-24.04
4537
needs: [ deploy-pypi ]
@@ -64,8 +56,8 @@ jobs:
6456
shell: bash -l {0}
6557
run: codecarbon --help
6658
- name: Conda upload already build package
67-
# This shell is made necessary by https://github.com/conda-incubator/setup-miniconda/issues/128
6859
shell: bash -l {0}
60+
env:
61+
ANACONDA_API_TOKEN: ${{ secrets.ANACONDA_TOKEN }}
6962
run: |
70-
conda install --yes anaconda-client
71-
anaconda -t ${{ secrets.ANACONDA_TOKEN }} upload --user codecarbon /tmp/conda-bld/noarch/codecarbon-*
63+
anaconda upload --user codecarbon /tmp/conda-bld/noarch/codecarbon-*.tar.bz2

.github/workflows/test-package.yml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
paths:
66
- "codecarbon/**"
77
- "pyproject.toml"
8-
- "requirements.txt"
8+
- "uv.lock"
99

1010
jobs:
1111
python-test:
@@ -15,14 +15,13 @@ jobs:
1515
python-version: ["3.9", "3.12", "3.13"]
1616
steps:
1717
- uses: actions/checkout@v4
18-
- name: Set up Python ${{ matrix.python-version }}
19-
uses: actions/setup-python@v5
18+
- name: Install uv
19+
uses: astral-sh/setup-uv@v3
2020
with:
21-
python-version: ${{ matrix.python-version }}
21+
version: "latest"
22+
- name: Set up Python ${{ matrix.python-version }}
23+
run: uv python install ${{ matrix.python-version }}
2224
- name: Install dependencies
23-
run: |
24-
python -m pip install --upgrade pip
25-
pip install hatch==1.13.0 hatchling==1.25.0
25+
run: uv sync --python ${{ matrix.python-version }}
2626
- name: Test package
27-
run: |
28-
hatch run +py=${{ matrix.python-version }} test:package
27+
run: uv run --python ${{ matrix.python-version }} task test-package

0 commit comments

Comments
 (0)