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

Đang mở Phù hợp với người mới
#1,432 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@sohammishra864-wq đang làm issue này rồi.

Từ ngày 29/9/2026.

  • #1433 của @sohammishra864-wq — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
Nửa ngày
Mức phù hợp với người mới
82/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
cli

Hướng nghiên cứu

Bắt đầu trong codecarbon/cli/cli_utils.py với get_config() và get_api_endpoint(), sau đó so sánh get_api_endpoint() với write_local_exp_id() như đã đề xuất. Tái hiện cả hai trường hợp bằng các lệnh trong issue và xác minh rằng dữ liệu [codecarbon] bị thiếu không còn khiến show_config bị crash, đồng thời api_endpoint được ghi dưới đúng section mà không bị trùng lặp.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Bug 1 — get_config() returns None
If .codecarbon.config exists but has no [codecarbon] section, get_config() implicitly returns None. show_config() then crashes with TypeError: argument of type 'NoneType' is not iterable on "organization_id" not in d.

Repro:

printf "[other]\nkey=value\n" > .codecarbon.config
codecarbon config   # or show_config path

Bug 2 — get_api_endpoint() writes to the wrong section
When api_endpoint is missing, the function raw-appends api_endpoint=... to the end of the file. If [codecarbon] isn't the last section, the key ends up under another section, and the next call appends it again.

Repro:

printf "[codecarbon]\nproject_id=abc\n\n[other]\nkey=value\n" > .codecarbon.config
python -c "from pathlib import Path; from codecarbon.cli.cli_utils import get_api_endpoint; get_api_endpoint(Path('.codecarbon.config'))"
cat .codecarbon.config   # api_endpoint is under [other]

Proposed fix: return {} from get_config(), and set the key through ConfigParser in get_api_endpoint(), as write_local_exp_id() does. I'm happy to open a PR.

Ngôn ngữ chính
Python
Star
1.9k
Fork
347
Merge trung bình
3 ngày 12 giờ
Pull request đã merge (30 ngày)
22

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của mlco2/codecarbon

Tất cả issue của mlco2/codecarbon

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.