Skip to content

fix(cli): use configured API endpoint and declare option defaults#1145

Merged
inimaz merged 4 commits intomlco2:masterfrom
DiogoRibeiro7:fix/cli-config-and-defaults
Mar 27, 2026
Merged

fix(cli): use configured API endpoint and declare option defaults#1145
inimaz merged 4 commits intomlco2:masterfrom
DiogoRibeiro7:fix/cli-config-and-defaults

Conversation

@DiogoRibeiro7
Copy link
Copy Markdown
Contributor

Description

This PR makes CLI API endpoint usage consistent for the affected commands and keeps the CLI working correctly under Python 3.11.

Changes included:

  • test-api now uses get_api_endpoint()
  • login now uses get_api_endpoint()
  • API token creation now builds its URL from the configured API endpoint
  • the related CLI tests were added/updated to cover custom API endpoint usage
  • the Typer option declarations were adjusted to preserve default behavior without breaking CLI parsing under Python 3.11

Related Issue

No related issue was verified.

Motivation and Context

Some CLI code paths were still using the hardcoded API_URL constant instead of the configured endpoint returned by get_api_endpoint(). This could cause inconsistent behavior when running against a custom CodeCarbon API endpoint.

While validating the change under Python 3.11, the explicit default= values added inside typer.Option(...) caused a CLI parsing regression with the installed Typer/Click stack. This PR keeps the same runtime defaults while removing that compatibility issue.

How Has This Been Tested?

Tested locally under Python 3.11 in a dedicated virtual environment.

Commands run:

  • .venv311/bin/python -m pytest tests/cli/test_cli_main.py
  • CODECARBON_ALLOW_MULTIPLE_RUNS=True .venv311/bin/python -m pytest --ignore=tests/test_viz_data.py -vv -m 'not integ_test' tests/

Results:

  • tests/cli/test_cli_main.py: 15 passed
  • broader non-integration test suite: 1 failed, 302 passed, 20 skipped, 3 deselected

Remaining failure observed during the broader suite:

  • tests/test_cpu_load.py::TestCPULoad::test_cpu_total_power_process
  • failure type: PermissionError from psutil on macOS process inspection
  • this does not appear to be caused by the CLI changes in this PR

Screenshots (if appropriate):

Not applicable.

Types of changes

What types of changes does your code introduce? Put an x in all the boxes that apply:

  • 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)

Checklist:

Go over all the following points, and put an x in all the boxes that apply.

  • 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 CONTRIBUTING.md document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@DiogoRibeiro7 DiogoRibeiro7 requested a review from a team as a code owner March 27, 2026 12:19
Copy link
Copy Markdown
Collaborator

@inimaz inimaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice thanks for this @DiogoRibeiro7! It will make the cli more coherent to get everything from the same get_api_endpoint

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.10%. Comparing base (46e234b) to head (03e8b92).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1145      +/-   ##
==========================================
+ Coverage   83.08%   83.10%   +0.01%     
==========================================
  Files          45       45              
  Lines        4275     4279       +4     
==========================================
+ Hits         3552     3556       +4     
  Misses        723      723              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@inimaz inimaz merged commit 5defee3 into mlco2:master Mar 27, 2026
12 checks passed
@DiogoRibeiro7 DiogoRibeiro7 deleted the fix/cli-config-and-defaults branch March 27, 2026 16:18
@benoit-cty benoit-cty mentioned this pull request Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants