Repository: equinor/iterative_ensemble_smoother (language: python)

Issue:
Add a __version__ attribute
Hi guys,

From what I have seen, the version is not hard-coded but red from GitHub (see pyproject.toml):

Following this procedure:
https://www.moritzkoerber.com/posts/versioning-with-setuptools_scm/

We could get something like:
```
import iterative_ensemble_smoother as ies
ies.__version__
````

This is quite useful when sharing a work based the library if one wants to see what version was used (in a notebook for instance).


Discussion / hints:

Fix patch:
diff --git a/.gitignore b/.gitignore
index ad4a1f17..8b9dee82 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,6 +10,9 @@ __pycache__/
 # C extensions
 *.so
 
+# Exclude the _verison.py from the git control
+src/iterative_ensemble_smoother/_version.py
+
 # Distribution / packaging
 .Python
 build/
diff --git a/pyproject.toml b/pyproject.toml
index 373ef70e..1ecf08e9 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -63,7 +63,10 @@ dev = [
     "pylint"
 ]
 
+# setuptools_scm also writes the version to a file so that one can use the
+# __version__ attribute from the package
 [tool.setuptools_scm]
+write_to = "src/iterative_ensemble_smoother/_version.py"
 
 [tool.pytest.ini_options]
 testpaths = [
diff --git a/src/iterative_ensemble_smoother/__init__.py b/src/iterative_ensemble_smoother/__init__.py
index 1af2fdda..6cac8d67 100644
--- a/src/iterative_ensemble_smoother/__init__.py
+++ b/src/iterative_ensemble_smoother/__init__.py
@@ -3,6 +3,12 @@
 for Data Assimilation and Reservoir History Matching"
 https://www.frontiersin.org/articles/10.3389/fams.2019.00047/full
 """
+try:
+    from ._version import version as __version__
+    from ._version import version_tuple
+except ImportError:
+    __version__ = "unknown version"
+    version_tuple = (0, 0, "unknown version", "unknown commit")
 
 from iterative_ensemble_smoother._iterative_ensemble_smoother import (
     ES,


Test patch:
diff --git a/tests/test_properties.py b/tests/test_properties.py
index c047d242..1599360e 100644
--- a/tests/test_properties.py
+++ b/tests/test_properties.py
@@ -43,6 +43,11 @@ def g(x):
     return x1 + 0.2 * x1**3
 
 
+def test_version_attribute() -> None:
+    assert ies.__version__ != "unknown version"
+    assert ies.version_tuple != (0, 0, "unknown version", "unknown commit")
+
+
 @pytest.mark.parametrize("N", [100, 200])
 def test_that_projection_is_better_for_nonlinear_forward_model_big_N_small_n(N):
     # For non-linear forward model, g, and n<N,