From 8712eb023a2e52c2c441e8ee6955c764af288a1c Mon Sep 17 00:00:00 2001 From: Nina P <23741953+NP4567-dev@users.noreply.github.com> Date: Wed, 6 Nov 2024 22:22:12 +0100 Subject: [PATCH 1/5] fix: range can now be included in f-strings --- ecologits/_ecologits.py | 4 ++-- ecologits/impacts/modeling.py | 4 ++-- ecologits/utils/__init__.py | 0 ecologits/{ => utils}/exceptions.py | 0 ecologits/{ => utils}/log.py | 0 ecologits/{ => utils}/range_value.py | 5 +++++ tests/test_modeling_impacts.py | 4 ++-- tests/utils/__init__.py | 0 tests/utils/range_value.py | 10 ++++++++++ 9 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 ecologits/utils/__init__.py rename ecologits/{ => utils}/exceptions.py (100%) rename ecologits/{ => utils}/log.py (100%) rename ecologits/{ => utils}/range_value.py (93%) create mode 100644 tests/utils/__init__.py create mode 100644 tests/utils/range_value.py diff --git a/ecologits/_ecologits.py b/ecologits/_ecologits.py index dbdbd453..3f120055 100644 --- a/ecologits/_ecologits.py +++ b/ecologits/_ecologits.py @@ -5,8 +5,8 @@ from packaging.version import Version -from ecologits.exceptions import EcoLogitsError -from ecologits.log import logger +from ecologits.utils.exceptions import EcoLogitsError +from ecologits.utils.log import logger def init_openai_instrumentor() -> None: diff --git a/ecologits/impacts/modeling.py b/ecologits/impacts/modeling.py index 2d35a36b..f8904b51 100644 --- a/ecologits/impacts/modeling.py +++ b/ecologits/impacts/modeling.py @@ -2,8 +2,8 @@ from pydantic import BaseModel -from ecologits.exceptions import ModelingError -from ecologits.range_value import ValueOrRange +from ecologits.utils.exceptions import ModelingError +from ecologits.utils.range_value import ValueOrRange @total_ordering diff --git a/ecologits/utils/__init__.py b/ecologits/utils/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/ecologits/exceptions.py b/ecologits/utils/exceptions.py similarity index 100% rename from ecologits/exceptions.py rename to ecologits/utils/exceptions.py diff --git a/ecologits/log.py b/ecologits/utils/log.py similarity index 100% rename from ecologits/log.py rename to ecologits/utils/log.py diff --git a/ecologits/range_value.py b/ecologits/utils/range_value.py similarity index 93% rename from ecologits/range_value.py rename to ecologits/utils/range_value.py index 9d385fbc..3229cec9 100644 --- a/ecologits/range_value.py +++ b/ecologits/utils/range_value.py @@ -63,5 +63,10 @@ def __gt__(self, other: Any) -> bool: else: return self.min > other + def __format__(self,format_spec:str)-> str: + return f"{format(self.min,format_spec)} to {format(self.max,format_spec)}" + + + ValueOrRange = Union[int, float, RangeValue] diff --git a/tests/test_modeling_impacts.py b/tests/test_modeling_impacts.py index 3205bfc4..9bec602f 100644 --- a/tests/test_modeling_impacts.py +++ b/tests/test_modeling_impacts.py @@ -3,8 +3,8 @@ import pytest from ecologits.impacts.modeling import Impact, Energy, GWP, ADPe, PE -from ecologits.exceptions import ModelingError -from ecologits.range_value import RangeValue +from ecologits.utils.exceptions import ModelingError +from ecologits.utils.range_value import RangeValue impact_config = dict( diff --git a/tests/utils/__init__.py b/tests/utils/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/utils/range_value.py b/tests/utils/range_value.py new file mode 100644 index 00000000..55c02a18 --- /dev/null +++ b/tests/utils/range_value.py @@ -0,0 +1,10 @@ +from ecologits.utils.range_value import RangeValue + + +def test_range_formats_ok(): + + range = RangeValue(min =0.00000006, max=0.00008) + + expected = f"{range.min:.2f} to {range.max:.2f}" + + assert f"{range:.2f}" == expected \ No newline at end of file From 9b55978fda62650c75237da6ab8fc756f9bc1a6a Mon Sep 17 00:00:00 2001 From: Nina P <23741953+NP4567-dev@users.noreply.github.com> Date: Wed, 6 Nov 2024 22:27:01 +0100 Subject: [PATCH 2/5] fix: fix tests --- ecologits/impacts/llm.py | 2 +- ecologits/model_repository.py | 2 +- ecologits/tracers/utils.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ecologits/impacts/llm.py b/ecologits/impacts/llm.py index f403d30a..52add327 100644 --- a/ecologits/impacts/llm.py +++ b/ecologits/impacts/llm.py @@ -4,7 +4,7 @@ from ecologits.impacts.dag import DAG from ecologits.impacts.modeling import GWP, PE, ADPe, Embodied, Energy, Impacts, Usage -from ecologits.range_value import RangeValue, ValueOrRange +from ecologits.utils.range_value import RangeValue, ValueOrRange MODEL_QUANTIZATION_BITS = 4 diff --git a/ecologits/model_repository.py b/ecologits/model_repository.py index 87ffba8d..d4c1bd36 100644 --- a/ecologits/model_repository.py +++ b/ecologits/model_repository.py @@ -5,7 +5,7 @@ from pydantic import BaseModel -from ecologits.range_value import ValueOrRange +from ecologits.utils.range_value import ValueOrRange class Providers(Enum): diff --git a/ecologits/tracers/utils.py b/ecologits/tracers/utils.py index e1911a9b..16007f25 100644 --- a/ecologits/tracers/utils.py +++ b/ecologits/tracers/utils.py @@ -3,7 +3,7 @@ from ecologits.electricity_mix_repository import electricity_mixes from ecologits.impacts.llm import compute_llm_impacts from ecologits.impacts.modeling import Impacts -from ecologits.log import logger +from ecologits.utils.log import logger from ecologits.model_repository import ArchitectureTypes, models From b3913c32c5dc2e67c7a2126a03edde72d5d6ff43 Mon Sep 17 00:00:00 2001 From: Nina P <23741953+NP4567-dev@users.noreply.github.com> Date: Wed, 6 Nov 2024 22:29:30 +0100 Subject: [PATCH 3/5] fix: happy ruff happy life --- ecologits/tracers/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ecologits/tracers/utils.py b/ecologits/tracers/utils.py index 16007f25..0f95be91 100644 --- a/ecologits/tracers/utils.py +++ b/ecologits/tracers/utils.py @@ -3,8 +3,8 @@ from ecologits.electricity_mix_repository import electricity_mixes from ecologits.impacts.llm import compute_llm_impacts from ecologits.impacts.modeling import Impacts -from ecologits.utils.log import logger from ecologits.model_repository import ArchitectureTypes, models +from ecologits.utils.log import logger def _avg(value_range: tuple) -> float: From 9102d3e4e316fc4760d484a51b1ca4000cfc0630 Mon Sep 17 00:00:00 2001 From: Nina P <23741953+NP4567-dev@users.noreply.github.com> Date: Tue, 12 Nov 2024 21:31:07 +0100 Subject: [PATCH 4/5] fix: fix review --- ecologits/{utils => }/exceptions.py | 0 ecologits/{utils => }/log.py | 0 tests/{utils/range_value.py => test_range_value.py} | 0 tests/utils/__init__.py | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename ecologits/{utils => }/exceptions.py (100%) rename ecologits/{utils => }/log.py (100%) rename tests/{utils/range_value.py => test_range_value.py} (100%) delete mode 100644 tests/utils/__init__.py diff --git a/ecologits/utils/exceptions.py b/ecologits/exceptions.py similarity index 100% rename from ecologits/utils/exceptions.py rename to ecologits/exceptions.py diff --git a/ecologits/utils/log.py b/ecologits/log.py similarity index 100% rename from ecologits/utils/log.py rename to ecologits/log.py diff --git a/tests/utils/range_value.py b/tests/test_range_value.py similarity index 100% rename from tests/utils/range_value.py rename to tests/test_range_value.py diff --git a/tests/utils/__init__.py b/tests/utils/__init__.py deleted file mode 100644 index e69de29b..00000000 From 526b2927c16920d7748102cfa3d93082a209a126 Mon Sep 17 00:00:00 2001 From: Nina P <23741953+NP4567-dev@users.noreply.github.com> Date: Tue, 12 Nov 2024 21:34:08 +0100 Subject: [PATCH 5/5] fix: fix review --- ecologits/_ecologits.py | 4 ++-- ecologits/impacts/modeling.py | 2 +- ecologits/tracers/utils.py | 2 +- tests/test_modeling_impacts.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ecologits/_ecologits.py b/ecologits/_ecologits.py index 3f120055..dbdbd453 100644 --- a/ecologits/_ecologits.py +++ b/ecologits/_ecologits.py @@ -5,8 +5,8 @@ from packaging.version import Version -from ecologits.utils.exceptions import EcoLogitsError -from ecologits.utils.log import logger +from ecologits.exceptions import EcoLogitsError +from ecologits.log import logger def init_openai_instrumentor() -> None: diff --git a/ecologits/impacts/modeling.py b/ecologits/impacts/modeling.py index f8904b51..af114be1 100644 --- a/ecologits/impacts/modeling.py +++ b/ecologits/impacts/modeling.py @@ -2,7 +2,7 @@ from pydantic import BaseModel -from ecologits.utils.exceptions import ModelingError +from ecologits.exceptions import ModelingError from ecologits.utils.range_value import ValueOrRange diff --git a/ecologits/tracers/utils.py b/ecologits/tracers/utils.py index 0f95be91..e1911a9b 100644 --- a/ecologits/tracers/utils.py +++ b/ecologits/tracers/utils.py @@ -3,8 +3,8 @@ from ecologits.electricity_mix_repository import electricity_mixes from ecologits.impacts.llm import compute_llm_impacts from ecologits.impacts.modeling import Impacts +from ecologits.log import logger from ecologits.model_repository import ArchitectureTypes, models -from ecologits.utils.log import logger def _avg(value_range: tuple) -> float: diff --git a/tests/test_modeling_impacts.py b/tests/test_modeling_impacts.py index 9bec602f..59b9bf12 100644 --- a/tests/test_modeling_impacts.py +++ b/tests/test_modeling_impacts.py @@ -3,7 +3,7 @@ import pytest from ecologits.impacts.modeling import Impact, Energy, GWP, ADPe, PE -from ecologits.utils.exceptions import ModelingError +from ecologits.exceptions import ModelingError from ecologits.utils.range_value import RangeValue