Skip to content

Commit bbbaa9c

Browse files
committed
Merge branch 'master' of github.com:mlco2/codecarbon into feat/codecarbon-run-cli
2 parents 0e7c962 + c4be423 commit bbbaa9c

162 files changed

Lines changed: 7819 additions & 9186 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.conda/recipe.yaml

Lines changed: 0 additions & 47 deletions
This file was deleted.

.conda/variants.yaml

Lines changed: 0 additions & 8 deletions
This file was deleted.

.github/pyproject_versions.py

Lines changed: 33 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Read package version in pyproject.toml and replace it in .conda/recipe.yaml
1+
# Read package version in pyproject.toml
22
# Also provides version coherence checking across multiple files
33

44
import argparse
@@ -132,48 +132,10 @@ def get_versions():
132132
}
133133

134134

135-
def replace_in_file(filepath: str, info: dict):
136-
"""
137-
::filepath:: Path to recipe.yaml, with filename
138-
::info:: Dict with information to populate
139-
"""
140-
with open(filepath, "rt") as fin:
141-
meta = fin.read()
142-
# Replace with info from pyproject.toml
143-
if PACKAGE_VERSION not in meta:
144-
raise Exception(f"{PACKAGE_VERSION=} not found in {filepath}")
145-
meta = meta.replace(PACKAGE_VERSION, info["package_version"])
146-
if " - dependencies" not in meta:
147-
raise Exception(f'" - dependencies" not found in {filepath}')
148-
dependencies = ""
149-
for dep in info["dependencies"]:
150-
if "fief-client" in dep:
151-
# Prevent to have unsupported "fief-client[cli]" in dependencies
152-
dependencies += " - fief-client-fastapi\n - yaspin\n"
153-
else:
154-
dependencies += f" - {dep}\n"
155-
meta = meta.replace(" - dependencies", dependencies)
156-
with open(filepath, "wt") as fout:
157-
fout.write(meta)
158-
logging.info(
159-
f"File {filepath} has been updated with informations from pyproject.toml."
160-
)
161-
162-
163-
if __name__ == "__main__":
164-
parser = argparse.ArgumentParser()
165-
parser.add_argument(
166-
"-r",
167-
"--replace",
168-
action="store_true",
169-
help="replace in file",
170-
)
171-
parser.add_argument(
172-
"-f",
173-
"--filename",
174-
type=str,
175-
default=".conda/recipe.yaml",
176-
help="Path to recipe.yaml, with filename",
135+
def main():
136+
"""Main entry point for the script."""
137+
parser = argparse.ArgumentParser(
138+
description="Read package version and check version coherence"
177139
)
178140
parser.add_argument(
179141
"-o",
@@ -187,27 +149,39 @@ def replace_in_file(filepath: str, info: dict):
187149
action="store_true",
188150
help="Check version coherence across all bumpver-managed files",
189151
)
152+
153+
# Parse arguments - all arguments are optional, so this works fine with no args
190154
args = parser.parse_args()
191155

192-
# Check version coherence first if requested or before any operations
156+
# Check version coherence first if requested
193157
if args.check_coherence:
194158
coherence_ok = check_version_coherence()
195159
sys.exit(0 if coherence_ok else 1)
196160

197-
# Always check coherence before doing replacements or showing versions
198-
if not check_version_coherence(quiet=True):
199-
logging.error("Aborting due to version coherence issues.")
161+
# If only_package_version is requested, just print version and exit
162+
if args.only_package_version:
163+
try:
164+
info = get_versions()
165+
print(f'{info["package_version"]}')
166+
sys.exit(0)
167+
except Exception as e:
168+
logging.error(f"Error getting version: {e}")
169+
sys.exit(1)
170+
171+
# Default behavior: check coherence quietly, then show versions
172+
try:
173+
if not check_version_coherence(quiet=True):
174+
logging.error("Aborting due to version coherence issues.")
175+
sys.exit(1)
176+
177+
info = get_versions()
178+
logging.info("Versions:")
179+
print(info) # noqa: T201
180+
sys.exit(0)
181+
except Exception as e:
182+
logging.error(f"Error: {e}")
200183
sys.exit(1)
201184

202-
info = get_versions()
203-
file = args.filename
204-
if args.only_package_version:
205-
print(f'{info["package_version"]}')
206-
exit()
207-
logging.info("Versions :")
208-
print(info) # noqa: T201
209-
if args.replace:
210-
logging.info(f"Replace in {file}")
211-
replace_in_file(file, info)
212-
else:
213-
logging.info("Dry mode, no replace made")
185+
186+
if __name__ == "__main__":
187+
main()

.github/workflows/build-ui.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ on:
1414
permissions:
1515
contents: read
1616

17+
env:
18+
NODE_VERSION: "24"
19+
1720
jobs:
1821
build-ui:
1922
runs-on: ubuntu-22.04
@@ -22,7 +25,7 @@ jobs:
2225
- name: Use Node.js
2326
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
2427
with:
25-
node-version: "18"
28+
node-version: "${{ env.NODE_VERSION }}"
2629
- name: Setup pnpm
2730
uses: pnpm/action-setup@eae0cfeb286e66ffb5155f1a79b90583a127a68b # v2.4.1
2831
with:

.github/workflows/check-requirements.yml

Lines changed: 0 additions & 51 deletions
This file was deleted.

.github/workflows/package.yml

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -70,48 +70,3 @@ jobs:
7070
# Test that the CLI is functional
7171
codecarbon --help
7272
python -c "from codecarbon import EmissionsTracker; print('✓ Package import successful')"
73-
74-
build-conda:
75-
runs-on: ubuntu-24.04
76-
steps:
77-
- name: Checkout
78-
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
79-
- name: Cache build
80-
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
81-
with:
82-
path: /tmp/conda-bld
83-
key: build-conda-${{ github.sha }}
84-
- name: set version
85-
run: |
86-
python3 .github/pyproject_versions.py --check_coherence --replace
87-
- name: Build conda package
88-
uses: prefix-dev/rattler-build-action@20cb88d3095cc01fa181385021c57f886d624879 # v0.2.16
89-
with:
90-
build-args: --channel codecarbon --channel conda-forge --output-dir /tmp/conda-bld
91-
recipe-path: .conda/recipe.yaml
92-
upload-artifact: false
93-
test-conda:
94-
runs-on: ubuntu-24.04
95-
needs: [ build-conda ]
96-
steps:
97-
# Checkout needed to get github.sha
98-
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
99-
- name: Setup conda
100-
uses: conda-incubator/setup-miniconda@505e6394dae86d6a5c7fbb6e3fb8938e3e863830 # v3.1.1
101-
with:
102-
activate-environment: codecarbon
103-
miniforge-version: latest
104-
python-version: 3.12
105-
use-mamba: true
106-
- name: Restore build
107-
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
108-
with:
109-
path: /tmp/conda-bld
110-
key: build-conda-${{ github.sha }}
111-
fail-on-cache-miss: true
112-
- name: Install package
113-
shell: bash -l {0}
114-
run: mamba install --channel file:///tmp/conda-bld --channel codecarbon codecarbon
115-
- name: Test conda package
116-
shell: bash -l {0}
117-
run: codecarbon --help

.github/workflows/python-publish.yml

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -33,32 +33,3 @@ jobs:
3333
run: uv build
3434
- name: Publish package
3535
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # release/v1.13.0
36-
publish-to-conda:
37-
runs-on: ubuntu-24.04
38-
needs: [ deploy-pypi ]
39-
steps:
40-
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
41-
- name: Restore build
42-
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
43-
with:
44-
path: /tmp/conda-bld
45-
key: build-conda-${{ github.sha }}
46-
fail-on-cache-miss: true
47-
- uses: conda-incubator/setup-miniconda@505e6394dae86d6a5c7fbb6e3fb8938e3e863830 # v3.1.1
48-
with:
49-
activate-environment: codecarbon
50-
miniforge-version: latest
51-
python-version: 3.12
52-
use-mamba: true
53-
- name: Install package
54-
shell: bash -l {0}
55-
run: mamba install --channel file:///tmp/conda-bld --channel codecarbon codecarbon
56-
- name: Test conda package
57-
shell: bash -l {0}
58-
run: codecarbon --help
59-
- name: Conda upload already build package
60-
shell: bash -l {0}
61-
env:
62-
ANACONDA_API_TOKEN: ${{ secrets.ANACONDA_TOKEN }}
63-
run: |
64-
anaconda upload --user codecarbon /tmp/conda-bld/noarch/codecarbon-*.tar.bz2

.github/workflows/test-package.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,13 @@ jobs:
2626
- name: Install dependencies
2727
run: uv sync --python ${{ matrix.python-version }}
2828
- name: Test package
29-
run: uv run --python ${{ matrix.python-version }} task test-package
29+
run: uv run --python ${{ matrix.python-version }} task test-coverage
30+
- name: Upload coverage to Codecov
31+
uses: codecov/codecov-action@v5
32+
with:
33+
token: ${{ secrets.CODECOV_TOKEN }}
34+
35+
- name: Install carbonboard dependencies
36+
run: uv pip install --python ${{ matrix.python-version }} dash 'dash_bootstrap_components>1.0.0' fire
37+
- name: Test carbonboard visualization
38+
run: uv run --python ${{ matrix.python-version }} pytest -vv tests/test_viz_data.py tests/test_viz_units.py

.pre-commit-config.yaml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
repos:
2+
- repo: https://github.com/PyCQA/autoflake
3+
rev: v2.3.1
4+
hooks:
5+
- id: autoflake
6+
args:
7+
[
8+
--in-place,
9+
--remove-unused-variables,
10+
--remove-all-unused-imports,
11+
--expand-star-imports,
12+
]
213
- repo: https://github.com/pycqa/isort
314
rev: 7.0.0
415
hooks:
@@ -14,10 +25,4 @@ repos:
1425
hooks:
1526
- id: flake8
1627
args: ["--config=.flake8"]
17-
additional_dependencies: ['flake8-bugbear==23.9.16']
18-
19-
# removes unused imports and unused variables
20-
- repo: https://github.com/PyCQA/autoflake
21-
rev: v2.3.1
22-
hooks:
23-
- id: autoflake
28+
additional_dependencies: ['flake8-bugbear==23.9.16']

CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.github/copilot-instructions.md

0 commit comments

Comments
 (0)