From fe409bfe9d6a2fca7431be3977b8ebb8e04cfebd Mon Sep 17 00:00:00 2001
From: David Schaefer <david.schaefer@ufz.de>
Date: Mon, 30 Nov 2020 12:03:51 +0100
Subject: [PATCH] DmpFlagger: remove git dependency

---
 saqc/flagger/baseflagger.py |  1 -
 saqc/flagger/dmpflagger.py  | 16 ++++++----------
 2 files changed, 6 insertions(+), 11 deletions(-)

diff --git a/saqc/flagger/baseflagger.py b/saqc/flagger/baseflagger.py
index edb275bba..9c6ba4fbe 100644
--- a/saqc/flagger/baseflagger.py
+++ b/saqc/flagger/baseflagger.py
@@ -36,7 +36,6 @@ class BaseFlagger(ABC):
     def __init__(self, dtype):
         # NOTE: the type of the _flags DictOfSeries
         self.dtype = dtype
-        self.extra_defaults = dict()
         # NOTE: the arggumens of setFlags supported from
         #       the configuration functions
         self.signature = ("flag",)
diff --git a/saqc/flagger/dmpflagger.py b/saqc/flagger/dmpflagger.py
index 10c83de4a..bb2eb8ef5 100644
--- a/saqc/flagger/dmpflagger.py
+++ b/saqc/flagger/dmpflagger.py
@@ -1,7 +1,6 @@
 #! /usr/bin/env python
 # -*- coding: utf-8 -*-
 
-import subprocess
 import json
 from copy import deepcopy
 from typing import TypeVar, Optional, List
@@ -36,15 +35,12 @@ FLAGS = ["NIL", "OK", "DOUBTFUL", "BAD"]
 
 
 class DmpFlagger(CategoricalFlagger):
-    def __init__(self, include_version=True):
+    def __init__(self, **kwargs):
         super().__init__(FLAGS)
         self.flags_fields = [FlagFields.FLAG, FlagFields.CAUSE, FlagFields.COMMENT]
-        self.extra_defaults = dict(cause=FLAGS[0], comment="")
-        version = subprocess.run(
-            "git describe --tags --always --dirty", shell=True, check=False, stdout=subprocess.PIPE,
-        ).stdout
-        self.project_version = version.decode().strip() if include_version else ""
         self.signature = ("flag", "comment", "cause", "force")
+
+        self._global_comments = kwargs
         self._flags = None
         self._causes = None
         self._comments = None
@@ -151,8 +147,8 @@ class DmpFlagger(CategoricalFlagger):
         else:
             flag = self.BAD if flag is None else flag
             comment = json.dumps(
-                {"comment": comment,
-                 "commit": self.project_version,
+                {**self._global_comments,
+                 "comment": comment,
                  "test": kwargs.get("func_name", "")}
             )
 
@@ -240,7 +236,7 @@ class DmpFlagger(CategoricalFlagger):
 
     def _construct_new(self, flags, causes, comments) -> DmpFlaggerT:
         new = DmpFlagger()
-        new.project_version = self.project_version
+        new._global_comments = self._global_comments
         new._flags = flags
         new._causes = causes
         new._comments = comments
-- 
GitLab