Skip to content

Commit 3c99b8e

Browse files
committed
1. Moved check-docs-drift.py to tests/ — the script is now at tests/check-docs-drift.py and the CI workflow triggers on changes to that path.
2. Replaced inline save_to_file=False/log_level="error" arguments with environment variables — CODECARBON_SAVE_TO_FILE=false and CODECARBON_LOG_LEVEL=error are now set at the top of the test script, so the doc examples themselves stay clean and uncluttered. 3. Reduced the number of skipped blocks — the task manager example in usage.md was skippable only because it was missing an import; adding from codecarbon import EmissionsTracker made it runnable. The remaining # skip blocks (TensorFlow examples, Comet integration, Prometheus/Logfire output) are unavoidable due to missing dependencies. Skip comments now explain why each block is excluded.
1 parent 70df9ab commit 3c99b8e

7 files changed

Lines changed: 29 additions & 18 deletions

File tree

docs/getting-started/api.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ codecarbon monitor
3333
Or use the API in your code:
3434

3535
```python
36-
# skip
3736
from codecarbon import track_emissions
3837

3938
@track_emissions(save_to_api=True)

docs/getting-started/comet.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ In the
2525
example file, replace the placeholder code with your API key:
2626

2727
```python
28-
# skip
28+
# skip testing this with mkdoctests - would require making comet_ml a doc dependency which is overkill.
2929
experiment = Experiment(api_key="YOUR API KEY")
3030
```
3131

docs/getting-started/examples.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ But you can't get them in your code, see the Context Manager section
1414
below for that.
1515

1616
```python
17-
# skip
17+
# skip mktestdocs testing because a) we would need to add the large tensorflow package as a doc
18+
# dependency, which would slow down CI setup time, b) these snippets do quiet a lot of work which
19+
# would slow things down further.
1820
import tensorflow as tf
1921
from codecarbon import track_emissions
2022

@@ -51,7 +53,9 @@ We think this is the best way to use CodeCarbon. Still only two lines of
5153
code, and you can get the emissions in your code.
5254

5355
```python
54-
# skip
56+
# skip mktestdocs testing because a) we would need to add the large tensorflow package as a doc
57+
# dependency, which would slow down CI setup time, b) these snippets do quiet a lot of work which
58+
# would slow things down further.
5559
import tensorflow as tf
5660

5761
from codecarbon import EmissionsTracker
@@ -98,7 +102,9 @@ background after your computation code has crashed, so your program will
98102
never finish.
99103

100104
```python
101-
# skip
105+
# skip mktestdocs testing because a) we would need to add the large tensorflow package as a doc
106+
# dependency, which would slow down CI setup time, b) these snippets do quiet a lot of work which
107+
# would slow things down further.
102108
import tensorflow as tf
103109

104110
from codecarbon import EmissionsTracker

docs/getting-started/usage.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ tracking of the compute section.
147147

148148
```python
149149
from codecarbon import EmissionsTracker
150-
tracker = EmissionsTracker(save_to_file=False, log_level="error")
150+
tracker = EmissionsTracker()
151151
tracker.start()
152152
try:
153153
# Compute intensive code goes here
@@ -168,14 +168,15 @@ If you want to monitor small piece of code, like a model inference, you
168168
could use the task manager:
169169

170170
```python
171-
# skip
171+
from codecarbon import EmissionsTracker
172+
172173
try:
173174
tracker = EmissionsTracker(project_name="bert_inference", measure_power_secs=10)
174175
tracker.start_task("load dataset")
175-
dataset = load_dataset("imdb", split="test")
176+
# do some data loading
176177
imdb_emissions = tracker.stop_task()
177178
tracker.start_task("build model")
178-
model = build_model()
179+
# build some model
179180
model_emissions = tracker.stop_task()
180181
finally:
181182
_ = tracker.stop()
@@ -197,7 +198,7 @@ The `Emissions tracker` also works as a context manager.
197198
```python
198199
from codecarbon import EmissionsTracker
199200

200-
with EmissionsTracker(save_to_file=False, log_level="error") as tracker:
201+
with EmissionsTracker() as tracker:
201202
_ = 1 + 1 # Compute intensive training code goes here
202203
```
203204

@@ -213,7 +214,7 @@ emissions of the training code.
213214
```python
214215
from codecarbon import track_emissions
215216

216-
@track_emissions(save_to_file=False, log_level="error")
217+
@track_emissions
217218
def training_loop():
218219
# Compute intensive training code goes here
219220
pass
@@ -243,7 +244,7 @@ emissions as follows:
243244

244245
```python
245246
from codecarbon import OfflineEmissionsTracker
246-
tracker = OfflineEmissionsTracker(country_iso_code="CAN", save_to_file=False, log_level="error")
247+
tracker = OfflineEmissionsTracker(country_iso_code="CAN")
247248
tracker.start()
248249
# GPU intensive training code
249250
tracker.stop()
@@ -256,7 +257,7 @@ The `OfflineEmissionsTracker` also works as a context manager
256257
```python
257258
from codecarbon import OfflineEmissionsTracker
258259

259-
with OfflineEmissionsTracker(country_iso_code="CAN", save_to_file=False, log_level="error") as tracker:
260+
with OfflineEmissionsTracker(country_iso_code="CAN") as tracker:
260261
# GPU intensive training code goes here
261262
pass
262263
```
@@ -273,7 +274,7 @@ parameters:
273274

274275
```python
275276
from codecarbon import track_emissions
276-
@track_emissions(offline=True, country_iso_code="CAN", save_to_file=False, log_level="error")
277+
@track_emissions(offline=True, country_iso_code="CAN")
277278
def training_loop():
278279
# training code goes here
279280
pass
@@ -338,7 +339,7 @@ CodeCarbon is structured so that you can configure it in a hierarchical manner:
338339
parameter is set in both:
339340

340341
```python
341-
# skip
342+
# skip this block for mktestdocs testing because it tries to call APIs
342343
EmissionsTracker(
343344
api_call_interval=4,
344345
save_to_api=True,

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Only a few lines of code:
3838
```python
3939
from codecarbon import EmissionsTracker
4040

41-
tracker = EmissionsTracker(save_to_file=False, log_level="error")
41+
tracker = EmissionsTracker()
4242
tracker.start()
4343

4444
# Your code here

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ test-coverage = "CODECARBON_ALLOW_MULTIPLE_RUNS=True pytest --cov --cov-report=x
145145
test-package-integ = "CODECARBON_ALLOW_MULTIPLE_RUNS=True python -m pytest -vv tests/"
146146
docs = "zensical build -f mkdocs.yml"
147147
docs-serve = "zensical serve -f mkdocs.yml"
148-
docs-check-drift = "pytest scripts/check-docs-drift.py -v"
148+
docs-check-drift = "pytest tests/check-docs-drift.py -v"
149149
carbonboard = "python codecarbon/viz/carbonboard.py"
150150

151151
[tool.bumpver]
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,20 @@
44
Blocks whose first line is '# skip' are intentionally excluded
55
(e.g. examples requiring external services or heavy dependencies).
66
7-
Run with: pytest scripts/check-docs-drift.py -v
7+
Run with: pytest tests/check-docs-drift.py -v
88
"""
99

10+
import os
1011
import pathlib
1112

1213
import pytest
1314
from mktestdocs import grab_code_blocks
1415
from mktestdocs.__main__ import exec_python
1516

17+
# Suppress CSV output and log noise when tracker examples run in CI.
18+
os.environ["CODECARBON_SAVE_TO_FILE"] = "false"
19+
os.environ["CODECARBON_LOG_LEVEL"] = "error"
20+
1621

1722
@pytest.mark.parametrize("fpath", pathlib.Path("docs").glob("**/*.md"), ids=str)
1823
def test_doc_file(fpath):

0 commit comments

Comments
 (0)