-
Notifications
You must be signed in to change notification settings - Fork 593
Add Versioning Support from version.txt
#3140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
paulromano
merged 31 commits into
openmc-dev:develop
from
ahnaf-tahmid-chowdhury:version
Feb 21, 2025
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
5779779
single source of truth for version identifier
ahnaf-tahmid-chowdhury 104dfb0
Follow PyPA compliant
ahnaf-tahmid-chowdhury cb849ee
move version file to root-level
ahnaf-tahmid-chowdhury 0ce318c
add get_version_info function
ahnaf-tahmid-chowdhury 0eff6a4
Merge remote-tracking branch 'upstream/develop' into version
ahnaf-tahmid-chowdhury dd6e579
Merge remote-tracking branch 'upstream/develop' into version
ahnaf-tahmid-chowdhury 23b93e3
add export config
ahnaf-tahmid-chowdhury 31e3692
remove version file
ahnaf-tahmid-chowdhury d6be0ff
Ensure the version string matches a standard format
ahnaf-tahmid-chowdhury 8bc99cd
set fetch depth to zero
ahnaf-tahmid-chowdhury 2eb6c93
Merge branch 'develop' into version
shimwell 5219406
add hash
ahnaf-tahmid-chowdhury d4b37cf
Add more log
ahnaf-tahmid-chowdhury 160bf43
clang format
ahnaf-tahmid-chowdhury 2b47355
Find git at the beginning
ahnaf-tahmid-chowdhury 923f84a
add VERSION_COMMIT_COUNT
ahnaf-tahmid-chowdhury 07c65a3
Increment release number for dev versions
ahnaf-tahmid-chowdhury 940c571
Merge remote-tracking branch 'upstream/develop' into version
ahnaf-tahmid-chowdhury 21594d6
Move versioning to a separate file, as suggested by @gonuke
ahnaf-tahmid-chowdhury 14e678f
add more info
ahnaf-tahmid-chowdhury 075f92b
Merge remote-tracking branch 'upstream/develop' into version
ahnaf-tahmid-chowdhury dc28e2a
Update cmake/Modules/GetVersionFromGit.cmake
ahnaf-tahmid-chowdhury e2a64d7
Update cmake/Modules/GetVersionFromGit.cmake
ahnaf-tahmid-chowdhury 1603dc5
add more variables
ahnaf-tahmid-chowdhury 9dc344e
Update cmake/Modules/GetVersionFromGit.cmake
ahnaf-tahmid-chowdhury efc43ba
Merge branch 'develop' into version
ahnaf-tahmid-chowdhury a2942f6
Don't use PROJECT_ variable names
paulromano 727a0ae
Get rid of unused variables
paulromano 8440b2c
Fix fetch-depth
paulromano 8ddcb06
Set fetch-depth to 0 as before
paulromano ece247a
Update cmake/Modules/GetVersionFromGit.cmake
paulromano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,3 @@ | ||
| commit: $Format:%H$ | ||
| commit-date: $Format:%cI$ | ||
| describe-name: $Format:%(describe:tags=true,match=*[0-9]*)$ |
This file contains hidden or 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 @@ | ||
| .git_archival.txt export-subst |
This file contains hidden or 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 hidden or 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 hidden or 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,109 @@ | ||
| # GetVersionFromGit.cmake | ||
| # Standalone script to retrieve versioning information from Git or .git_archival.txt. | ||
| # Customizable for any project by setting variables before including this file. | ||
|
|
||
| # Configurable variables: | ||
| # - VERSION_PREFIX: Prefix for version tags (default: "v"). | ||
| # - VERSION_SUFFIX: Suffix for version tags (default: "[~+-]([a-zA-Z0-9]+)"). | ||
| # - VERSION_REGEX: Regex to extract version (default: "(?[0-9]+\\.[0-9]+\\.[0-9]+)"). | ||
| # - ARCHIVAL_FILE: Path to .git_archival.txt (default: "${CMAKE_SOURCE_DIR}/.git_archival.txt"). | ||
| # - DESCRIBE_NAME_KEY: Key for describe name in .git_archival.txt (default: "describe-name: "). | ||
| # - COMMIT_HASH_KEY: Key for commit hash in .git_archival.txt (default: "commit: "). | ||
|
|
||
| # Default Format Example: | ||
| # 1.2.3 v1.2.3 v1.2.3-rc1 | ||
|
|
||
| set(VERSION_PREFIX "v" CACHE STRING "Prefix used in version tags") | ||
| set(VERSION_SUFFIX "[~+-]([a-zA-Z0-9]+)" CACHE STRING "Suffix used in version tags") | ||
| set(VERSION_REGEX "?([0-9]+\\.[0-9]+\\.[0-9]+)" CACHE STRING "Regex for extracting version") | ||
| set(ARCHIVAL_FILE "${CMAKE_SOURCE_DIR}/.git_archival.txt" CACHE STRING "Path to .git_archival.txt") | ||
| set(DESCRIBE_NAME_KEY "describe-name: " CACHE STRING "Key for describe name in .git_archival.txt") | ||
| set(COMMIT_HASH_KEY "commit: " CACHE STRING "Key for commit hash in .git_archival.txt") | ||
|
|
||
|
|
||
| # Combine prefix and regex | ||
| set(VERSION_REGEX_WITH_PREFIX "^${VERSION_PREFIX}${VERSION_REGEX}") | ||
|
|
||
| # Find Git | ||
| find_package(Git) | ||
|
|
||
| # Attempt to retrieve version from Git | ||
| if(EXISTS "${CMAKE_SOURCE_DIR}/.git" AND GIT_FOUND) | ||
| message(STATUS "Using git describe for versioning") | ||
|
|
||
| # Extract the version string | ||
| execute_process( | ||
| COMMAND git describe --tags --dirty | ||
| WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} | ||
| OUTPUT_VARIABLE VERSION_STRING | ||
| OUTPUT_STRIP_TRAILING_WHITESPACE | ||
| ) | ||
|
|
||
| # Extract the commit hash | ||
| execute_process( | ||
| COMMAND git rev-parse HEAD | ||
| WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} | ||
| OUTPUT_VARIABLE COMMIT_HASH | ||
| OUTPUT_STRIP_TRAILING_WHITESPACE | ||
| ) | ||
| else() | ||
| message(STATUS "Using archival file for versioning: ${ARCHIVAL_FILE}") | ||
| if(EXISTS "${ARCHIVAL_FILE}") | ||
| file(READ "${ARCHIVAL_FILE}" ARCHIVAL_CONTENT) | ||
|
|
||
| # Extract the describe-name line | ||
| string(REGEX MATCH "${DESCRIBE_NAME_KEY}([^\\n]+)" VERSION_STRING "${ARCHIVAL_CONTENT}") | ||
| if(VERSION_STRING MATCHES "${DESCRIBE_NAME_KEY}(.*)") | ||
| set(VERSION_STRING "${CMAKE_MATCH_1}") | ||
| else() | ||
| message(FATAL_ERROR "Could not extract version from ${ARCHIVAL_FILE}") | ||
| endif() | ||
|
|
||
| # Extract the commit hash | ||
| string(REGEX MATCH "${COMMIT_HASH_KEY}([a-f0-9]+)" COMMIT_HASH "${ARCHIVAL_CONTENT}") | ||
| if(COMMIT_HASH MATCHES "${COMMIT_HASH_KEY}([a-f0-9]+)") | ||
| set(COMMIT_HASH "${CMAKE_MATCH_1}") | ||
| else() | ||
| message(FATAL_ERROR "Could not extract commit hash from ${ARCHIVAL_FILE}") | ||
| endif() | ||
| else() | ||
| message(FATAL_ERROR "Neither git describe nor ${ARCHIVAL_FILE} is available for versioning.") | ||
| endif() | ||
| endif() | ||
|
|
||
| # Ensure version string format | ||
| if(VERSION_STRING MATCHES "${VERSION_REGEX_WITH_PREFIX}") | ||
| set(VERSION_NO_SUFFIX "${CMAKE_MATCH_1}") | ||
| else() | ||
| message(FATAL_ERROR "Invalid version format: Missing base version in ${VERSION_STRING}") | ||
| endif() | ||
|
|
||
| # Check for development state | ||
| if(VERSION_STRING MATCHES "-([0-9]+)-g([0-9a-f]+)") | ||
| set(DEV_STATE "true") | ||
| set(COMMIT_COUNT "${CMAKE_MATCH_1}") | ||
| string(REGEX REPLACE "-([0-9]+)-g([0-9a-f]+)" "" VERSION_WITHOUT_META "${VERSION_STRING}") | ||
| else() | ||
| set(DEV_STATE "false") | ||
| set(VERSION_WITHOUT_META "${VERSION_STRING}") | ||
| endif() | ||
|
|
||
| # Split and set version components | ||
| string(REPLACE "." ";" VERSION_LIST "${VERSION_NO_SUFFIX}") | ||
| list(GET VERSION_LIST 0 VERSION_MAJOR) | ||
| list(GET VERSION_LIST 1 VERSION_MINOR) | ||
| list(GET VERSION_LIST 2 VERSION_PATCH) | ||
|
|
||
| # Increment patch number for dev versions | ||
| if(DEV_STATE) | ||
| math(EXPR VERSION_PATCH "${VERSION_PATCH} + 1") | ||
| endif() | ||
|
|
||
| # Export variables | ||
| set(OPENMC_VERSION_MAJOR "${VERSION_MAJOR}") | ||
| set(OPENMC_VERSION_MINOR "${VERSION_MINOR}") | ||
| set(OPENMC_VERSION_PATCH "${VERSION_PATCH}") | ||
| set(OPENMC_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}") | ||
| set(OPENMC_COMMIT_HASH "${COMMIT_HASH}") | ||
| set(OPENMC_DEV_STATE "${DEV_STATE}") | ||
| set(OPENMC_COMMIT_COUNT "${COMMIT_COUNT}") | ||
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| [build-system] | ||
| requires = ["setuptools", "wheel"] | ||
| requires = ["setuptools", "setuptools-scm", "wheel"] | ||
| build-backend = "setuptools.build_meta" | ||
|
|
||
| [project] | ||
|
|
@@ -8,7 +8,7 @@ authors = [ | |
| {name = "The OpenMC Development Team", email = "[email protected]"}, | ||
| ] | ||
| description = "OpenMC" | ||
| version = "0.15.1-dev" | ||
| dynamic = ["version"] | ||
| requires-python = ">=3.11" | ||
| license = {file = "LICENSE"} | ||
| classifiers = [ | ||
|
|
@@ -66,3 +66,5 @@ exclude = ['tests*'] | |
| "openmc.data.effective_dose" = ["**/*.txt"] | ||
| "openmc.data" = ["*.txt", "*.DAT", "*.json", "*.h5"] | ||
| "openmc.lib" = ["libopenmc.dylib", "libopenmc.so"] | ||
|
|
||
| [tool.setuptools_scm] | ||
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.