Skip to content
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

Add Versioning Support from version.txt #3140

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
3 changes: 3 additions & 0 deletions .git_archival.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node: $Format:%H$
node-date: $Format:%cI$
describe-name: $Format:%(describe:tags=true,match=*[0-9]*)$
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.git_archival.txt export-subst
7 changes: 5 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,11 @@ jobs:
RDMAV_FORK_SAFE: 1

steps:
- uses: actions/checkout@v4

- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
Expand Down
46 changes: 42 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,49 @@
cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
project(openmc C CXX)

# Set version numbers
set(OPENMC_VERSION_MAJOR 0)
set(OPENMC_VERSION_MINOR 15)
set(OPENMC_VERSION_RELEASE 1)
# Try to get the version from git describe
if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
execute_process(
COMMAND git describe --tags --match "*[0-9]*" --dirty
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE VERSION_STRING
OUTPUT_STRIP_TRAILING_WHITESPACE
)
else()
set(GIT_ARCHIVAL_FILE "${CMAKE_SOURCE_DIR}/.git_archival.txt")
if(EXISTS "${GIT_ARCHIVAL_FILE}")
file(READ "${GIT_ARCHIVAL_FILE}" GIT_ARCHIVAL_CONTENT)

# Extract the describe-name line
string(REGEX MATCH "describe-name: ([^\\n]+)" VERSION_STRING "${GIT_ARCHIVAL_CONTENT}")

# If a match is found, extract the actual version
if(VERSION_STRING MATCHES "describe-name: (.*)")
set(VERSION_STRING "${CMAKE_MATCH_1}")
else()
message(FATAL_ERROR "Could not extract version from .git_archival.txt")
endif()
else()
message(FATAL_ERROR "Neither git describe nor .git_archival.txt is available for versioning.")
endif()
endif()

# Ensure the version string matches a standard format
if(VERSION_STRING MATCHES "^v?([0-9]+\\.[0-9]+\\.[0-9]+)([-].*)?")
set(VERSION_NO_SUFFIX "${CMAKE_MATCH_1}")
else()
message(FATAL_ERROR "Invalid version format: ${VERSION_STRING}")
endif()

# Set OpenMC version
string(REPLACE "." ";" VERSION_LIST "${VERSION_NO_SUFFIX}")
list(GET VERSION_LIST 0 OPENMC_VERSION_MAJOR)
list(GET VERSION_LIST 1 OPENMC_VERSION_MINOR)
list(GET VERSION_LIST 2 OPENMC_VERSION_RELEASE)
Comment on lines +4 to +42
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is complicated and risks getting a different version. couldn't you just run python -m setuptools_scm? This would require the package be installed though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am using a validator in line 32, so if anything goes wrong, it will fail.

Your approach requires both Python and setuptools_scm to be installed first. For now, we can build OpenMC without the Python API. However, if this method is recommended here, we can adopt it.

set(OPENMC_VERSION ${OPENMC_VERSION_MAJOR}.${OPENMC_VERSION_MINOR}.${OPENMC_VERSION_RELEASE})
message(STATUS "OpenMC version: ${OPENMC_VERSION}")

# Generate version.h
configure_file(include/openmc/version.h.in "${CMAKE_BINARY_DIR}/include/openmc/version.h" @ONLY)

# Setup output directories
Expand Down
8 changes: 6 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,14 @@
# |version| and |release|, also used in various other places throughout the
# built documents.
#

import openmc

# The short X.Y version.
version = "0.15"
version = ".".join(openmc.__version__.split('.')[:2])

# The full version, including alpha/beta/rc tags.
release = "0.15.1-dev"
release = openmc.__version__

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
6 changes: 4 additions & 2 deletions pyproject.toml
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]
Expand All @@ -8,7 +8,7 @@ authors = [
{name = "The OpenMC Development Team", email = "openmc@anl.gov"},
]
description = "OpenMC"
version = "0.15.1-dev"
dynamic = ["version"]
requires-python = ">=3.10"
license = {file = "LICENSE"}
classifiers = [
Expand Down Expand Up @@ -67,6 +67,8 @@ exclude = ['tests*']
"openmc.data" = ["*.txt", "*.DAT", "*.json", "*.h5"]
"openmc.lib" = ["libopenmc.dylib", "libopenmc.so"]

[tool.setuptools_scm]

[project.scripts]
openmc-ace-to-hdf5 = "scripts.openmc_ace_to_hdf5:main"
openmc-plot-mesh-tally = "scripts.openmc_plot_mesh_tally:main"
Expand Down