Skip to content

Commit

Permalink
Fix footprint return type of get_runtime_config
Browse files Browse the repository at this point in the history
This is arguably one of those places where static type checking
and python do not play particually well together, but this does
allow mypy to report all is well.

The issue here is that the optional command line argument 'footprint'
results in get_runtime_config getting hold of values for PUE and
jobinfo. These are used by carbonFootprint.py's
get_footprint_reduction_estimate. If footprint is not passed in
we should return some null value. The presence of the same command
line argument is checked in main before dispatching to
get_footprint_reduction_estimate so it does not really matter
what those values are if footprint is not selected. It feels
"pythonic" to return None, but get_footprint_reduction_estimate
cannot handle None so mypy is unhappy. Instead we return 'zero'
values in the "correct" types.

A better solution, probably, would be to bundle jobinfo and PUE into
a container of some sort that can be tested in main
and passed into get_footprint_reduction_estimate.
  • Loading branch information
andreww committed Apr 17, 2024
1 parent a724229 commit fb01f50
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions cats/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import logging
import sys
from collections.abc import Mapping
from typing import Any
from typing import Any, Union

import requests
import yaml
Expand All @@ -24,7 +24,8 @@
__all__ = ["get_runtime_config"]


def get_runtime_config(args) -> tuple[dict, APIInterface, str, int]:
def get_runtime_config(args) -> tuple[APIInterface, str, int,
list[tuple[int, float]],float]:
"""Return the runtime cats configuration from list of command line
arguments and content of configuration file.
Expand Down Expand Up @@ -61,8 +62,13 @@ def get_runtime_config(args) -> tuple[dict, APIInterface, str, int]:
jobinfo = get_job_info(args, configmapping["profiles"])
PUE = configmapping["PUE"]
else:
jobinfo = None
PUE = None
# Here we return zero values of the correct type rather than
# None so that static typing allows our return type to match
# the input to get_footprint_reduction_estimate(). However,
# we call that function inside a args.footprint conditional so
# we should never see these values in that function.
jobinfo = [(0, 0.0)]
PUE = 0.0

return CI_API_interface, location, duration, jobinfo, PUE

Expand Down

0 comments on commit fb01f50

Please sign in to comment.