Skip to content

Commit 4462829

Browse files
benoit-ctybenoit-cty
andauthored
Better support for carbonboard (#1014)
Co-authored-by: benoit-cty <anne@onyme.fr>
1 parent c7e7bc3 commit 4462829

File tree

6 files changed

+67
-49
lines changed

6 files changed

+67
-49
lines changed

.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

CONTRIBUTING.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,13 +326,15 @@ pytest test_package_integrity.py
326326
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:
327327

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

331331
# or, if you don't want to use UV
332-
pip install codecarbon["viz"]
332+
pip install codecarbon[carbonboard]
333333
python codecarbon/viz/carbonboard.py --filepath="examples/emissions.csv"
334334
```
335335

336+
> **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.
337+
336338
If you have the package installed, you can run the CLI command:
337339

338340
```bash

codecarbon/viz/carbonboard.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,32 @@
1-
import dash
2-
import dash_bootstrap_components as dbc
3-
import fire
1+
import sys
2+
3+
try:
4+
import dash
5+
import dash_bootstrap_components as dbc
6+
except ImportError:
7+
print(
8+
"\n❌ Error: Carbonboard requires additional dependencies that are not installed.\n"
9+
"\nTo install them, run:\n"
10+
" pip install codecarbon[carbonboard]\n"
11+
"\nOr if using uv:\n"
12+
" uv pip install codecarbon[carbonboard]\n",
13+
file=sys.stderr,
14+
)
15+
sys.exit(1)
16+
17+
try:
18+
import fire
19+
except ImportError:
20+
print(
21+
"\n❌ Error: Carbonboard requires 'fire' which is not installed.\n"
22+
"\nTo install it, run:\n"
23+
" pip install codecarbon[carbonboard]\n"
24+
"\nOr if using uv:\n"
25+
" uv pip install codecarbon[carbonboard]\n",
26+
file=sys.stderr,
27+
)
28+
sys.exit(1)
29+
430
import pandas as pd
531
from dash import dash_table as dt
632
from dash import dcc

docs/edit/visualize.rst

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@ Offline
88
The package also comes with a ``Dash App`` containing illustrations to understand the emissions logged from various experiments across projects.
99
The App currently consumes logged information from a CSV file, generated from an in-built logger in the package.
1010

11+
Installation
12+
~~~~~~~~~~~~
13+
The carbonboard visualization tool requires additional dependencies. Install them with:
14+
15+
.. code-block:: bash
16+
17+
pip install codecarbon[carbonboard]
18+
19+
.. note::
20+
The ``viz-legacy`` extra is deprecated but still works for backwards compatibility. It will be removed in v4.0.0. Please use ``carbonboard`` instead.
21+
22+
Usage
23+
~~~~~
1124
The App can be run by executing the below CLI command that needs following arguments:
1225

1326
- ``filepath`` - path to the CSV file containing logged information across experiments and projects
@@ -107,6 +120,5 @@ The app also provides a visualization of regional carbon intensity of electricit
107120
:alt: carbon intensity carbon_map
108121
:width: 750px
109122

110-
Note that for now, all data sent to CodeCarbon API are public.
111123

112124

pyproject.toml

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,22 +98,16 @@ doc = [
9898
]
9999

100100
[project.optional-dependencies]
101-
viz-legacy = [
101+
carbonboard = [
102102
"dash",
103103
"dash_bootstrap_components > 1.0.0",
104104
"fire",
105105
]
106-
107-
viz = [
108-
"mock",
109-
"pytest",
110-
"responses",
111-
"numpy<2.0.0;python_version<'3.9'",
112-
"numpy;python_version>='3.9'",
113-
"psutil",
114-
"requests-mock",
115-
"rapidfuzz",
116-
"importlib_resources;python_version<'3.9'"
106+
# Backwards compatibility alias - will be removed in v4.0.0
107+
viz-legacy = [
108+
"dash",
109+
"dash_bootstrap_components > 1.0.0",
110+
"fire",
117111
]
118112
api = [
119113
"alembic<2.0.0",

uv.lock

Lines changed: 11 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)