-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
unify Version handling of the implementation
- Loading branch information
Showing
8 changed files
with
92 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
function(get_git_commit_hash OUTPUT_VAR) | ||
# Ensure Git is available | ||
find_package(Git QUIET REQUIRED) | ||
|
||
# Run a Git command to get the current commit hash | ||
execute_process( | ||
COMMAND ${GIT_EXECUTABLE} rev-parse HEAD | ||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} | ||
OUTPUT_VARIABLE GIT_COMMIT_HASH | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
ERROR_VARIABLE GIT_ERROR | ||
ERROR_STRIP_TRAILING_WHITESPACE | ||
) | ||
|
||
# Check if the Git command was successful | ||
if (NOT GIT_COMMIT_HASH OR GIT_ERROR) | ||
message(WARNING "Failed to retrieve Git commit hash: ${GIT_ERROR}") | ||
set(${OUTPUT_VAR} "UNKNOWN" PARENT_SCOPE) | ||
else() | ||
# Pass the hash back to the calling scope | ||
set(${OUTPUT_VAR} "${GIT_COMMIT_HASH}" PARENT_SCOPE) | ||
endif() | ||
endfunction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
function(polyhedral_gravity_parse_version OUTPUT_VAR) | ||
# Read the content of the given header file | ||
file(READ "${PROJECT_SOURCE_DIR}/src/polyhedralGravity/Version.h" HEADER_CONTENTS) | ||
# Extract the version using regex | ||
string(REGEX MATCH "constexpr std::string_view POLYHEDRAL_GRAVITY_VERSION = \"([0-9]+\\.[0-9]+\\.[0-9]+[a-zA-Z0-9]*)\"" VERSION_MATCH "${HEADER_CONTENTS}") | ||
# Set the output variable to the matched version group | ||
if(CMAKE_MATCH_1) | ||
set(${OUTPUT_VAR} "${CMAKE_MATCH_1}" PARENT_SCOPE) | ||
else() | ||
message(FATAL_ERROR "Failed to parse POLYHEDRAL_GRAVITY_VERSION from '${HEADER_FILE}'") | ||
endif() | ||
endfunction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,27 @@ def get_cmake_generator(): | |
else: | ||
return None | ||
|
||
def get_version(): | ||
"""Returns the version of the polyhedral gravity package by reading Version.h.""" | ||
# Construct the path to Version.h relative to the current file | ||
version_file = os.path.join(os.path.dirname(__file__), "src", "polyhedralGravity", "Version.h") | ||
|
||
# Check if the Version.h file exists | ||
if not os.path.exists(version_file): | ||
raise FileNotFoundError(f"Version file not found: {version_file}") | ||
|
||
# Open and read the file | ||
with open(version_file, "r") as file: | ||
content = file.read() | ||
|
||
# Use regex to extract the version string | ||
version_match = re.search(r'POLYHEDRAL_GRAVITY_VERSION\s*=\s*\"([^\"]+)\"', content) | ||
if version_match: | ||
return version_match.group(1) | ||
else: | ||
raise ValueError("Version string not found in Version.h") | ||
|
||
|
||
# ----------------------------------------------------------------------------------------- | ||
# The following is adapted from https://github.com/pybind/cmake_example/blob/master/setup.py | ||
# ----------------------------------------------------------------------------------------- | ||
|
@@ -173,7 +194,7 @@ def build_extension(self, ext): | |
# -------------------------------------------------------------------------------- | ||
setup( | ||
name="polyhedral_gravity", | ||
version="3.2.1", | ||
version=get_version(), | ||
author="Jonas Schuhmacher", | ||
author_email="[email protected]", | ||
description="Package to compute full gravity tensor of a given constant density polyhedron for arbitrary points " | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#pragma once | ||
|
||
#include <string_view> | ||
|
||
namespace polyhedralGravity { | ||
|
||
/** | ||
* The API version of the polyhedral gravity model's interface. | ||
* This value is utilized across C++ and Python Interface and the single value | ||
* to change in case of updates. | ||
*/ | ||
constexpr std::string_view POLYHEDRAL_GRAVITY_VERSION = "3.2.1"; | ||
|
||
|
||
}// namespace polyhedralGravity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters