Skip to content
5 changes: 2 additions & 3 deletions _updateversion.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
#!/usr/bin/env/python
# coding=utf-8

import sys
import os
import subprocess

_HERE = os.path.join(os.path.abspath(os.path.dirname(__file__)),'tofu')
_HERE = os.path.abspath(os.path.dirname(__file__))

def updateversion(path=_HERE):
# Fetch version from git tags, and write to version.py
# Also, when git is not available (PyPi package), use stored version.py
version_py = os.path.join(path,"version.py")
version_py = os.path.join(path, 'tofu', 'version.py')
try:
version_git = subprocess.check_output(["git",
"describe"]).rstrip().decode()
Expand Down
1 change: 1 addition & 0 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Contents

How to install tofu <installation.rst>
A guide to contributing to tofu <contributing.rst>
A list of all different device configurations available (ITER, WEST, JET, ...) <auto_examples/tutorials/tuto_plot_gallery_fusion_machines.rst>
Tutorials and examples <auto_examples/index.rst>

* How to create / handle a diagnostic geometry
Expand Down
27 changes: 14 additions & 13 deletions examples/tutorials/tuto_plot_gallery_fusion_machines.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
A gallery of Fusion Machines
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This tutorial functions as a gallery of fusion machines that can easily be loaded with `tofu`.
This tutorial functions as a gallery of fusion machines that can easily be
loaded with `tofu`.
"""

###############################################################################
Expand All @@ -11,28 +12,28 @@
import tofu as tf

###############################################################################
# `tofu` provides a geometry helper function that allows creating a configuration with a single call.
# `tofu` provides a geometry helper function that allows creating a
# configuration with a single call.
#
# Calling with empty arguments results in a default configuration. At the time of writing, this is ITER.
# By printing the `config` object, a text representation of its components is printed. This allows inspecting
# Calling with empty arguments results in a default configuration. At the time
# of writing, this is ITER.
# By printing the `config` object, a text representation of its components is
# printed. This allows inspecting
# component names, number of sections, color or visibility.

config = tf.geom.utils.create_config()
config = tf.geom.utils.create_config() # create default configuration
print(config)

###############################################################################
# To get a list of all available built-in configs, one has to know some details about `tofu`.
# Configurations can either be accessed by names (ITER, WEST, JET).
# To get a list of all available built-in configs, one has to know some details
# about `tofu`. Configurations can be accessed by names (ITER, WEST, JET, etc).

print(tf.geom.utils._DCONFIG_TABLE.keys())

###############################################################################
# With that being said, let's create a gallery of the "top 3" fusion machines provided by `tofu` to accelerate
# diagnostic development.
# With that being said, let's create a gallery of the "top 3" fusion machines
# provided by `tofu` to accelerate diagnostic development.

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
for fusion_machine in ['ITER', 'WEST', 'JET']:
config = tf.geom.utils.create_config(fusion_machine)
config.plot()
config.plot()
27 changes: 25 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
from Cython.Distutils import build_ext
import numpy as np
# ...
import _updateversion as up
# Remove _updateversion import due to build-time dependency
# => updateversion defined in here for commodity
# => find a cleaner solution later
# import _updateversion as up
# ... for `clean` command
from distutils.command.clean import clean as Clean

Expand Down Expand Up @@ -143,6 +146,26 @@ def check_for_openmp(cc_var):

# == Getting tofu version =====================================================
_HERE = os.path.abspath(os.path.dirname(__file__))


def updateversion(path=_HERE):
# Fetch version from git tags, and write to version.py
# Also, when git is not available (PyPi package), use stored version.py
version_py = os.path.join(path, 'tofu', 'version.py')
try:
version_git = subprocess.check_output(["git",
"describe"]).rstrip().decode()
except Exception as err:
with open(version_py, 'r') as fh:
version_git = fh.read().strip().split("=")[-1].replace("'", '')
version_git = version_git.lower().replace('v', '')

version_msg = "# Do not edit, pipeline versioning governed by git tags!"
with open(version_py, "w") as fh:
msg = "{0}__version__ = '{1}'{0}".format(os.linesep, version_git)
fh.write(version_msg + msg)
return version_git

def get_version_tofu(path=_HERE):

# Try from git
Expand All @@ -163,7 +186,7 @@ def get_version_tofu(path=_HERE):
.decode()
)
if git_branch in ["master"]:
version_tofu = up.updateversion(os.path.join(path, "tofu"))
version_tofu = updateversion(os.path.join(path, "tofu"))
else:
isgit = False
except Exception:
Expand Down
18 changes: 3 additions & 15 deletions tofu/tests/tests09_tutorials/tests01_runall.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@

# External modules
import os
import shutil
import types
import subprocess
import numpy as np
import warnings as warn
import matplotlib.pyplot as plt

# Nose-specific
from nose import with_setup # optional

# Importing package tofu.geom
import tofu as tf
from tofu import __version__

from pathlib import Path

_HERE = os.path.abspath(os.path.dirname(__file__))
_TFROOT = _HERE[:-_HERE[::-1].index('/tofu'[::-1])-len('/tofu')]
# _TFROOT = tf.__path__[0][:-5]
# _PATHTUTO = os.path.join(_TFROOT, 'examples', 'tutorials')
_TFROOT = Path(_HERE).parent.parent.parent

keyVers = 'Vers'


Expand Down
2 changes: 1 addition & 1 deletion tofu/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Do not edit, pipeline versioning governed by git tags!
__version__ = '1.4.2-a4'
__version__ = '1.4.2-a4-5-g9b404aa'