6 Commits 1313c93cfe ... dc2d45f42f

Author SHA1 Message Date
  Fabian Peter Hammerle dc2d45f42f readme: extend example how to read surface 3 years ago
  Fabian Peter Hammerle f17897dfca readme: added example how to read surface file 3 years ago
  Fabian Peter Hammerle fd1e7e2fa8 fix ModuleNotFoundError for developers not installing package 3 years ago
  Fabian Peter Hammerle 63f6f37e28 fix missing version.py detection for python3.5 3 years ago
  Fabian Peter Hammerle 8209171326 fix ModuleNotFoundError for developers not installing package 3 years ago
  Fabian Peter Hammerle c5a6314d6f test __version__ 3 years ago
3 changed files with 67 additions and 1 deletions
  1. 22 0
      README.rst
  2. 5 1
      freesurfer_surface/__init__.py
  3. 40 0
      tests/test_version.py

+ 22 - 0
README.rst

@@ -27,6 +27,28 @@ Install
 Usage
 -----
 
+Read Surface File
+~~~~~~~~~~~~~~~~~
+
+.. code:: python
+
+    from freesurfer_surface import Surface
+
+    surface = Surface.read_triangular('bert/surf/lh.pial')
+
+    for vertex in surface.vertices[:3]:
+        print(vertex)
+
+    vertex_0 = surface.vertices[0]
+    print('coordinates of vertex #0:', (vertex_0.right, vertex_0.anterior, vertex_0.superior))
+
+    for triangle_index, triangle in enumerate(surface.triangles[:4]):
+        print('\ntriangle #{}:'.format(triangle_index))
+        print('vertex indices:', triangle.vertex_indices)
+        print('vertex coordinates:')
+        for vertex in surface.select_vertices(triangle.vertex_indices):
+            print((vertex.right, vertex.anterior, vertex.superior))
+
 Edit Surface File
 ~~~~~~~~~~~~~~~~~
 

+ 5 - 1
freesurfer_surface/__init__.py

@@ -48,7 +48,11 @@ import typing
 
 import numpy
 
-from freesurfer_surface.version import __version__
+try:
+    from freesurfer_surface.version import __version__
+except ImportError:  # ModuleNotFoundError not available in python<3.6
+    # package is not installed
+    __version__ = None
 
 
 class UnsupportedLocaleSettingError(locale.Error):

+ 40 - 0
tests/test_version.py

@@ -0,0 +1,40 @@
+import re
+import pathlib
+import subprocess
+import sys
+
+import pytest
+
+import freesurfer_surface
+
+_VERSION_MODULE_PATH = pathlib.Path(__file__).parent.parent.joinpath(
+    "freesurfer_surface", "version.py"
+)
+
+
+def test_version():
+    if not _VERSION_MODULE_PATH.exists():
+        pytest.skip("package is not installed")
+    assert re.match(r"^\d+\.\d+\.\d+", freesurfer_surface.__version__)
+
+
+def test_version_missing(tmp_path):
+    temp_module_path = tmp_path.joinpath("version.py")
+    if _VERSION_MODULE_PATH.exists():
+        _VERSION_MODULE_PATH.rename(temp_module_path)
+    try:
+        assert (
+            subprocess.run(
+                [
+                    sys.executable,
+                    "-c",
+                    "import freesurfer_surface; print(freesurfer_surface.__version__)",
+                ],
+                check=True,
+                stdout=subprocess.PIPE,
+            ).stdout.rstrip()
+            == b"None"
+        )
+    finally:
+        if temp_module_path.exists():
+            temp_module_path.rename(_VERSION_MODULE_PATH)