Skip to content

fix(cli): handle missing [codecarbon] section and write api_endpoint via ConfigParser - #1433

Open
sohammishra864-wq wants to merge 1 commit into
mlco2:masterfrom
sohammishra864-wq:fix/cli-config-section
Open

sohammishra864-wq wants to merge 1 commit into
mlco2:masterfrom
sohammishra864-wq:fix/cli-config-section

Conversation

@sohammishra864-wq

@sohammishra864-wq sohammishra864-wq commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Description

  • get_config() now returns {} instead of None when the config file has no [codecarbon] section.
  • get_api_endpoint() now sets the default api_endpoint through ConfigParser instead of raw-appending a line, so it always lands under [codecarbon].

Related Issue

Fixes #1432

Motivation and Context

show_config() crashed with TypeError on a config file that had no [codecarbon] section. get_api_endpoint() wrote the key under the last section of multi-section files, so it was never found and got appended again on every call.

How Has This Been Tested?

Added two tests in tests/cli/test_cli_utils.py. Both fail on master and pass with this change. pytest tests/cli: 76 passed.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

AI Usage Disclosure

  • 🟥 AI-vibecoded
  • 🟠 AI-generated
  • ⭐ AI-assisted
  • ♻️ No AI used

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the docs/how-to/contributing.md document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

get_api_endpoint now writes the default endpoint via ConfigParser so it lands under [codecarbon] instead of the last section. Fixes mlco2#1432.
@sohammishra864-wq
sohammishra864-wq requested a review from a team as a code owner September 29, 2026 14:42

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLI: get_config() returns None without [codecarbon] section; get_api_endpoint() appends api_endpoint under wrong section

1 participant