Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 0 additions & 75 deletions .github/check_version.py

This file was deleted.

126 changes: 120 additions & 6 deletions .github/pyproject_versions.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,113 @@
# Read package version in pyproject.toml and replace it in .conda/recipe.yaml
# Also provides version coherence checking across multiple files

import argparse
import logging
import re
import sys
import tomllib

logging.basicConfig(level=logging.INFO, format="%(message)s")
PACKAGE_VERSION = "X.X.X"


def get_version_from_file(filepath: str, pattern: str) -> str:
"""
Extract version from a file using a regex pattern.

:param filepath: Path to the file to read
:param pattern: Regex pattern to match the version
:return: The version string found
:raises: Exception if version not found
"""
try:
with open(filepath, "rt") as file:
content = file.read()

match = re.search(pattern, content, re.MULTILINE)
if match:
return match.group(1)
else:
raise Exception(f"Version pattern '{pattern}' not found in {filepath}")
except FileNotFoundError:
raise Exception(f"File not found: {filepath}")


def get_all_versions() -> dict:
"""
Read versions from all three files managed by bumpver.

:return: Dict containing versions from all files
"""
versions = {}

# Get version from pyproject.toml
try:
with open("./pyproject.toml", "rb") as file:
content = tomllib.load(file)
versions["pyproject_toml"] = (
content.get("tool", {}).get("bumpver", {}).get("current_version", None)
)
if versions["pyproject_toml"] is None:
raise Exception(
"current_version not found in pyproject.toml [tool.bumpver] section"
)
except FileNotFoundError:
raise Exception("pyproject.toml not found")

# Get version from codecarbon/_version.py
versions["codecarbon_version"] = get_version_from_file(
"codecarbon/_version.py", r'^__version__\s*=\s*["\']([^"\']+)["\']'
)

# Get version from docs/edit/conf.py
versions["docs_conf"] = get_version_from_file(
"docs/edit/conf.py", r'^release\s*=\s*["\']([^"\']+)["\']'
)

return versions


def check_version_coherence(quiet=False) -> bool:
"""
Check that all version files have the same version.

:return: True if all versions match, False otherwise
"""
try:
versions = get_all_versions()

# Get unique versions
unique_versions = set(versions.values())

if len(unique_versions) == 1:
version = list(unique_versions)[0]
if not quiet:
logging.info(
f"✓ Version coherence check passed. All files have version: {version}"
)
return True
else:
logging.error(
"✗ Version coherence check failed! Versions are inconsistent:"
)
for file_key, version in versions.items():
file_mapping = {
"pyproject_toml": "pyproject.toml [tool.bumpver] current_version",
"codecarbon_version": "codecarbon/_version.py __version__",
"docs_conf": "docs/edit/conf.py release",
}
logging.error(f" {file_mapping[file_key]}: {version}")
logging.error(
"\nPlease use 'bumpver' to update versions consistently across all files."
)
return False

except Exception as e:
logging.error(f"✗ Error checking version coherence: {e}")
return False


def get_versions():
"""
Read package version and deps in pyproject.toml
Expand Down Expand Up @@ -65,9 +165,7 @@ def replace_in_file(filepath: str, info: dict):
parser.add_argument(
"-r",
"--replace",
type=bool,
default=False,
required=False,
action="store_true",
help="replace in file",
)
parser.add_argument(
Expand All @@ -80,15 +178,31 @@ def replace_in_file(filepath: str, info: dict):
parser.add_argument(
"-o",
"--only_package_version",
type=bool,
default=False,
action="store_true",
help="Only display current package version",
)
parser.add_argument(
"-c",
"--check_coherence",
action="store_true",
help="Check version coherence across all bumpver-managed files",
)
args = parser.parse_args()

# Check version coherence first if requested or before any operations
if args.check_coherence:
coherence_ok = check_version_coherence()
sys.exit(0 if coherence_ok else 1)

# Always check coherence before doing replacements or showing versions
if not check_version_coherence(quiet=True):
logging.error("Aborting due to version coherence issues.")
sys.exit(1)

info = get_versions()
file = args.filename
if args.only_package_version:
print(f'{info["openfisca_france"]}') # noqa: T201
print(f'{info["package_version"]}')
exit()
logging.info("Versions :")
print(info) # noqa: T201
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Set up Python
run: uv python install 3.12
- name: Check versions
run: uv run python .github/check_version.py -o
run: uv run python .github/pyproject_versions.py -o
- name: Build pip package
run: uv build
- name: Archive Pypi artifacts
Expand Down Expand Up @@ -83,7 +83,7 @@ jobs:
key: build-conda-${{ github.sha }}
- name: set version
run: |
python3 .github/pyproject_versions.py --replace True
python3 .github/pyproject_versions.py --check_coherence --replace
- name: Build conda package
uses: prefix-dev/rattler-build-action@20cb88d3095cc01fa181385021c57f886d624879 # v0.2.16
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
run: uv python install 3.12
- name: Check versions
run: |
uv run python .github/check_version.py
uv run python .github/pyproject_versions.py -c
- name: Build package
run: uv build
- name: Publish package
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ to regenerate the html files.

- Merge all PRs.
- Create a PR bumping the version with `uv run bumpver update --patch`. For a release candidate, use `uv run bumpver update --set-version 3.0.0_rc1`.
- Run `uv run python3 .github/check_version.py` to check version consistancy.
- Run `uv run python .github/pyproject_versions.py -c` to check version consistancy.
- Update the dependencies with `uv sync --upgrade`
- [Build Documentation](#documentation) with `uv run --only-group doc task docs`.
- Push the changes.
Expand Down
2 changes: 1 addition & 1 deletion codecarbon/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "3.0.4"
__version__ = "3.0.5"
2 changes: 1 addition & 1 deletion docs/.buildinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file records the configuration used when building these files. When it is not found, a full rebuild will be done.
config: b7ea6f802c48a45c32e0628608376fd9
config: 5f482fbbfa770d9f8999adc89a86852e
tags: 645f666f9bcd5a90fca523b33c5a78b7
4 changes: 3 additions & 1 deletion docs/_sources/parameters.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ Input Parameters
- | ``machine`` measure the power consumptions of the entire machine (defaults)
| ``process`` try and isolate the tracked processes in isolation
* - gpu_ids
- User-specified known gpu ids to track, defaults to ``None``
- | Comma-separated list of GPU ids to track, defaults to ``None``
| These can either be integer indexes of GPUs on the system, or prefixes
| to match against GPU identifiers as described `here <https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#cuda-environment-variables>`_
* - log_level
- | Global codecarbon log level (by order of verbosity): "debug", "info" (defaults),
| "warning", "error", or "critical"
Expand Down
2 changes: 1 addition & 1 deletion docs/_static/documentation_options.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const DOCUMENTATION_OPTIONS = {
VERSION: '3.0.4',
VERSION: '3.0.5',
LANGUAGE: 'en',
COLLAPSE_INDEX: false,
BUILDER: 'html',
Expand Down
4 changes: 2 additions & 2 deletions docs/advanced_installation.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
<meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" />

<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Advanced Installation &mdash; CodeCarbon 3.0.4 documentation</title>
<title>Advanced Installation &mdash; CodeCarbon 3.0.5 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=03e43079" />
<link rel="stylesheet" type="text/css" href="_static/css/theme.css?v=e59714d7" />


<script src="_static/jquery.js?v=5d32c60e"></script>
<script src="_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="_static/documentation_options.js?v=50b65552"></script>
<script src="_static/documentation_options.js?v=f4ced14b"></script>
<script src="_static/doctools.js?v=9bcbadda"></script>
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="_static/js/theme.js"></script>
Expand Down
4 changes: 2 additions & 2 deletions docs/api.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
<meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" />

<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>CodeCarbon API &mdash; CodeCarbon 3.0.4 documentation</title>
<title>CodeCarbon API &mdash; CodeCarbon 3.0.5 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=03e43079" />
<link rel="stylesheet" type="text/css" href="_static/css/theme.css?v=e59714d7" />


<script src="_static/jquery.js?v=5d32c60e"></script>
<script src="_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="_static/documentation_options.js?v=50b65552"></script>
<script src="_static/documentation_options.js?v=f4ced14b"></script>
<script src="_static/doctools.js?v=9bcbadda"></script>
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="_static/js/theme.js"></script>
Expand Down
4 changes: 2 additions & 2 deletions docs/comet.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
<meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" />

<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Comet Integration &mdash; CodeCarbon 3.0.4 documentation</title>
<title>Comet Integration &mdash; CodeCarbon 3.0.5 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=03e43079" />
<link rel="stylesheet" type="text/css" href="_static/css/theme.css?v=e59714d7" />


<script src="_static/jquery.js?v=5d32c60e"></script>
<script src="_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="_static/documentation_options.js?v=50b65552"></script>
<script src="_static/documentation_options.js?v=f4ced14b"></script>
<script src="_static/doctools.js?v=9bcbadda"></script>
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="_static/js/theme.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion docs/edit/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

# The full version, including alpha/beta/rc tags

release = "3.0.4"
release = "3.0.5"

# -- General configuration ---------------------------------------------------

Expand Down
4 changes: 2 additions & 2 deletions docs/examples.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
<meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" />

<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Examples &mdash; CodeCarbon 3.0.4 documentation</title>
<title>Examples &mdash; CodeCarbon 3.0.5 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=03e43079" />
<link rel="stylesheet" type="text/css" href="_static/css/theme.css?v=e59714d7" />


<script src="_static/jquery.js?v=5d32c60e"></script>
<script src="_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="_static/documentation_options.js?v=50b65552"></script>
<script src="_static/documentation_options.js?v=f4ced14b"></script>
<script src="_static/doctools.js?v=9bcbadda"></script>
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="_static/js/theme.js"></script>
Expand Down
4 changes: 2 additions & 2 deletions docs/faq.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
<meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" />

<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Frequently Asked Questions &mdash; CodeCarbon 3.0.4 documentation</title>
<title>Frequently Asked Questions &mdash; CodeCarbon 3.0.5 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=03e43079" />
<link rel="stylesheet" type="text/css" href="_static/css/theme.css?v=e59714d7" />


<script src="_static/jquery.js?v=5d32c60e"></script>
<script src="_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="_static/documentation_options.js?v=50b65552"></script>
<script src="_static/documentation_options.js?v=f4ced14b"></script>
<script src="_static/doctools.js?v=9bcbadda"></script>
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="_static/js/theme.js"></script>
Expand Down
Loading
Loading