Skip to content

Commit 7fe1490

Browse files
authored
Merge pull request #50 from esa/bits-bytes-and-fixes
Bits Bytes and Fixes
2 parents 77157f0 + b758e78 commit 7fe1490

File tree

11 files changed

+96
-20
lines changed

11 files changed

+96
-20
lines changed

.github/workflows/wheels.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
platforms: all
3232
if: matrix.os == 'ubuntu-latest'
3333
- name: Build wheels (Linux)
34-
uses: pypa/cibuildwheel@v2.22.0
34+
uses: pypa/cibuildwheel@v3.1.4
3535
env:
3636
CIBW_BEFORE_BUILD: pipx install ninja cmake
3737
CIBW_ENABLE: cpython-freethreading pypy
@@ -44,14 +44,14 @@ jobs:
4444
############################# MACOS WHEELS #############################
4545
# We use Apple Clang as it is the only compiler offering cross-compiling for x86_64
4646
# The macOS GitHub Runner is nowadays arm64 based
47-
# For the x86_64, we set the MACOSX_DEPLOYMENT_TARGET='10.13' (released 2017) in order to have support for C++17
48-
# We don't need this for arm64 since macOS arm64 initially supported C++17/ came years later than macOS 10.13
47+
# For the x86_64, we set the MACOSX_DEPLOYMENT_TARGET='10.15' (released 2019) in order to have support for C++17
48+
# We don't need this for arm64 since macOS arm64 initially supported C++17/ came years later than macOS 10.15
4949
- name: Build wheels (macOS)
50-
uses: pypa/cibuildwheel@v2.22.0
50+
uses: pypa/cibuildwheel@v3.1.4
5151
env:
5252
CIBW_BEFORE_BUILD: pipx install ninja cmake
5353
CIBW_ENABLE: cpython-freethreading pypy
54-
CIBW_ENVIRONMENT: 'MACOSX_DEPLOYMENT_TARGET="10.13"'
54+
CIBW_ENVIRONMENT: 'MACOSX_DEPLOYMENT_TARGET="10.15"'
5555
CIBW_ARCHS_MACOS: "x86_64 arm64"
5656
CIBW_TEST_COMMAND: 'python -c "import polyhedral_gravity"'
5757
with:
@@ -65,10 +65,10 @@ jobs:
6565
- uses: ilammy/msvc-dev-cmd@v1
6666
if: matrix.os == 'windows-latest'
6767
- name: Build wheels (Windows)
68-
uses: pypa/cibuildwheel@v2.22.0
68+
uses: pypa/cibuildwheel@v3.1.4
6969
env:
7070
CIBW_BEFORE_BUILD: pipx install ninja cmake
71-
CIBW_ENABLE: pypy # cpython-freethreading is not yet working on Windows
71+
CIBW_ENABLE: pypy cpython-freethreading
7272
CIBW_ARCHS_WINDOWS: "auto64"
7373
CIBW_TEST_COMMAND: 'python -c "import polyhedral_gravity"'
7474
with:

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ if (_LIBCPP_DISABLE_AVAILABILITY)
4848
add_definitions(-D_LIBCPP_DISABLE_AVAILABILITY)
4949
endif ()
5050

51-
if (${CMAKE_CXX_COMPILER_ID} STREQUAL "AppleClang")
51+
if (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" AND (${CMAKE_CXX_COMPILER_ID} STREQUAL "AppleClang" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang"))
5252
# Fixes undefined _VSTD when using Apple Clang 17
5353
message(STATUS "Using Apple Clang compiler. Defining _VSTD=std.")
5454
add_definitions(-D_VSTD=std)

cmake/git.cmake

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
find_package(Git QUIET REQUIRED)
1+
find_package(Git QUIET)
22

33
function(get_git_commit_hash OUTPUT_VAR)
44
# Run a Git command to get the first 8 characters of the current commit hash
5+
if(NOT GIT_FOUND OR NOT GIT_EXECUTABLE)
6+
set(${OUTPUT_VAR} "Unknown" PARENT_SCOPE)
7+
return()
8+
endif()
9+
510
execute_process(
611
COMMAND ${GIT_EXECUTABLE} rev-parse --short=8 HEAD
712
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
@@ -23,6 +28,11 @@ endfunction()
2328

2429
function(is_git_working_tree_clean OUTPUT_VAR)
2530
# Run a Git command to check if the working tree is clean
31+
if(NOT GIT_FOUND OR NOT GIT_EXECUTABLE)
32+
set(${OUTPUT_VAR} "Unknown" PARENT_SCOPE)
33+
return()
34+
endif()
35+
2636
execute_process(
2737
COMMAND ${GIT_EXECUTABLE} diff-index --quiet HEAD --
2838
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
@@ -43,4 +53,29 @@ function(is_git_working_tree_clean OUTPUT_VAR)
4353
message(WARNING "Error while checking Git working tree: ${GIT_ERROR}")
4454
endif()
4555
endif()
56+
endfunction()
57+
58+
function(get_git_version_tag OUTPUT_VAR)
59+
# Runs a git command to return the latest version number (given the most similar git tag)
60+
if(NOT GIT_FOUND OR NOT GIT_EXECUTABLE)
61+
set(${OUTPUT_VAR} "Unknown" PARENT_SCOPE)
62+
return()
63+
endif()
64+
65+
execute_process(
66+
COMMAND git describe --tags --abbrev=0
67+
--match v[0-9]*.[0-9]*.[0-9]* # plain
68+
--match v[0-9]*.[0-9]*.[0-9]*a* # alpha
69+
--match v[0-9]*.[0-9]*.[0-9]*b* # beta
70+
--match v[0-9]*.[0-9]*.[0-9]*rc* # release candidate
71+
--match v[0-9]*.[0-9]*.[0-9]*.post* # post
72+
--match v[0-9]*.[0-9]*.[0-9]*.dev* # dev
73+
OUTPUT_VARIABLE GIT_TAG
74+
ERROR_VARIABLE GIT_TAG_ERR
75+
RESULT_VARIABLE GIT_TAG_RES
76+
OUTPUT_STRIP_TRAILING_WHITESPACE
77+
)
78+
string(LENGTH ${GIT_TAG} TAG_LENGTH)
79+
string(SUBSTRING ${GIT_TAG} 1 ${TAG_LENGTH} VERSION_NUMBER)
80+
set(${OUTPUT_VAR} "${VERSION_NUMBER}" PARENT_SCOPE)
4681
endfunction()

cmake/pybind11.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
include(FetchContent)
22

33
message(STATUS "Setting up Pybind11 Library")
4-
set(PYBIND11_VERSION 2.12.0)
4+
set(PYBIND11_VERSION 3.0.1)
5+
set(PYBIND11_FINDPYTHON ON)
56

67
find_package(pybind11 ${PYBIND11_VERSION} QUIET)
78

setup.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,21 @@ def get_cmake_generator():
5555
else:
5656
return None
5757

58-
def get_version():
58+
def get_git_version():
59+
"""Returns the version of the polyhedral gravity package by using git describe"""
60+
version_string = subprocess.check_output([
61+
"git", "describe", "--tags", "--abbrev=0",
62+
"--match", "v[0-9]*.[0-9]*.[0-9]*", # plain
63+
"--match", "v[0-9]*.[0-9]*.[0-9]*a*", # alpha
64+
"--match", "v[0-9]*.[0-9]*.[0-9]*b*", # beta
65+
"--match", "v[0-9]*.[0-9]*.[0-9]*rc*", # release candidate
66+
"--match", "v[0-9]*.[0-9]*.[0-9]*.post*", # post
67+
"--match", "v[0-9]*.[0-9]*.[0-9]*.dev*", # dev
68+
]).decode("utf-8").strip()
69+
# Remove the leading "v"
70+
return version_string[1:]
71+
72+
def get_cmake_version():
5973
"""Returns the version of the polyhedral gravity package by reading the CMake file."""
6074
# Path to the CMake file
6175
cmake_file = os.path.join(os.path.dirname(__file__), "version.cmake" )
@@ -69,7 +83,7 @@ def get_version():
6983
content = file.read()
7084

7185
# Use regex to extract the PROJECT_VERSION
72-
version_match = re.search(r'set\(PROJECT_VERSION\s+([^\s)]+)\)', content)
86+
version_match = re.search(r'set\(POLYHEDRAL_GRAVITY_VERSION\s+"(.*)"', content)
7387
if version_match:
7488
return version_match.group(1)
7589
else:
@@ -196,7 +210,7 @@ def build_extension(self, ext):
196210
# --------------------------------------------------------------------------------
197211
setup(
198212
name="polyhedral_gravity",
199-
version=get_version(),
213+
version=get_cmake_version(),
200214
author="Jonas Schuhmacher",
201215
author_email="jonas.schuhmacher@tum.de",
202216
description="Package to compute full gravity tensor of a given constant density polyhedron for arbitrary points "
@@ -208,7 +222,7 @@ def build_extension(self, ext):
208222
license="GPLv3",
209223
license_file="LICENSE",
210224
zip_safe=False,
211-
python_requires=">=3.8",
225+
python_requires=">=3.9",
212226
include_package_data=True,
213227
project_urls={
214228
"Homepage": "https://github.com/esa/polyhedral-gravity-model",

src/polyhedralGravity/input/MeshReader.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
namespace polyhedralGravity {
77

88
PolyhedralSource MeshReader::getPolyhedralSource(const std::vector<std::string> &fileNames) {
9+
// Input Sanity Check if the files exists
10+
for (const auto &fileName: fileNames) {
11+
if (!std::filesystem::exists(fileName)) {
12+
throw std::runtime_error("File '" + fileName + "' does not exist.");
13+
}
14+
}
915
switch (fileNames.size()) {
1016
case 0:
1117
throw std::runtime_error("No mesh file given");

src/polyhedralGravity/input/MeshReader.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "polyhedralGravity/util/UtilityContainer.h"
1212
#include <exception>
1313
#include <stdexcept>
14+
#include <filesystem>
1415

1516
namespace polyhedralGravity {
1617

@@ -23,7 +24,8 @@ namespace polyhedralGravity {
2324
* Returns a polyhedral source consisting of vertices and faces by reading mesh input files.
2425
* @param fileNames files specifying a polyhedron
2526
* @return polyhedral source consisting of vertices and faces
26-
* @throws std::invalid_argument exception if the file type is unsupported by the implementation
27+
* @throws std::invalid_argument if the file type is unsupported by the implementation
28+
* @throws std::runtime_error if the provided files do not exist
2729
*/
2830
PolyhedralSource getPolyhedralSource(const std::vector<std::string> &fileNames);
2931

src/polyhedralGravityPython/PolyhedralGravityPython.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
namespace py = pybind11;
1717

18-
PYBIND11_MODULE(polyhedral_gravity, m) {
18+
PYBIND11_MODULE(polyhedral_gravity, m, py::mod_gil_not_used()) {
1919
using namespace polyhedralGravity;
2020
m.doc() = R"mydelimiter(
2121
The evaluation of the polyhedral gravity model requires the following parameters:
@@ -175,6 +175,7 @@ PYBIND11_MODULE(polyhedral_gravity, m) {
175175
176176
Raises:
177177
ValueError: If :code:`integrity_check` is set to :code:`AUTOMATIC` or :code:`VERIFY` and the mesh is inconsistent
178+
RuntimeError: If files given as :code:`polyhedral_source` do not exist
178179
179180
Note:
180181
The :code:`integrity_check` is automatically enabled to avoid wrong results due to the wrong vertex ordering.

test/model/PolyhedronTest.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,3 +335,13 @@ TEST_F(PolyhedronTest, CorrectBigPolyhedron) {
335335
);
336336
}
337337

338+
TEST_F(PolyhedronTest, FileDoesNotExistPolyhedron) {
339+
using namespace testing;
340+
using namespace polyhedralGravity;
341+
// All normals are pointing outwards, extensive Eros example
342+
ASSERT_THROW(Polyhedron(
343+
std::vector<std::string>({"resources/FileDoesNotExist.node", "resources/FileDoesNotExist.face"}),
344+
1.0, NormalOrientation::OUTWARDS, PolyhedronIntegrity::VERIFY), std::runtime_error
345+
);
346+
}
347+

test/python/test_polyhedron.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,11 @@ def test_polyhedron_metric() -> None:
113113
)
114114
assert unitless_polyhedron.density_unit == "unitless"
115115
assert unitless_polyhedron.mesh_unit == "unitless"
116+
117+
def test_failed_polyhedral_construction() -> None:
118+
"""Tests if the construction of a Polyhedron fails when the source is invalid."""
119+
with pytest.raises(RuntimeError):
120+
Polyhedron(
121+
polyhedral_source=["test/resources/FileDoesNotExist.node", "test/resources/FileDoesNotExist.face"],
122+
density=1.0,
123+
)

0 commit comments

Comments
 (0)