Skip to content

Commit

Permalink
ENH: Add a function snap.get_snap_version to retrieve current SNAP …
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-braun committed Aug 13, 2024
1 parent 656c626 commit 04de7f8
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release History

## 1.42.0 (2024-mm-dd)

- **ENH: Add a function `snap.get_snap_version` to retrieve current SNAP version** ([#172](https://github.com/sertit/eoreader/issues/172))

## 1.41.0 (2024-08-06)

- **BREAKING CHANGE**: Renaming of `rasters(_rio).get_nodata_value` function to `rasters(_rio).get_nodata_value_from_dtype`. Older function is deprecated.
Expand Down
11 changes: 10 additions & 1 deletion CI/SCRIPTS/test_snap.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
import shutil

import pytest
from packaging.version import Version

from sertit import ci, snap
from sertit import ci, misc, snap
from sertit.snap import TILE_SIZE

ci.reduce_verbosity()
Expand Down Expand Up @@ -50,3 +51,11 @@ def test_snap():

for substr in must_appear:
assert substr in cli


def snap_version():
"""Test SNAP version"""
snap_version = snap.get_snap_version()
assert misc.compare(
snap_version, Version("10.0.0"), "=="
), f"Unexpected SNAP version: {snap_version}."
26 changes: 26 additions & 0 deletions sertit/snap.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
"""
import logging
import os
import subprocess

import psutil
from packaging.version import Version

from sertit import misc, strings
from sertit.logs import SU_NAME
Expand Down Expand Up @@ -133,3 +135,27 @@ def get_gpt_cli(
misc.run_cli(gpt_cli + ["--diag"])

return gpt_cli


def get_snap_version() -> Version:
"""Get SNAP version with a call to GPT --diag"""
snap_version = None
try:
output = subprocess.run(["gpt", "--diag"], capture_output=True)
except FileNotFoundError:
raise FileNotFoundError("'gpt' not found in your PATH")

stdout = output.stdout.decode("utf-8")

if stdout is not None:
version_str = stdout.split("\n")
try:
version_str = [v for v in version_str if "version" in v][0]
except IndexError as ex:
LOGGER.debug(ex)
else:
snap_version = version_str.split(" ")[-1]

snap_version = Version(snap_version)

return snap_version

0 comments on commit 04de7f8

Please sign in to comment.