Skip to content

Commit 6abb4c1

Browse files
sbodensteinTorax team
authored and
Torax team
committed
Use dynamically set version from __init__.py.
This allows programmatic querying of the Torax version, for eg. serialization. It is put in a separate version.py file to avoid circular dependencies. PiperOrigin-RevId: 737640092
1 parent 9eee1b9 commit 6abb4c1

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

pyproject.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ build-backend = "setuptools.build_meta"
55
[project]
66
name = "torax"
77
description = "Differentiable 1D tokamak plasma transport simulator in JAX."
8-
version = "0.3.1"
98
readme = "README.md"
109
requires-python = ">=3.10"
1110
license = {file = "LICENSE"}
@@ -42,6 +41,9 @@ dependencies = [
4241
"treelib>=1.3.2",
4342
]
4443

44+
# `version` is automatically set to use the `torax.__version__`
45+
dynamic = ["version"]
46+
4547
[project.urls]
4648
homepage = "https://github.com/google-deepmind/torax"
4749
repository = "https://github.com/google-deepmind/torax"

torax/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
# pylint: disable=g-importing-member
2121

22+
from torax import version
2223
from torax.config.config_loader import import_module
2324
from torax.interpolated_param import InterpolatedVarSingleAxis
2425
from torax.interpolated_param import InterpolatedVarTimeRho
@@ -29,6 +30,8 @@
2930

3031
# pylint: enable=g-importing-member
3132

33+
__version__ = version.TORAX_VERSION
34+
__version_info__ = version.TORAX_VERSION_INFO
3235

3336
__all__ = [
3437
'import_module',

torax/version.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright 2024 DeepMind Technologies Limited
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
"""Torax version information."""
15+
16+
from typing import Final
17+
18+
# b/404741308: This is currently a closest tag that could be made more
19+
# fine-grained in the future, eg. based on an actual commit.
20+
TORAX_VERSION: Final[str] = "0.3.1"
21+
22+
23+
def _version_as_tuple(version_str: str) -> tuple[int, int, int]:
24+
return tuple(int(i) for i in version_str.split(".") if i.isdigit())
25+
26+
27+
TORAX_VERSION_INFO: Final[tuple[int, int, int]] = _version_as_tuple(
28+
TORAX_VERSION
29+
)

0 commit comments

Comments
 (0)