diff --git a/.github/workflows/pymake-linting-install.yml b/.github/workflows/pymake-linting-install.yml index ca256e9..feafe89 100644 --- a/.github/workflows/pymake-linting-install.yml +++ b/.github/workflows/pymake-linting-install.yml @@ -20,22 +20,17 @@ jobs: - name: Checkout repo uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v5 + - name: Setup pixi + uses: prefix-dev/setup-pixi@v0.8.1 with: - python-version: "3.12" - - - name: Setup Graphviz - uses: ts-graphviz/setup-graphviz@v2 - - - name: Install packages - run: pip install ".[lint]" + pixi-version: v0.19.1 + manifest-path: "pixi.toml" - name: Lint - run: ruff check . + run: pixi run check-lint - name: Check format - run: ruff format . --check + run: pixi run check-format pymake_setup: name: standard installation diff --git a/autotest/test_cli_cmds.py b/autotest/test_cli_cmds.py index 46aa32f..ed6900d 100644 --- a/autotest/test_cli_cmds.py +++ b/autotest/test_cli_cmds.py @@ -2,6 +2,7 @@ import pathlib as pl import subprocess from platform import system +from pymake import linker_update_environment import pytest from flaky import flaky @@ -113,8 +114,11 @@ def test_mfpymake(function_tmpdir, meson: bool) -> None: else: fc = os.environ.get("FC") cmd.append(fc) - if system() == "Darwin" and fc == "gfortran": - set_env(**{"LDFLAGS": "-Wl,-ld_classic"}) + + # if system() == "Darwin" and fc == "gfortran": + # set_env(**{"LDFLAGS": "-Wl,-ld_classic"}) + linker_update_environment(fc=fc) + if meson: cmd.append("--meson") run_cli_cmd(cmd) diff --git a/autotest/test_mf6_existing_meson.py b/autotest/test_mf6_existing_meson.py index b2ad444..a3750d7 100644 --- a/autotest/test_mf6_existing_meson.py +++ b/autotest/test_mf6_existing_meson.py @@ -3,6 +3,7 @@ from pathlib import Path from platform import system from typing import List +from pymake import linker_update_environment import pytest from modflow_devtools.ostags import get_binary_suffixes @@ -82,6 +83,8 @@ def test_build_with_existing_meson(pm, module_tmpdir, workspace, targets): pm.download_target(targets[0], download_path=module_tmpdir) assert pm.download, f"could not download {targets[0]} distribution" + linker_update_environment(cc=cc, fc=fc) + # make modflow 6 with existing meson.build file returncode = pymake.meson_build( workspace, diff --git a/pixi.toml b/pixi.toml index 20ecafc..1997cd3 100644 --- a/pixi.toml +++ b/pixi.toml @@ -33,8 +33,9 @@ ruff = "*" postinstall = "pip install --no-build-isolation --no-deps --disable-pip-version-check -e ." # format -check-format = "ruff check ." -fix-format = "ruff check . --fix" +check-lint = "ruff check ." +check-format = "ruff format . --check" +fix-format = "ruff format ." # build test = "meson test --verbose --no-rebuild -C" diff --git a/pymake/__init__.py b/pymake/__init__.py index 969ad52..077f485 100644 --- a/pymake/__init__.py +++ b/pymake/__init__.py @@ -30,6 +30,7 @@ repo_latest_version, zip_all, ) +from .utils._compiler_switches import linker_update_environment # utilities from .utils.usgsprograms import usgs_program_data diff --git a/pymake/utils/_compiler_switches.py b/pymake/utils/_compiler_switches.py index 69725e4..d19eff4 100644 --- a/pymake/utils/_compiler_switches.py +++ b/pymake/utils/_compiler_switches.py @@ -1,5 +1,5 @@ -"""Private functions for setting c/c++ and fortran compiler flags and -appropriate linker flags for defined targets. +"""Public and private functions for setting c/c++ and fortran compiler +flags and appropriate linker flags for defined targets. """ import os @@ -18,6 +18,28 @@ ) +def linker_update_environment(cc="gcc", fc="gfortran", verbose=False): + """Add additional LDFLAGS to the environment based on OS and compilers. + + Parameters + ---------- + fc : str + fortran compiler + cc : str + c or cpp compiler + verbose : bool + boolean for verbose output to terminal + + Returns + ------- + None + """ + syslibs = _darwin_syslibs(cc, fc, verbose=verbose) + if syslibs is not None: + environ = os.environ + environ.update({"LDFLAGS": syslibs}) + + def _check_gnu_switch_available(switch, compiler="gfortran", verbose=False): """Determine if a specified GNU compiler switch exists. Not all switches will be detected, for example '-O2' adn '-fbounds-check=on'. @@ -971,7 +993,7 @@ def _set_syslibs( # set default syslibs if default_syslibs: syslibs.append("-lc") - + darwin_options = _darwin_syslibs(cc, fc, verbose) if darwin_options is not None: syslibs.append(darwin_options) @@ -1060,8 +1082,11 @@ def _darwin_syslibs(cc, fc, verbose=False): """ linker_str = None if _get_osname() == "darwin": - if cc in ("gcc", "g++",) or fc in ("gfortran",): - cmd = ["pkgutil", "--pkg-info=com.apple.pkg.CLTools_Executables"] + if cc in ( + "gcc", + "g++", + ) or fc in ("gfortran",): + cmd = ["pkgutil", "--pkg-info=com.apple.pkg.CLTools_Executables"] out_lines = check_output(cmd).decode("utf-8").splitlines() version = None tag = "version: " @@ -1077,4 +1102,4 @@ def _darwin_syslibs(cc, fc, verbose=False): print(f"C/C++ compiler: {cc} \nFortran compiler: {fc}") print(f"Command line tools version: {version}") print(f"Command line tools major version number: {major}") - return linker_str \ No newline at end of file + return linker_str