Skip to content

Commit

Permalink
remove version file
Browse files Browse the repository at this point in the history
  • Loading branch information
ahnaf-tahmid-chowdhury committed Oct 16, 2024
1 parent 23b93e3 commit 31e3692
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 33 deletions.
37 changes: 29 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,38 @@
cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
project(openmc C CXX)

# Read the version information from version.txt
file(READ "version.txt" VERSION_STRING)

# Strip any whitespace
string(STRIP "${VERSION_STRING}" VERSION_STRING)
# Try to get the version from git describe
if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
execute_process(
COMMAND git describe --tags --match "*[0-9]*"
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()

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

# Set OpenMC version
Expand Down
28 changes: 8 additions & 20 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,26 +68,14 @@
# |version| and |release|, also used in various other places throughout the
# built documents.
#
def get_version_info():
"""Read the version information from version.txt"""
version_file = os.path.join(os.path.dirname(__file__), '..', '..', 'version.txt')
with open(version_file, 'r') as f:
version_string = f.read().strip()

# Check for the presence of a development suffix (e.g., -dev or .dev)
if version_string.endswith(('-dev', '.dev')):
version_parts = version_string.split('-')[0].split('.')
release = version_string
else:
version_parts = version_string.split('.')
release = version_string

version = ".".join(version_parts[:2]) # The short X.Y version.

return version, release

# Get version and release from version.txt
version, release = get_version_info()

import openmc

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

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

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
7 changes: 3 additions & 4 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 Down Expand Up @@ -58,9 +58,6 @@ Documentation = "https://docs.openmc.org"
Repository = "https://github.com/openmc-dev/openmc"
Issues = "https://github.com/openmc-dev/openmc/issues"

[tool.setuptools.dynamic]
version = {file = "version.txt"}

[tool.setuptools.packages.find]
include = ['openmc*', 'scripts*']
exclude = ['tests*']
Expand All @@ -70,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
1 change: 0 additions & 1 deletion version.txt

This file was deleted.

0 comments on commit 31e3692

Please sign in to comment.