mlco2 / codecarbon

Track emissions from Compute and recommend ways to reduce their impact on the environment.
https://mlco2.github.io/codecarbon
MIT License
1.18k stars 178 forks source link

Python 3.12 compatibility #465

Closed benoit-cty closed 8 months ago

benoit-cty commented 1 year ago

We discover in https://github.com/mlco2/codecarbon/pull/461#issuecomment-1782872408 that we have a problem with linting in Python 3.12.

We need to fixe the code to be compatible with 3.12 and below.

LuisBlanche commented 1 year ago

I repeat the comment here for visibility : Linting error with python 3.12 :

E201 : Whitespace after "(" E231 : Missing whitespace after ',', ';', or ':' E226 : Missing whitespace around arithmetic operator

I think this might be related to the updates on f-strings comming with python 3.12

LuisBlanche commented 1 year ago

I ran make pre-commit in local with a Python 3.12.0 env and it works without issues

benoit-cty commented 1 year ago

Well, so it's not just Python 3.12... Thanks for the test.

inimaz commented 8 months ago

Hello! I tried similar thing as @LuisBlanche but with conda in local to run the pre-commit and it works

conda create -n codecarbon312
conda activate codecarbon312
conda install pip
pip install pre-commit
pre-commit run --all-files

I have opened #514 to test it with the CI and it fails. Let's see...

inimaz commented 8 months ago

Sorry my bad, I was not using the correct pre-commit in local. I see the errors now

/home/inigo/miniconda3/envs/codecarbon312/bin/pre-commit run --all-files 
isort....................................................................Passed
black....................................................................Passed
flake8...................................................................Failed
- hook id: flake8
- exit code: 1

codecarbon/core/emissions.py:219:71: E226 missing whitespace around arithmetic operator
codecarbon/viz/carbonboard.py:89:65: E231 missing whitespace after ','
codecarbon/viz/carbonboard.py:92:59: E231 missing whitespace after ','
codecarbon/viz/carbonboard_on_api.py:90:65: E231 missing whitespace after ','
codecarbon/viz/carbonboard_on_api.py:93:59: E231 missing whitespace after ','
examples/task_inference.py:51:28: E201 whitespace after '{'
examples/task_inference.py:51:70: E201 whitespace after '{'
examples/task_inference.py:51:111: E201 whitespace after '{'
inimaz commented 8 months ago

If I run it with python 3.11 the errors are not there

/home/inigo/miniconda3/envs/codecarbon311/bin/pre-commit run --all-files

[INFO] Installing environment for https://github.com/pycqa/isort.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/psf/black.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/PyCQA/flake8.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
isort....................................................................Passed
black....................................................................Passed
flake8...................................................................Passed