From b5bc3a6df8ef8ccc3d24391f16acf480de1dbba2 Mon Sep 17 00:00:00 2001 From: benoit-cty <4-benoit-cty@users.noreply.git.leximpact.dev> Date: Sat, 18 May 2024 09:00:14 +0200 Subject: [PATCH 1/7] Add cpu test --- tests/test_cpu.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/test_cpu.py b/tests/test_cpu.py index e06cd9a54..290b5a804 100644 --- a/tests/test_cpu.py +++ b/tests/test_cpu.py @@ -193,7 +193,11 @@ def test_get_matching_cpu(self): tdp._get_matching_cpu(model, cpu_data, greedy=False), "Intel Xeon Gold 6330N", ) - + model = "Intel(R) Xeon(R) Silver 4208 CPU @ 2.10GHz" + self.assertEqual( + tdp._get_matching_cpu(model, cpu_data, greedy=False), + "Intel Xeon Silver 4208", + ) # Does not match when missing part replaced by (here wrong) other part. # Which here is good. Could happen if Intel creates a model with the # same name than AMD ("5800K"), but only AMD exists in our cpu list. From f3835fdc97a32be40eb1a9faa897d4d3ddb52315 Mon Sep 17 00:00:00 2001 From: benoit-cty <4-benoit-cty@users.noreply.git.leximpact.dev> Date: Sat, 18 May 2024 09:32:33 +0200 Subject: [PATCH 2/7] Update conda publication --- .conda/meta.yaml | 24 ++---- .github/check_version.py | 4 +- CONTRIBUTING.md | 6 +- requirements/requirements-dev.txt | 30 ++++++- requirements/requirements-test.py3.9.txt | 102 ++++++++++++++++++++++- 5 files changed, 140 insertions(+), 26 deletions(-) diff --git a/.conda/meta.yaml b/.conda/meta.yaml index 532f9931a..ec44e9265 100644 --- a/.conda/meta.yaml +++ b/.conda/meta.yaml @@ -1,11 +1,15 @@ -{% set version = "2.4.1" %} +{% set version_match = load_file_regex( + load_file='codecarbon/_version.py', + regex_pattern='^__version__ = "(.+)"') %} +{% set version = version_match[1] %} +{% set pyproject = load_file_data('pyproject.toml') %} package: name: codecarbon version: {{ version }} source: - path: ../.. + path: .. build: noarch: python @@ -21,19 +25,9 @@ requirements: - python - pip run: - - python>=3.7 - - arrow - - click - - dash - - dash-bootstrap-components - - fire - - pandas - - requests - - psutil - - pynvml - - py-cpuinfo - - prometheus_client - - rapidfuzz + {% for req in pyproject.get('project').get('dependencies') %} + - {{ req }} + {% endfor %} test: imports: diff --git a/.github/check_version.py b/.github/check_version.py index cef752db1..778ff8dcb 100644 --- a/.github/check_version.py +++ b/.github/check_version.py @@ -58,12 +58,10 @@ def get_versions_from_pypi(package_name: str = "") -> dict: args = parser.parse_args() versions = get_versions_from_pypi("codecarbon") module_version = get_local_version() - meta_version = get_local_version(".conda/meta.yaml") - local_versions = [module_version, meta_version] + local_versions = [module_version] if local_versions.count(local_versions[0]) != len(local_versions): print("All local versions did not match !") print(f"codecarbon/_version.py : {module_version}") - print(f".conda/meta.yaml : {meta_version}") sys.exit(1) if args.onlyprintversion: print(module_version) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8a8b515c3..e6edeaf46 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -415,7 +415,7 @@ to regenerate the html files. ### Release process - Merge all PRs. -- Create a PR bumping the version with `hatch version minor` and report it in https://github.com/mlco2/codecarbon/blob/master/.conda/meta.yaml. +- Create a PR bumping the version with `hatch version minor`. - Run `python3 .github/check_version.py` to check version consistancy. - [Build Documentation](#documentation) if needed with `hatch run docs:build`. - Merge the PR. @@ -433,8 +433,8 @@ Start a Docker image in the same directory and bind-mount the current directory Inside the docker container, run: - `conda install conda-build conda-verify` -- `cd /data && mkdir -p conda_dist` -- `conda build --python 3.8 .conda/ -c conda-forge --output-folder conda_dist` +- `cd /data && mkdir -p /conda_dist` +- `conda build --python 3.8 .conda/ -c conda-forge --output-folder /conda_dist` - `anaconda upload --user codecarbon /data/noarch/codecarbon-*.tar.bz2` diff --git a/requirements/requirements-dev.txt b/requirements/requirements-dev.txt index bd42d5585..d57ef2b21 100644 --- a/requirements/requirements-dev.txt +++ b/requirements/requirements-dev.txt @@ -3,6 +3,8 @@ # # - pre-commit # - ruff +# - black +# - mypy # - arrow # - click # - pandas @@ -16,6 +18,8 @@ arrow==1.3.0 # via hatch.envs.dev +black==24.4.2 + # via hatch.envs.dev certifi==2024.2.2 # via requests cfgv==3.4.0 @@ -23,7 +27,9 @@ cfgv==3.4.0 charset-normalizer==3.3.2 # via requests click==8.1.7 - # via hatch.envs.dev + # via + # hatch.envs.dev + # black distlib==0.3.8 # via virtualenv filelock==3.13.3 @@ -32,14 +38,26 @@ identify==2.5.35 # via pre-commit idna==3.7 # via requests +mypy==1.10.0 + # via hatch.envs.dev +mypy-extensions==1.0.0 + # via + # black + # mypy nodeenv==1.8.0 # via pre-commit numpy==1.26.4 # via pandas +packaging==24.0 + # via black pandas==2.2.1 # via hatch.envs.dev +pathspec==0.12.1 + # via black platformdirs==4.2.0 - # via virtualenv + # via + # black + # virtualenv pre-commit==3.7.0 # via hatch.envs.dev prometheus-client==0.20.0 @@ -66,8 +84,16 @@ ruff==0.3.4 # via hatch.envs.dev six==1.16.0 # via python-dateutil +tomli==2.0.1 + # via + # black + # mypy types-python-dateutil==2.9.0.20240316 # via arrow +typing-extensions==4.11.0 + # via + # black + # mypy tzdata==2024.1 # via pandas urllib3==2.2.1 diff --git a/requirements/requirements-test.py3.9.txt b/requirements/requirements-test.py3.9.txt index 9ed357cb2..a1b0c92ff 100644 --- a/requirements/requirements-test.py3.9.txt +++ b/requirements/requirements-test.py3.9.txt @@ -1,6 +1,13 @@ # # This file is autogenerated by hatch-pip-compile with Python 3.9 # +# - mock +# - pytest +# - responses +# - numpy +# - psutil +# - requests-mock +# - rapidfuzz # - arrow # - click # - pandas @@ -10,22 +17,75 @@ # - pynvml # - rapidfuzz # - requests +# - dash +# - dash-bootstrap-components<1.0.0 +# - fire # arrow==1.3.0 # via hatch.envs.test.py3.9 +blinker==1.8.2 + # via flask certifi==2024.2.2 # via requests charset-normalizer==3.3.2 # via requests click==8.1.7 + # via + # hatch.envs.test.py3.9 + # flask +dash==2.17.0 + # via + # hatch.envs.test.py3.9 + # dash-bootstrap-components +dash-bootstrap-components==0.13.1 + # via hatch.envs.test.py3.9 +dash-core-components==2.0.0 + # via dash +dash-html-components==2.0.0 + # via dash +dash-table==5.0.0 + # via dash +exceptiongroup==1.2.1 + # via pytest +fire==0.6.0 # via hatch.envs.test.py3.9 +flask==3.0.3 + # via dash idna==3.7 # via requests +importlib-metadata==7.1.0 + # via + # dash + # flask +iniconfig==2.0.0 + # via pytest +itsdangerous==2.2.0 + # via flask +jinja2==3.1.4 + # via flask +markupsafe==2.1.5 + # via + # jinja2 + # werkzeug +mock==5.1.0 + # via hatch.envs.test.py3.9 +nest-asyncio==1.6.0 + # via dash numpy==1.26.4 - # via pandas + # via + # hatch.envs.test.py3.9 + # pandas +packaging==24.0 + # via + # plotly + # pytest pandas==2.2.1 # via hatch.envs.test.py3.9 +plotly==5.22.0 + # via dash +pluggy==1.5.0 + # via pytest prometheus-client==0.20.0 # via hatch.envs.test.py3.9 psutil==5.9.8 @@ -34,21 +94,57 @@ py-cpuinfo==9.0.0 # via hatch.envs.test.py3.9 pynvml==11.5.0 # via hatch.envs.test.py3.9 +pytest==8.2.0 + # via hatch.envs.test.py3.9 python-dateutil==2.9.0.post0 # via # arrow # pandas pytz==2024.1 # via pandas +pyyaml==6.0.1 + # via responses rapidfuzz==3.7.0 # via hatch.envs.test.py3.9 requests==2.31.0 + # via + # hatch.envs.test.py3.9 + # dash + # requests-mock + # responses +requests-mock==1.12.1 + # via hatch.envs.test.py3.9 +responses==0.25.0 # via hatch.envs.test.py3.9 +retrying==1.3.4 + # via dash six==1.16.0 - # via python-dateutil + # via + # fire + # python-dateutil + # retrying +tenacity==8.3.0 + # via plotly +termcolor==2.4.0 + # via fire +tomli==2.0.1 + # via pytest types-python-dateutil==2.9.0.20240316 # via arrow +typing-extensions==4.11.0 + # via dash tzdata==2024.1 # via pandas urllib3==2.2.1 - # via requests + # via + # requests + # responses +werkzeug==3.0.3 + # via + # dash + # flask +zipp==3.18.2 + # via importlib-metadata + +# The following packages are considered to be unsafe in a requirements file: +# setuptools From 567cc18c7cd0f8c71421151d84e590fc4e381ed3 Mon Sep 17 00:00:00 2001 From: benoit-cty <4-benoit-cty@users.noreply.git.leximpact.dev> Date: Sat, 18 May 2024 09:36:23 +0200 Subject: [PATCH 3/7] bump --- codecarbon/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codecarbon/_version.py b/codecarbon/_version.py index 54499df34..60be088dc 100644 --- a/codecarbon/_version.py +++ b/codecarbon/_version.py @@ -1 +1 @@ -__version__ = "2.4.1" +__version__ = "2.4.2" From c62c77a0717b542b53cd48cc9d7358c125f841b1 Mon Sep 17 00:00:00 2001 From: benoit-cty <4-benoit-cty@users.noreply.git.leximpact.dev> Date: Sun, 19 May 2024 18:31:01 +0200 Subject: [PATCH 4/7] Fix API Docker build --- carbonserver/docker/Dockerfile | 8 +++++--- docker-compose.yml | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/carbonserver/docker/Dockerfile b/carbonserver/docker/Dockerfile index 6b07fc2a0..f9425fc10 100644 --- a/carbonserver/docker/Dockerfile +++ b/carbonserver/docker/Dockerfile @@ -2,7 +2,7 @@ # Use Ubuntu to install 3 versions of Python for testing # For production, you could use python:3.8-slim -FROM ubuntu:20.04 +FROM ubuntu:22.04 # set work directory WORKDIR /carbonserver @@ -10,6 +10,8 @@ WORKDIR /carbonserver # set env variables ENV PYTHONDONTWRITEBYTECODE 1 ENV PYTHONUNBUFFERED 1 +# Prevent apt to ask for region +ENV DEBIAN_FRONTEND noninteractive # install dependencies RUN apt-get update && apt-get upgrade -y && \ @@ -18,12 +20,12 @@ RUN apt-get update && apt-get upgrade -y && \ apt-get update && \ apt-get install -y gcc libpq-dev python3.11 python3-pip -COPY ../requirements/requirements-dev.txt . +COPY ./requirements/requirements-dev.txt . RUN pip install -r requirements-dev.txt COPY docker/entrypoint.sh /opt RUN chmod a+x /opt/entrypoint.sh # copy project -COPY . . +COPY ./carbonserver/* . EXPOSE 8000 ENTRYPOINT ["/opt/entrypoint.sh"] diff --git a/docker-compose.yml b/docker-compose.yml index be58738f2..4922e26f6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,8 +15,8 @@ services: carbonserver: build: - context: ./carbonserver/ - dockerfile: ./docker/Dockerfile + context: . + dockerfile: ./carbonserver/docker/Dockerfile #command: cd /carbonserver/carbonserver/database && python3 -m alembic upgrade head && cd ../.. && uvicorn --reload main:app --host 0.0.0.0 volumes: - ./carbonserver:/carbonserver From 610dc4fadb795ae6968e7c01ae86df01484657de Mon Sep 17 00:00:00 2001 From: benoit-cty <4-benoit-cty@users.noreply.git.leximpact.dev> Date: Sun, 19 May 2024 22:24:29 +0200 Subject: [PATCH 5/7] Fix conda build --- .conda/meta.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.conda/meta.yaml b/.conda/meta.yaml index ec44e9265..582ed3adc 100644 --- a/.conda/meta.yaml +++ b/.conda/meta.yaml @@ -24,6 +24,7 @@ requirements: host: - python - pip + - hatchling run: {% for req in pyproject.get('project').get('dependencies') %} - {{ req }} From 6d1d0f237e03184ccb5bd6fc16b7d4ce30c67fbb Mon Sep 17 00:00:00 2001 From: benoit-cty <4-benoit-cty@users.noreply.git.leximpact.dev> Date: Sun, 19 May 2024 22:31:55 +0200 Subject: [PATCH 6/7] doc --- CONTRIBUTING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e6edeaf46..a28ae64d9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -432,9 +432,9 @@ Start a Docker image in the same directory and bind-mount the current directory `docker run -ti --rm=true -v $PWD:/data continuumio/anaconda3`. Inside the docker container, run: -- `conda install conda-build conda-verify` +- `conda install conda-build conda-verify conda-forge::hatchling` - `cd /data && mkdir -p /conda_dist` -- `conda build --python 3.8 .conda/ -c conda-forge --output-folder /conda_dist` +- `conda build --python 3.11 .conda/ -c conda-forge --output-folder /conda_dist` - `anaconda upload --user codecarbon /data/noarch/codecarbon-*.tar.bz2` From 8b2272d5a0bd88483c151fe8a32351cc30b35f99 Mon Sep 17 00:00:00 2001 From: benoit-cty <4-benoit-cty@users.noreply.git.leximpact.dev> Date: Mon, 20 May 2024 11:45:32 +0200 Subject: [PATCH 7/7] conda doc works --- CONTRIBUTING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a28ae64d9..d415b4bc3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -432,10 +432,10 @@ Start a Docker image in the same directory and bind-mount the current directory `docker run -ti --rm=true -v $PWD:/data continuumio/anaconda3`. Inside the docker container, run: -- `conda install conda-build conda-verify conda-forge::hatchling` +- `conda install -y conda-build conda-verify conda-forge::hatchling` - `cd /data && mkdir -p /conda_dist` - `conda build --python 3.11 .conda/ -c conda-forge --output-folder /conda_dist` -- `anaconda upload --user codecarbon /data/noarch/codecarbon-*.tar.bz2` +- `anaconda upload --user codecarbon /conda_dist/noarch/codecarbon-*.tar.bz2`