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 18 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
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)
# Read the version information from version.txt
file(READ "tools/version.txt" VERSION_STRING)

# Strip any whitespace
string(STRIP "${VERSION_STRING}" VERSION_STRING)

# Match version format and capture the main version part
if(VERSION_STRING MATCHES "^([0-9]+\\.[0-9]+\\.[0-9]+)(-[^ ]+)?$")
set(VERSION_NO_SUFFIX "${CMAKE_MATCH_1}")
else()
message(FATAL_ERROR "Invalid version format in version.txt: ${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)
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
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.10"
license = {file = "LICENSE"}
classifiers = [
Expand Down Expand Up @@ -58,6 +58,9 @@ 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 = "tools/version.txt"}
Copy link
Member

Choose a reason for hiding this comment

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

Does this file need locating elsewhere, perhaps in the source code. I'm not sure but perhaps that helps when packaging as I don't think the tools folder is included in the packaging (e.g. conda)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This file is only required at build time. If it is necessary at runtime, we can put it in the root dir.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It appears that openmc-feedstock uses a specific release tar file, which includes all the folders, including the tools folder.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for answering this

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not an expert, but this doesn't feel like a tools sort of thing. To me it feels like a top level file.

Copy link
Contributor

Choose a reason for hiding this comment

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

Doing it this way means openmc.__version__ still works due to how __version__ is populated.

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 have stored this file in the tools directory because it is only required during build time. Python's wheel uses it to create the wheel, and CMake uses it to generate the version.h file. Additionally, we can use this file for other purposes. I placed it in that folder to keep the root directory clean. However, if necessary, we can move it to the root directory.

Copy link
Contributor

Choose a reason for hiding this comment

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

I tend to agree that this is more of a root-level file.


[tool.setuptools.packages.find]
include = ['openmc*', 'scripts*']
exclude = ['tests*']
Expand Down
1 change: 1 addition & 0 deletions tools/version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.15.1-dev
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 probably beyond the scope of this PR alone, but this isn't PyPA compliant. It should be: 0.15.1.devN (Probably dev1?). Also you accidentally incremented a major release.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Setuptools will handle the task for us, so we can continue using the legacy format.

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 something setuptools does because it's nice to do; not because it has to. I think changing to PyPA compliant is a small change that would reduce the risk of something breaking in the future. (Honestly I don't think many people would even notice beyond some of the core devs.)

Copy link
Contributor

Choose a reason for hiding this comment

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

PyPA does allow -dev but probably better to use a dot since it's perferred

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks. TIL.

ahnaf-tahmid-chowdhury marked this conversation as resolved.
Show resolved Hide resolved