From 29b5b804047b18d062afd6db250d64622df50d7b Mon Sep 17 00:00:00 2001 From: benoit-cty <4-benoit-cty@users.noreply.git.leximpact.dev> Date: Sun, 16 Jun 2024 10:37:02 +0200 Subject: [PATCH] Fix powermetrics test asking for password on Linux --- codecarbon/core/powermetrics.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/codecarbon/core/powermetrics.py b/codecarbon/core/powermetrics.py index b12b7805..8fd727fd 100644 --- a/codecarbon/core/powermetrics.py +++ b/codecarbon/core/powermetrics.py @@ -25,6 +25,14 @@ def is_powermetrics_available(): def _has_powermetrics_sudo(): + if shutil.which("sudo") is None: + logger.debug("sudo not available, we won't use Apple PowerMetrics.") + return False + if shutil.which("powermetrics") is None: + logger.info( + "Apple PowerMetrics not available. Please install it if you are using an Apple product." + ) + return False process = subprocess.Popen( [ "sudo",