feat(cli): add codecarbon badge command - #1357
Open
davidberenstein1957 wants to merge 1 commit into
Open
Conversation
Render a README badge locally from an existing emissions.csv: a flat SVG and a shields.io endpoint JSON, plus the markdown snippet to paste. No network call, no hosted service, no new dependency. The badge is colour-neutral by default. CodeCarbon values are often estimates, and no fixed gram threshold is meaningful across arbitrary workloads, so automatic green/red colouring would be greenwashing. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1357 +/- ##
==========================================
+ Coverage 91.39% 91.55% +0.16%
==========================================
Files 49 50 +1
Lines 5056 5153 +97
==========================================
+ Hits 4621 4718 +97
Misses 435 435 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements #1349.
What it adds
A
codecarbon badgecommand that turns an existingemissions.csvinto README badge artefacts. Strictly local: it reads the CSV, writes files, and prints a snippet. No network call, no hosted service, no account, no new dependency (stdlibcsv,jsonand string templating only).User-facing surface
It writes
codecarbon-badge.svg(a flat shields-style badge from a small string template) andcodecarbon-badge.json(the shields.io endpoint schema, for users who want to publish it themselves), then prints the markdown to paste into a README.The logic lives in
codecarbon/badge.py, whose functions (load_runs,summarise,format_value,render_svg,render_endpoint_json,render,write) are usable directly from Python. The CLI command sits next todetectincodecarbon/cli/main.py. No tracker or output-method changes.Colour-neutral by default. No automatic green/orange/red thresholds. CodeCarbon numbers are frequently estimates (TDP-modelled CPU power, country-average intensity), and no fixed gram threshold means anything across arbitrary workloads, so an automatic green badge would be greenwashing. Users who want a colour pass
--color. The docs say plainly that a badge is an order-of-magnitude signal, not an audited figure.Verification
tests/test_badge.py, 15 tests, no network,tmp_pathfor outputs: project filtering, the three aggregations against hand-computed values, unit formatting from mg to Mg, SVG well-formedness viaxml.etree.ElementTreeplus XML escaping, endpoint JSON schema, clean errors on a missing file and an empty project selection, and twotyper.testing.CliRunnerruns against the real command.black --checkandruff checkwere run scoped to the touched files; formatting is clean and the remaining ruff notes are pre-existing repo-wide style patterns (Optional[...],typer.Optiondefaults) that the surrounding code already uses.Deliberately left out
badge_*config keys from the proposal. Flags only for now; config keys are permanent surface for a command normally run by hand, and can follow if the CI recipe turns out common.Docs: a
codecarbon badgesection indocs/reference/cli.mdand a cross-link fromdocs/how-to/visualize.md.Closes #1349
🤖 Generated with Claude Code