Skip to content

Commit

Permalink
cmake >= 3.10, better feedback, Numpy 1.20 types
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Feb 11, 2021
1 parent f3895ee commit 2d0d219
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 46 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.x'
python-version: '3.7'

- run: pip install .[tests,lint]

- run: flake8
- run: mypy .
- run: mypy

- run: pytest

Expand All @@ -32,7 +32,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.x'
python-version: '3.7'

- run: pip install .[tests]

Expand All @@ -45,7 +45,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.x'
python-version: '3.7'

- run: pip install .[tests]

Expand Down
6 changes: 2 additions & 4 deletions .mypy.ini
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
[mypy]
files = src/

ignore_missing_imports = True
strict_optional = False
allow_redefinition = True
show_error_context = False
show_column_numbers = True
warn_unreachable = False

[mypy-xarray]
follow_imports = skip
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
requires = ["setuptools", "wheel"]

[tool.black]
line-length = 132
line-length = 100

[tool.pytest.ini_options]
addopts = "-ra -v"
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = wmm2015
version = 1.1.0
version = 1.1.1
author = Michael Hirsch, Ph.D.
url = https://github.com/space-physics/wmm2015
description = WMM2015 geomagnetic model with simple object-oriented Python interface
Expand Down
17 changes: 12 additions & 5 deletions src/wmm2015/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
cmake_minimum_required(VERSION 3.12)
cmake_minimum_required(VERSION 3.10)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Debug or Release" FORCE)
endif()
project(wmm15 LANGUAGES C)
enable_testing()
project(wmm20 LANGUAGES C)

include(CTest)

include(CheckSymbolExists)
check_symbol_exists(sqrt math.h NONEED_M)
if(NOT NONEED_M)
set(CMAKE_REQUIRED_LIBRARIES m)
check_symbol_exists(sqrt math.h NEED_M)
endif()

add_library(geo src/GeomagnetismLibrary.c)
set_target_properties(geo PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
if((NOT MSVC) AND
NOT (WIN32 AND CMAKE_C_COMPILER_ID STREQUAL Intel))
if(NEED_M)
target_link_libraries(geo m)
endif()

Expand Down
41 changes: 19 additions & 22 deletions src/wmm2015/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@

# NOTE: must be str() for Windows, even with py37
dllfn = get_libpath(BDIR, "wmm15")
if dllfn is not None:
libwmm = ct.cdll.LoadLibrary(str(dllfn))
else:
if not dllfn.is_file():
build()
dllfn = get_libpath(BDIR, "wmm15")
if dllfn:
libwmm = ct.cdll.LoadLibrary(str(dllfn))
else:
if not dllfn.is_file():
raise ModuleNotFoundError(f"could not find {dllfn}")

libwmm = ct.cdll.LoadLibrary(str(dllfn))


def wmm(glats: np.ndarray, glons: np.ndarray, alt_km: float, yeardec: float) -> xarray.Dataset:
"""
Expand Down Expand Up @@ -165,21 +163,20 @@ def transect(glats: np.ndarray, glons: np.ndarray, alt_km: np.ndarray, yeardec:

assert ret == 0

if len(sz) == 0:
north = x.value
east = y.value
down = z.value
total = T.value
decl = D.value
incl = mI.value
else:
north[i] = x.value
east[i] = y.value
down[i] = z.value
total[i] = T.value
decl[i] = D.value
incl[i] = mI.value

rd = {"north": north, "east": east, "down": down, "total": total, "decl": decl, "incl": incl}
north[i] = x.value
east[i] = y.value
down[i] = z.value
total[i] = T.value
decl[i] = D.value
incl[i] = mI.value

rd = {
"north": north[()],
"east": east[()],
"down": down[()],
"total": total[()],
"decl": decl[()],
"incl": incl[()],
}

return rd
7 changes: 0 additions & 7 deletions src/wmm2015/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
import subprocess
import sys

R = Path(__file__).resolve().parent
SRCDIR = R
BINDIR = SRCDIR / "build"


def build():
"""
Expand All @@ -35,7 +31,4 @@ def get_libpath(bin_dir: Path, stem: str) -> Path:
elif sys.platform == "darwin":
dllfn = bin_dir / ("lib" + stem + ".dylib")

if not dllfn.is_file():
dllfn = None

return dllfn
6 changes: 4 additions & 2 deletions src/wmm2015/setup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
set(_opts)

# --- boilerplate follows
set(CTEST_TEST_TIMEOUT 10)

message(STATUS "CMake ${CMAKE_VERSION}")
if(CMAKE_VERSION VERSION_LESS 3.15)
message(FATAL_ERROR "Please update CMake >= 3.15.
if(CMAKE_VERSION VERSION_LESS 3.10)
message(FATAL_ERROR "Please update CMake >= 3.10.
Try 'pip install -U cmake' or https://cmake.org/download/")
endif()

Expand Down

0 comments on commit 2d0d219

Please sign in to comment.