From 88acb95e93d0d1ee32a5c1768236b7115a1ae722 Mon Sep 17 00:00:00 2001 From: Jonas Jucker Date: Thu, 4 May 2023 14:45:47 +0200 Subject: [PATCH] use shutil.which to find fprettify --- pyutils/src/icon4py/icon4pygen/bindings/utils.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/pyutils/src/icon4py/icon4pygen/bindings/utils.py b/pyutils/src/icon4py/icon4pygen/bindings/utils.py index d33c56a987..83d2770d1c 100644 --- a/pyutils/src/icon4py/icon4pygen/bindings/utils.py +++ b/pyutils/src/icon4py/icon4pygen/bindings/utils.py @@ -11,7 +11,7 @@ # # SPDX-License-Identifier: GPL-3.0-or-later -import os +import shutil import subprocess import sys from pathlib import Path @@ -41,15 +41,12 @@ def calc_num_neighbors(dim_list: list[Dimension], includes_center: bool) -> int: def format_fortran_code(source: str) -> str: """Format fortran code using fprettify. - The path to fprettify needs to be set explicitly for the - non-Spack build process as Liskov does not activate a virtual environment. - - Variable SPACK_ROOT is always set in a spack build, used to assume that fprettify - is in PATH + Try to find fprettify in PATH -> found by which + otherwise look in PYTHONPATH """ - if os.getenv("SPACK_ROOT") is not None: - fprettify_path = "fprettify" - else: + fprettify_path = shutil.which("fprettify") + + if fprettify_path is None: bin_path = Path(PYTHON_PATH).parent fprettify_path = bin_path / "fprettify" args = [str(fprettify_path)]