Skip to content

Commit

Permalink
* update
Browse files Browse the repository at this point in the history
  • Loading branch information
jdhughes-usgs committed Jun 10, 2024
1 parent 44c7ff0 commit 637848f
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 21 deletions.
17 changes: 6 additions & 11 deletions .github/workflows/pymake-linting-install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions autotest/test_cli_cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions autotest/test_mf6_existing_meson.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions pymake/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 31 additions & 6 deletions pymake/utils/_compiler_switches.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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'.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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: "
Expand All @@ -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
return linker_str

0 comments on commit 637848f

Please sign in to comment.