Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] use shutil.which to find fprettify #203

Merged
merged 1 commit into from
May 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions pyutils/src/icon4py/icon4pygen/bindings/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# SPDX-License-Identifier: GPL-3.0-or-later

import os
import shutil
import subprocess
import sys
from pathlib import Path
Expand Down Expand Up @@ -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)]
Expand Down