Skip to content

Update Conda recipe #554

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 21, 2024
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
25 changes: 10 additions & 15 deletions .conda/meta.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -20,20 +24,11 @@ requirements:
host:
- python
- pip
- hatchling
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:
Expand Down
4 changes: 1 addition & 3 deletions .github/check_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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`
- `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`
- `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 /conda_dist/noarch/codecarbon-*.tar.bz2`


<!-- TOC --><a name="restore-database-from-a-production-backup"></a>
Expand Down
8 changes: 5 additions & 3 deletions carbonserver/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

# 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

# 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 && \
Expand All @@ -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"]
2 changes: 1 addition & 1 deletion codecarbon/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.4.1"
__version__ = "2.4.2"
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 28 additions & 2 deletions requirements/requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#
# - pre-commit
# - ruff
# - black
# - mypy
# - arrow
# - click
# - pandas
Expand All @@ -16,14 +18,18 @@

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
# via pre-commit
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
Expand All @@ -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
Expand All @@ -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
Expand Down
102 changes: 99 additions & 3 deletions requirements/requirements-test.py3.9.txt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
6 changes: 5 additions & 1 deletion tests/test_cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading