Skip to content

Commit 3051232

Browse files
authored
Merge branch 'master' into patch-1
2 parents 320c360 + faf89df commit 3051232

111 files changed

Lines changed: 6707 additions & 1794 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.conda/recipe.yaml

Lines changed: 0 additions & 47 deletions
This file was deleted.

.conda/variants.yaml

Lines changed: 0 additions & 8 deletions
This file was deleted.

.github/pyproject_versions.py

Lines changed: 33 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Read package version in pyproject.toml and replace it in .conda/recipe.yaml
1+
# Read package version in pyproject.toml
22
# Also provides version coherence checking across multiple files
33

44
import argparse
@@ -132,48 +132,10 @@ def get_versions():
132132
}
133133

134134

135-
def replace_in_file(filepath: str, info: dict):
136-
"""
137-
::filepath:: Path to recipe.yaml, with filename
138-
::info:: Dict with information to populate
139-
"""
140-
with open(filepath, "rt") as fin:
141-
meta = fin.read()
142-
# Replace with info from pyproject.toml
143-
if PACKAGE_VERSION not in meta:
144-
raise Exception(f"{PACKAGE_VERSION=} not found in {filepath}")
145-
meta = meta.replace(PACKAGE_VERSION, info["package_version"])
146-
if " - dependencies" not in meta:
147-
raise Exception(f'" - dependencies" not found in {filepath}')
148-
dependencies = ""
149-
for dep in info["dependencies"]:
150-
if "fief-client" in dep:
151-
# Prevent to have unsupported "fief-client[cli]" in dependencies
152-
dependencies += " - fief-client-fastapi\n - yaspin\n"
153-
else:
154-
dependencies += f" - {dep}\n"
155-
meta = meta.replace(" - dependencies", dependencies)
156-
with open(filepath, "wt") as fout:
157-
fout.write(meta)
158-
logging.info(
159-
f"File {filepath} has been updated with informations from pyproject.toml."
160-
)
161-
162-
163-
if __name__ == "__main__":
164-
parser = argparse.ArgumentParser()
165-
parser.add_argument(
166-
"-r",
167-
"--replace",
168-
action="store_true",
169-
help="replace in file",
170-
)
171-
parser.add_argument(
172-
"-f",
173-
"--filename",
174-
type=str,
175-
default=".conda/recipe.yaml",
176-
help="Path to recipe.yaml, with filename",
135+
def main():
136+
"""Main entry point for the script."""
137+
parser = argparse.ArgumentParser(
138+
description="Read package version and check version coherence"
177139
)
178140
parser.add_argument(
179141
"-o",
@@ -187,27 +149,39 @@ def replace_in_file(filepath: str, info: dict):
187149
action="store_true",
188150
help="Check version coherence across all bumpver-managed files",
189151
)
152+
153+
# Parse arguments - all arguments are optional, so this works fine with no args
190154
args = parser.parse_args()
191155

192-
# Check version coherence first if requested or before any operations
156+
# Check version coherence first if requested
193157
if args.check_coherence:
194158
coherence_ok = check_version_coherence()
195159
sys.exit(0 if coherence_ok else 1)
196160

197-
# Always check coherence before doing replacements or showing versions
198-
if not check_version_coherence(quiet=True):
199-
logging.error("Aborting due to version coherence issues.")
161+
# If only_package_version is requested, just print version and exit
162+
if args.only_package_version:
163+
try:
164+
info = get_versions()
165+
print(f'{info["package_version"]}')
166+
sys.exit(0)
167+
except Exception as e:
168+
logging.error(f"Error getting version: {e}")
169+
sys.exit(1)
170+
171+
# Default behavior: check coherence quietly, then show versions
172+
try:
173+
if not check_version_coherence(quiet=True):
174+
logging.error("Aborting due to version coherence issues.")
175+
sys.exit(1)
176+
177+
info = get_versions()
178+
logging.info("Versions:")
179+
print(info) # noqa: T201
180+
sys.exit(0)
181+
except Exception as e:
182+
logging.error(f"Error: {e}")
200183
sys.exit(1)
201184

202-
info = get_versions()
203-
file = args.filename
204-
if args.only_package_version:
205-
print(f'{info["package_version"]}')
206-
exit()
207-
logging.info("Versions :")
208-
print(info) # noqa: T201
209-
if args.replace:
210-
logging.info(f"Replace in {file}")
211-
replace_in_file(file, info)
212-
else:
213-
logging.info("Dry mode, no replace made")
185+
186+
if __name__ == "__main__":
187+
main()

.github/workflows/deploy.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,6 @@ jobs:
2828
tar -xvf clever-tools-${CC_VERSION}_linux.tar.gz
2929
PATH=${PATH}:$(pwd)/clever-tools-${CC_VERSION}_linux
3030
31-
- name: Install uv
32-
uses: astral-sh/setup-uv@caf0cab7a618c569241d31dcd442f54681755d39 # v3.2.4
33-
with:
34-
version: "latest"
35-
36-
- name: Set up Python
37-
run: uv python install 3.12
38-
3931
- name: Login to Clever Cloud
4032
env:
4133
CLEVER_TOKEN: ${{ secrets.CLEVER_TOKEN }}
@@ -46,7 +38,6 @@ jobs:
4638
CLEVER_APP_ID: ${{ secrets.BE_CLEVER_APP_ID_PROD }}
4739
APP_NAME: cc_api_prod
4840
run: |
49-
uv pip compile carbonserver/pyproject.toml > requirements/requirements-api.txt
5041
./clever-tools-latest_linux/clever link $CLEVER_APP_ID
5142
./clever-tools-latest_linux/clever deploy -f
5243

.github/workflows/package.yml

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ jobs:
5959
run: |
6060
# Install the wheel and test dependencies without the source code
6161
uv pip install dist/*.whl
62-
uv pip install pytest pytest-mock requests-mock responses pandas
62+
uv pip install pytest pytest-mock requests-mock responses pandas logfire
6363
- name: Test package integrity
6464
run: |
6565
# Run the package integrity tests to verify all data files are included
@@ -70,48 +70,3 @@ jobs:
7070
# Test that the CLI is functional
7171
codecarbon --help
7272
python -c "from codecarbon import EmissionsTracker; print('✓ Package import successful')"
73-
74-
build-conda:
75-
runs-on: ubuntu-24.04
76-
steps:
77-
- name: Checkout
78-
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
79-
- name: Cache build
80-
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
81-
with:
82-
path: /tmp/conda-bld
83-
key: build-conda-${{ github.sha }}
84-
- name: set version
85-
run: |
86-
python3 .github/pyproject_versions.py --check_coherence --replace
87-
- name: Build conda package
88-
uses: prefix-dev/rattler-build-action@20cb88d3095cc01fa181385021c57f886d624879 # v0.2.16
89-
with:
90-
build-args: --channel codecarbon --channel conda-forge --output-dir /tmp/conda-bld
91-
recipe-path: .conda/recipe.yaml
92-
upload-artifact: false
93-
test-conda:
94-
runs-on: ubuntu-24.04
95-
needs: [ build-conda ]
96-
steps:
97-
# Checkout needed to get github.sha
98-
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
99-
- name: Setup conda
100-
uses: conda-incubator/setup-miniconda@505e6394dae86d6a5c7fbb6e3fb8938e3e863830 # v3.1.1
101-
with:
102-
activate-environment: codecarbon
103-
miniforge-version: latest
104-
python-version: 3.12
105-
use-mamba: true
106-
- name: Restore build
107-
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
108-
with:
109-
path: /tmp/conda-bld
110-
key: build-conda-${{ github.sha }}
111-
fail-on-cache-miss: true
112-
- name: Install package
113-
shell: bash -l {0}
114-
run: mamba install --channel file:///tmp/conda-bld --channel codecarbon codecarbon
115-
- name: Test conda package
116-
shell: bash -l {0}
117-
run: codecarbon --help

.github/workflows/python-publish.yml

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ permissions:
1313
jobs:
1414
deploy-pypi:
1515
runs-on: ubuntu-latest
16+
# Specifying a GitHub environment is optional, but strongly encouraged
17+
environment: pypi
18+
permissions:
19+
# IMPORTANT: this permission is mandatory for Trusted Publishing
20+
id-token: write
1621
steps:
1722
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
1823
- name: Install uv
@@ -27,36 +32,4 @@ jobs:
2732
- name: Build package
2833
run: uv build
2934
- name: Publish package
30-
uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # release/v1
31-
with:
32-
user: __token__
33-
password: ${{ secrets.PYPI_TOKEN }}
34-
publish-to-conda:
35-
runs-on: ubuntu-24.04
36-
needs: [ deploy-pypi ]
37-
steps:
38-
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
39-
- name: Restore build
40-
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
41-
with:
42-
path: /tmp/conda-bld
43-
key: build-conda-${{ github.sha }}
44-
fail-on-cache-miss: true
45-
- uses: conda-incubator/setup-miniconda@505e6394dae86d6a5c7fbb6e3fb8938e3e863830 # v3.1.1
46-
with:
47-
activate-environment: codecarbon
48-
miniforge-version: latest
49-
python-version: 3.12
50-
use-mamba: true
51-
- name: Install package
52-
shell: bash -l {0}
53-
run: mamba install --channel file:///tmp/conda-bld --channel codecarbon codecarbon
54-
- name: Test conda package
55-
shell: bash -l {0}
56-
run: codecarbon --help
57-
- name: Conda upload already build package
58-
shell: bash -l {0}
59-
env:
60-
ANACONDA_API_TOKEN: ${{ secrets.ANACONDA_TOKEN }}
61-
run: |
62-
anaconda upload --user codecarbon /tmp/conda-bld/noarch/codecarbon-*.tar.bz2
35+
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # release/v1.13.0

.github/workflows/test-package.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,7 @@ jobs:
2727
run: uv sync --python ${{ matrix.python-version }}
2828
- name: Test package
2929
run: uv run --python ${{ matrix.python-version }} task test-package
30+
- name: Install carbonboard dependencies
31+
run: uv pip install --python ${{ matrix.python-version }} dash 'dash_bootstrap_components>1.0.0' fire
32+
- name: Test carbonboard visualization
33+
run: uv run --python ${{ matrix.python-version }} pytest -vv tests/test_viz_data.py tests/test_viz_units.py

CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.github/copilot-instructions.md

CONTRIBUTING.md

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ You have a cool idea, but do not know know if it fits with Code Carbon? You can
7070
<!-- TOC --><a name="installation"></a>
7171
### Installation
7272

73-
CodeCarbon is a Python package, to contribute to it, you need to have Python installed on your machine, natively or with [Conda](https://docs.conda.io/projects/conda/en/latest/user-guide/install/), or better, faster, stronger with [UV](https://github.com/astral-sh/uv).
73+
CodeCarbon is a Python package, to contribute to it, you need to have Python installed on your machine, natively or with [UV](https://github.com/astral-sh/uv).
7474

7575
Between April 2024 and July 2025 we use Hatch for managing development environment. Since August 2025 we use UV manages the environments, Python versions, and dependencies - it's a fast, reliable way to work with Python projects.
7676

@@ -258,7 +258,6 @@ Dependencies are defined in different places:
258258

259259
- In [pyproject.toml](pyproject.toml#L28), those are all the dependencies.
260260
- In [uv.lock](uv.lock), those are the locked dependencies managed by UV, do not edit them.
261-
- In [.conda/meta.yaml](.conda/meta.yaml#L21), those are the dependencies for the Conda pacakge targeting Python 3.7 and higher versions.
262261

263262

264263
<!-- TOC --><a name="build-documentation-"></a>
@@ -288,20 +287,6 @@ to regenerate the html files.
288287
- Wait for the Github Action `ReleaseDrafter` to finish running on the merge commit.
289288
- [Edit the Draft release](https://github.com/mlco2/codecarbon/releases/) on Github and give it a tag, `v1.0.0` for the version 1.0.0. Github will automatically create a Git tag for it. Complete help [here](https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository).
290289
- A [Github Action](https://github.com/mlco2/codecarbon/actions) _Upload Python Package_ will be run automaticaly to upload the package.
291-
- For conda, we now have a [feedstock](https://github.com/conda-forge/codecarbon-feedstock/pulls) to publish to Conda-Forge channel.
292-
293-
If you still want to publish to the Anaconda CodeCarbon channel:
294-
295-
Start a Docker image in the same directory and bind-mount the current directory with:
296-
297-
`docker run -ti --rm=true -v $PWD:/data continuumio/anaconda3`.
298-
299-
Inside the docker container, run:
300-
301-
- `conda install -y conda-build conda-verify`
302-
- `cd /data && mkdir -p /conda_dist`
303-
- `conda build --python 3.11 .conda/ -c conda-forge --output-folder /conda_dist`
304-
- `anaconda upload --user codecarbon /conda_dist/noarch/codecarbon-*.tar.bz2`
305290

306291
#### Test the build in Docker
307292

@@ -326,13 +311,15 @@ pytest test_package_integrity.py
326311
To run locally the dashboard application, you can use it out on a sample data file such as the one in `examples/emissions.csv`, and run it with the following command from the code base:
327312

328313
```bash
329-
uv run --extra viz-legacy task carbonboard --filepath="examples/emissions.csv"
314+
uv run --extra carbonboard task carbonboard --filepath="examples/emissions.csv"
330315

331316
# or, if you don't want to use UV
332-
pip install codecarbon["viz"]
317+
pip install codecarbon[carbonboard]
333318
python codecarbon/viz/carbonboard.py --filepath="examples/emissions.csv"
334319
```
335320

321+
> **Note:** The `viz-legacy` extra is deprecated but still works for backwards compatibility. It will be removed in v4.0.0. Please use `carbonboard` instead.
322+
336323
If you have the package installed, you can run the CLI command:
337324

338325
```bash
@@ -390,7 +377,7 @@ api_endpoint = http://localhost:8008
390377
Before using it, you need an experiment_id, to get one, run:
391378

392379
```
393-
codecarbon init
380+
codecarbon login
394381
```
395382

396383
It will ask the API for an experiment_id on the default project and save it to `.codecarbon.config` for you.

GEMINI.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.github/copilot-instructions.md

0 commit comments

Comments
 (0)