Skip to content

Commit 46df5e4

Browse files
authored
Merge pull request #892 from mlco2/copilot/fix-887
Remove Hatch completely and replace with UV + setuptools
2 parents 66dfe9d + 619d041 commit 46df5e4

28 files changed

Lines changed: 43 additions & 2402 deletions

.conda/recipe.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ requirements:
2525
host:
2626
- python
2727
- pip
28-
- hatchling
28+
- setuptools
29+
- wheel
2930
run:
3031
# Will be replaced by the dependencies from the pyproject.toml file
3132
- dependencies

.github/copilot-instructions.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ Here's what you need to know to navigate and contribute effectively.
4141
- **docs/** - Sphinx documentation (build with `uv run task docs`)
4242
- **examples/** - Usage examples and demos
4343
- **deploy/** - Deployment configurations and scripts
44-
- **requirements/** - Dependency specifications for different environments
4544

4645
## Development Setup
4746

@@ -149,7 +148,6 @@ uv run task -l
149148
- **pyproject.toml**: Main project configuration
150149
- **.codecarbon.config**: Runtime configuration for API connection
151150
- **docker-compose.yml**: Local development with PostgreSQL
152-
- **requirements/**: Pinned dependencies for different environments
153151

154152
## Documentation and Help
155153

.github/workflows/package.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ jobs:
2020
run: uv python install 3.12
2121
- name: Check versions
2222
run: |
23-
uv pip install --system requests
24-
python3 .github/check_version.py -o
23+
uv run python .github/check_version.py -o
2524
- name: Build pip package
2625
run: |
2726
uv build

.github/workflows/python-publish.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ jobs:
2323
run: uv python install 3.12
2424
- name: Check versions
2525
run: |
26-
uv pip install --system requests
27-
python3 .github/check_version.py
26+
uv run python .github/check_version.py
2827
- name: Build package
2928
run: uv build
3029
- name: Publish package

CONTRIBUTING.md

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,9 @@ To test CodeCarbon, it is useful to stress your computer to make it use its full
144144
<!-- TOC --><a name="update-all-dependancies"></a>
145145
### Update all dependancies
146146

147-
```sh
148-
uv pip compile requirements.in -o requirements.txt
149-
```
150-
151147
For multiple requirement files:
152-
153148
```sh
154-
uv pip compile requirements/dev.in -o requirements/dev.txt
155-
uv pip compile requirements/test.in -o requirements/test.txt
149+
uv sync --upgrade
156150
```
157151

158152
<!-- TOC --><a name="branching-and-pull-requests"></a>
@@ -256,7 +250,7 @@ You can also run `pre-commit` with `uv run pre-commit run -v` if you have some c
256250
Dependencies are defined in different places:
257251

258252
- In [pyproject.toml](pyproject.toml#L28), those are all the dependencies.
259-
- In [requirements.txt](requirements.txt) and [requirements/](requirements/), those are locked dependencies managed by [Hatch plugin pip-compile](https://github.com/juftin/hatch-pip-compile), do not edit them.
253+
- In [uv.lock](uv.lock), those are the locked dependencies managed by UV, do not edit them.
260254
- In [.conda/meta.yaml](.conda/meta.yaml#L21), those are the dependencies for the Conda pacakge targeting Python 3.7 and higher versions.
261255

262256

@@ -268,8 +262,8 @@ To make generating documentation easier, we use [`sphinx` package](https://www.s
268262

269263
In order to make changes, edit the `.rst` files that are in the `/docs/edit` folder, and then run in root folder:
270264

271-
```
272-
uv run docs
265+
```sh
266+
uv run --only-group doc task docs
273267
```
274268

275269
to regenerate the html files.
@@ -281,8 +275,6 @@ to regenerate the html files.
281275
- Create a PR bumping the version with `uv run bumpver update --patch`. For a release candidate, use `uv run bumpver update --set-version 3.0.0_rc1`.
282276
- Run `uv run python3 .github/check_version.py` to check version consistancy.
283277
- Update the dependencies with `uv sync --upgrade`
284-
- Export a requirements.txt `uv pip freeze > requirements.txt`.
285-
- Keep pre-commit up-to-date with `uv run task precommit-update`.
286278
- [Build Documentation](#documentation) with `uv run --only-group doc task docs`.
287279
- Push the changes.
288280
- Merge the PR.
@@ -299,13 +291,11 @@ Start a Docker image in the same directory and bind-mount the current directory
299291

300292
Inside the docker container, run:
301293

302-
- `conda install -y conda-build conda-verify conda-forge::hatchling`
294+
- `conda install -y conda-build conda-verify`
303295
- `cd /data && mkdir -p /conda_dist`
304296
- `conda build --python 3.11 .conda/ -c conda-forge --output-folder /conda_dist`
305297
- `anaconda upload --user codecarbon /conda_dist/noarch/codecarbon-*.tar.bz2`
306298

307-
308-
309299
<!-- TOC --><a name="api-and-dashboard"></a>
310300
## API and Dashboard
311301

carbonserver/tests/TESTING.md

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# Testing the carbon server
22

3-
4-
## Behaviors to test :
5-
3+
## Behaviors to test
64

75
### Domain logic
86
To test the interface exposed by entities, in memory repositories can be used to isolate the domain logic from technical
@@ -29,55 +27,34 @@ To test the interface exposed by entities, in memory repositories can be used to
2927
Domain logic can be tested at a higher level, with more complex setups, in service/use cases tests.
3028
Use case tests mocks repositories returns to focus on
3129

32-
33-
3430
### Routers
3531
To test a router, validation parameters are ensured by pydantic (available on the swagger documentation),
3632
and logic is tested by interfaces.
3733
A Postman collection of requests is available: ```carbonserver/tests/postman/TestCollection.postman_collection.json```.
3834

39-
40-
4135
### Integration
4236
- Database: in the CI, a prod-like database can be used to test features on real data (TODO)
4337
- Code Carbon package: Launch a train scenario (TODO)
4438

45-
4639
## Running the tests:
4740

48-
### Install the test setup
49-
50-
In a virtual environment, install and build the api package:
5141
```bash
52-
git clone git@github.com:mlco2/codecarbon.git
53-
git checkout api
54-
cd carbonserver
55-
python -m setup install
56-
python -m setup build # Verify the build on local environment
57-
pip install -r requirements-dev.txt # Install test dependencies
42+
uv run --extra api task test-api-unit # Unit tests on api
43+
uv run --extra api task test-api-integ # Integration tests
5844
```
5945

60-
61-
### Run tests
62-
```bash
63-
hatch run api:test-unit # Unit tests on api
64-
hatch run api:test-integ # Integration tests
65-
```
66-
67-
6846
To test the HTTP layer, you can also deploy a local instance:
6947

7048
```bash
7149
cd carbonserver/
72-
uvicorn main:app --reload
50+
uv run --extra api uvicorn main:app --reload
7351
```
7452

7553
Swagger documentation is available at http://localhost:8000/docs
7654

7755

7856
### Run locally the CI
7957

80-
8158
To test the full build process, the Github Actions workflow can be executed locally with act ([install available here](https://raw.githubusercontent.com/nektos/act/master/install.sh)):
8259
```bash
8360
# Build patched dockerfile from project root

carbonserver/tests/api/integration/test_api_black_box.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
export CODECARBON_API_URL=http://localhost:8008
44
export DATABASE_URL=postgresql://codecarbon-user:supersecret@localhost:5480/codecarbon_db
55
Then execute the tests:
6-
hatch run api:test-integ
6+
uv run task test-api-integ
77
"""
88

99
import os

codecarbon/data/hardware/cpu_dataset_builder/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ To update the CPU database, you have to run:
44

55
```bash
66
cd codecarbon/data/hardware/cpu_dataset_builder
7-
hatch run pip install playwright beautifulsoup4
8-
hatch run python intel_cpu_scrapper.py
9-
hatch run python amd_cpu_scrapper.py
10-
hatch run python merge_scrapped_cpu_power.py
7+
uv run pip install playwright beautifulsoup4
8+
uv run python intel_cpu_scrapper.py
9+
uv run python amd_cpu_scrapper.py
10+
uv run python merge_scrapped_cpu_power.py
1111
```
1212

1313
Then commit the changes to the CSV files.

codecarbon/data/hardware/cpu_dataset_builder/amd_cpu_scrapper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""
22
This script uses Playwright to scrape AMD CPU data from their website and save it as a CSV file.
33
4-
hatch run pip install playwright
5-
hatch run python amd_cpu_scrapper.py
4+
uv run pip install playwright
5+
uv run python amd_cpu_scrapper.py
66
"""
77

88
import asyncio

codecarbon/data/hardware/cpu_dataset_builder/intel_cpu_scrapper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
This script uses requests and BeautifulSoup to scrape CPU names and their associated TDP values
66
from the Intel ARK website using the advanced filter search URL.
77
8-
hatch run pip install beautifulsoup4
9-
hatch run python intel_cpu_scrapper.py
8+
uv run pip install beautifulsoup4
9+
uv run python intel_cpu_scrapper.py
1010
1111
"""
1212

0 commit comments

Comments
 (0)