From eabc0bb148b8b79ccd5bdf78c5c5b2adc78c8a6a Mon Sep 17 00:00:00 2001
From: haufs <steffen.hauf@xfel.eu>
Date: Sun, 22 Nov 2020 22:32:24 +0100
Subject: [PATCH 1/2] Autogenerated version update for Karabo 2.10

---
 .gitlab-ci.yml                           | 49 ++++++++++++++++++++++++
 setup.py                                 | 28 +++++++++-----
 src/dataFlowAnalyzer/DataFlowAnalyzer.py |  9 +++--
 3 files changed, 73 insertions(+), 13 deletions(-)
 create mode 100644 .gitlab-ci.yml

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
new file mode 100644
index 0000000..461157d
--- /dev/null
+++ b/.gitlab-ci.yml
@@ -0,0 +1,49 @@
+
+.test_build_template: &test_build_latest
+  script:
+    - export REL_OS_NAME=$(lsb_release -is)
+    - export REL_OS_VERS=$(lsb_release -rs | sed -r "s/^([0-9]+).*/\1/")
+    - export REL_PROJECT_NAME=$CI_PROJECT_NAME
+    - export REL_TAG=$CI_BUILD_REF_NAME
+    - export KARABO_TAG="latest_build"
+    - export GIT_TOKEN=$XFEL_TOKEN
+    - export CI_BUILD="LATEST"
+    - export KARABO_BROKER_TOPIC="gitlab_ci_$CI_JOB_ID"
+    - curl http://exflserv05.desy.de/karabo/karaboFramework/tags/$KARABO_TAG/karabo-$KARABO_TAG-Release-$REL_OS_NAME-$REL_OS_VERS-x86_64.sh > karabo.sh
+    - bash karabo.sh --prefix=/root
+    - source /root/karabo/activate
+    - git config --global user.email "xfel.redmine@xfel.eu"
+    - git config --global user.name "xfel.redmine"
+    - cd $CI_PROJECT_DIR
+    # install depends
+    - >
+        if test -f "DEPENDS"; then
+           IFS=","
+           while read line; do
+               [[ $line =~ ^#.* ]] && continue
+               norm=${line/,/ }
+               norm=`echo $norm | sed -e "s/[[:space:]]\+/ /g"`
+               device=$(echo $norm | cut -f1 -d' ')
+               tag=$(echo $norm | cut -f2 -d' ')
+               echo $device
+               echo $tag
+               karabo -g https://$XFEL_TOKEN@git.xfel.eu/gitlab install $device $tag
+           done < DEPENDS        
+        fi;
+
+
+    - pip install -e . 
+    # run a device server to test for syntax errors
+    - karabo-middlelayerserver serverId=test > test.log &
+    - karabo-pythonserver serverId=test2 >> test.log &
+    - sleep 15
+    - if [[ $(grep -e SyntaxError -e ImportError test.log) ]]; then exit 1; else exit 0; fi
+    # - nosetests . uncomment this line to enable actual unit tests!
+
+
+test:centos7-latest:
+  image: europeanxfel/karabo-ci:centos-7gcc7
+  before_script:
+    - source /opt/rh/devtoolset-7/enable
+  <<: *test_build_latest
+
diff --git a/setup.py b/setup.py
index 3f32b02..14480f7 100644
--- a/setup.py
+++ b/setup.py
@@ -1,20 +1,22 @@
 #!/usr/bin/env python
-from os.path import dirname
-from setuptools import setup, find_packages
+import shutil
+from os.path import dirname, join, realpath
 
+from setuptools import find_packages, setup
 
-def _get_version_string():
-    try:
-        from karabo.packaging.versioning import get_package_version
-    except ImportError:
-        print("WARNING: Karabo framework not found! Version will be blank!")
-        return ''
+ROOT_FOLDER = dirname(realpath(__file__))
+VERSION_FILE_PATH = join(ROOT_FOLDER, '_version.py')
 
-    return get_package_version(dirname(__file__))
+try:
+    from karabo.packaging.versioning import device_scm_version
+    scm_version = device_scm_version(ROOT_FOLDER, VERSION_FILE_PATH)
+except ImportError:
+    # compatibility with karabo versions earlier than 2.10
+    scm_version = {'write_to': VERSION_FILE_PATH}
 
 
 setup(name='DataFlowAnalyzer',
-      version=_get_version_string(),
+      use_scm_version=scm_version,
       author='zhujun',
       author_email='jun.zhu@xfel.eu',
       description='',
@@ -30,3 +32,9 @@ setup(name='DataFlowAnalyzer',
       package_data={},
       requires=[],
       )
+
+
+# copy to subpaths with Karabo class files
+
+shutil.copy(join(ROOT_FOLDER, '_version.py'),
+            join(ROOT_FOLDER, "src/dataFlowAnalyzer"))
diff --git a/src/dataFlowAnalyzer/DataFlowAnalyzer.py b/src/dataFlowAnalyzer/DataFlowAnalyzer.py
index c2f4ae6..fb5082c 100644
--- a/src/dataFlowAnalyzer/DataFlowAnalyzer.py
+++ b/src/dataFlowAnalyzer/DataFlowAnalyzer.py
@@ -7,13 +7,13 @@ import asyncio
 from asyncio import coroutine
 
 import zmq
-
-from karabo.middlelayer import Device, Slot, String, Hash
+from karabo.middlelayer import Device, Hash, Slot, String
 from karabo.middlelayer_api.device_client import getConfiguration
 
+from ._version import version as deviceVersion
 from .device_graph import DeviceGraph
-from .helpers import sanitize
 from .exceptions import DataFlowAnalyzerError
+from .helpers import sanitize
 
 
 def get_connections(device_id, timeout):
@@ -100,6 +100,9 @@ def _analyze_devices(devices, callback, timeout=None):
 
 
 class DataFlowAnalyzer(Device):
+    # provide version for classVersion property
+    __version__ = deviceVersion
+
     server = String(
         displayedName="Server Address",
         description="TCP address of the server"
-- 
GitLab


From e081b192318499872bf91975eb03adb5ebcc425a Mon Sep 17 00:00:00 2001
From: Andrea Parenti <andrea.parenti@xfel.eu>
Date: Mon, 30 Nov 2020 14:03:10 +0100
Subject: [PATCH 2/2] Update .gitignore

---
 .gitignore     | 1 +
 .gitlab-ci.yml | 5 ++---
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/.gitignore b/.gitignore
index b7018dc..54bf119 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,3 +8,4 @@ __pycache__
 *egg-info
 .cache
 .ipynb_checkpoints
+_version.py
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 461157d..5505aa7 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -28,11 +28,10 @@
                echo $device
                echo $tag
                karabo -g https://$XFEL_TOKEN@git.xfel.eu/gitlab install $device $tag
-           done < DEPENDS        
+           done < DEPENDS
         fi;
 
-
-    - pip install -e . 
+    - pip install -e .
     # run a device server to test for syntax errors
     - karabo-middlelayerserver serverId=test > test.log &
     - karabo-pythonserver serverId=test2 >> test.log &
-- 
GitLab