From 3c01d37e0e838bc071a0fec2ec07536904e612ea Mon Sep 17 00:00:00 2001 From: abishekg7 <56273301+abishekg7@users.noreply.github.com> Date: Fri, 31 Mar 2023 06:43:39 -0500 Subject: [PATCH] change fprettify path if invoked from spack (#184) * change fprettify path if invoked from spack * convert to str * add comment --- pyutils/src/icon4py/icon4pygen/bindings/utils.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pyutils/src/icon4py/icon4pygen/bindings/utils.py b/pyutils/src/icon4py/icon4pygen/bindings/utils.py index 5c4fe34f8b..ca0c47c4ab 100644 --- a/pyutils/src/icon4py/icon4pygen/bindings/utils.py +++ b/pyutils/src/icon4py/icon4pygen/bindings/utils.py @@ -38,9 +38,17 @@ def calc_num_neighbors(dim_list: list[Dimension], includes_center: bool) -> int: def format_fortran_code(source: str) -> str: - """Format fortran code using fprettify.""" + """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. + However, the PYTHON_PATH does not contain fprettify in a Spack build, hence the need for a special condition + """ bin_path = Path(PYTHON_PATH).parent - fprettify_path = bin_path / "fprettify" + if "spack" not in str(bin_path): + fprettify_path = bin_path / "fprettify" + else: + fprettify_path = "fprettify" args = [str(fprettify_path)] p1 = subprocess.Popen(args, stdout=subprocess.PIPE, stdin=subprocess.PIPE) return p1.communicate(source.encode("UTF-8"))[0].decode("UTF-8").rstrip()