Skip to content

Commit

Permalink
change fprettify path if invoked from spack (#184)
Browse files Browse the repository at this point in the history
* change fprettify path if invoked from spack

* convert to str

* add comment
  • Loading branch information
abishekg7 authored Mar 31, 2023
1 parent c8b868a commit 3c01d37
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pyutils/src/icon4py/icon4pygen/bindings/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 3c01d37

Please sign in to comment.