فهرست منبع

[Feature] Update install process to manage only major version

monf 8 سال پیش
والد
کامیت
9c6f72d8db

+ 2 - 2
Docs/contributing/dna.md

@@ -10,7 +10,7 @@ This file has a yaml syntax and must be present to allow Kalliope to install it
 | name                       | string | yes      |         |                  | Lowercase. It will be the name of the folder installed in ressources_dir for the target type of resource                              |
 | type                       | string | yes      |         | neuron, stt, tts | The type of resource. This will be used by Kalliope install process to place the resource in the right directory set in resources_dir |
 | author                     | string | no       |         |                  | String that contain info about the author of the modul like a name or a github profile page                                           |
-| kalliope_supported_version | list   | yes      |         | 0.4.0            | list of kalliope version the module support. E.g `- 0.4.0`                                                                            |
+| kalliope_supported_version | list   | yes      |         | 0.4              | list of kalliope __MAJOR__ version the module support. E.g `- 0.4`                                                                    |
 | tags                       | list   | no       |         |                  | list of tags that can help to categorize the module. E.g: "email", "social network", "search engine"                                  |
 
 ## DNA file examples
@@ -22,7 +22,7 @@ type: "neuron"
 author: "The dream team of Kalliope project"
 
 kalliope_supported_version:
-  - 0.4.0
+  - 0.4
 
 tags:
   - "search engine"

+ 1 - 1
Tests/modules/test_invalid_dna.yml

@@ -4,7 +4,7 @@
   author: "Kalliope project team"
 
   kalliope_supported_version:
-    - 0.4.0
+    - 0.4
 
   tags:
     - "test"

+ 1 - 1
Tests/modules/test_valid_dna.yml

@@ -4,7 +4,7 @@
   author: "Kalliope project team"
 
   kalliope_supported_version:
-    - 0.4.0
+    - 0.4
 
   tags:
     - "test"

+ 15 - 6
Tests/test_dna_loader.py

@@ -18,7 +18,7 @@ class TestDnaLoader(unittest.TestCase):
 
     def test_get_yaml_config(self):
 
-        expected_result = {'kalliope_supported_version': ['0.4.0'],
+        expected_result = {'kalliope_supported_version': [0.4],
                            'author': 'Kalliope project team',
                            'type': 'neuron',
                            'name': 'neuron_test',
@@ -35,7 +35,7 @@ class TestDnaLoader(unittest.TestCase):
         expected_result.module_type = "neuron"
         expected_result.tags = ['test']
         expected_result.author = 'Kalliope project team'
-        expected_result.kalliope_supported_version = ['0.4.0']
+        expected_result.kalliope_supported_version = [0.4]
 
         dna_to_test = DnaLoader(self.dna_test_file).get_dna()
 
@@ -57,7 +57,7 @@ class TestDnaLoader(unittest.TestCase):
 
     def test_check_dna(self):
         # check with valid DNA file
-        test_dna = {'kalliope_supported_version': ['0.4.0'],
+        test_dna = {'kalliope_supported_version': [0.4],
                     'author': 'Kalliope project team',
                     'type': 'neuron',
                     'name': 'neuron_test',
@@ -66,7 +66,7 @@ class TestDnaLoader(unittest.TestCase):
         self.assertTrue(DnaLoader(file_path=self.dna_test_file)._check_dna_file(test_dna))
 
         # invalid DNA file, no name
-        test_dna = {'kalliope_supported_version': ['0.4.0'],
+        test_dna = {'kalliope_supported_version': [0.4],
                     'author': 'Kalliope project team',
                     'type': 'neuron',
                     'tags': ['test']}
@@ -74,7 +74,7 @@ class TestDnaLoader(unittest.TestCase):
         self.assertFalse(DnaLoader(file_path=self.dna_test_file)._check_dna_file(test_dna))
 
         # invalid DNA file, no type
-        test_dna = {'kalliope_supported_version': ['0.4.0'],
+        test_dna = {'kalliope_supported_version': [0.4],
                     'author': 'Kalliope project team',
                     'name': 'neuron_test',
                     'tags': ['test']}
@@ -82,7 +82,7 @@ class TestDnaLoader(unittest.TestCase):
         self.assertFalse(DnaLoader(file_path=self.dna_test_file)._check_dna_file(test_dna))
 
         # invalid DNA, wrong type
-        test_dna = {'kalliope_supported_version': ['0.4.0'],
+        test_dna = {'kalliope_supported_version': [0.4],
                     'author': 'Kalliope project team',
                     'type': 'doesnotexist',
                     'name': 'neuron_test',
@@ -105,3 +105,12 @@ class TestDnaLoader(unittest.TestCase):
                     'tags': ['test']}
 
         self.assertFalse(DnaLoader(file_path=self.dna_test_file)._check_dna_file(test_dna))
+
+        # invalid DNA, kalliope_supported_version wrong format
+        test_dna = {'kalliope_supported_version': ['0.4.1'],
+                    'author': 'Kalliope project team',
+                    'type': 'neuron',
+                    'name': 'neuron_test',
+                    'tags': ['test']}
+
+        self.assertFalse(DnaLoader(file_path=self.dna_test_file)._check_dna_file(test_dna))

+ 2 - 2
Tests/test_resources_manager.py

@@ -134,14 +134,14 @@ class TestResourcesmanager(unittest.TestCase):
     def test_check_supported_version(self):
         # version ok
         current_version = '0.4.0'
-        supported_version = ['0.4.0', '0.3.0', '0.2.0']
+        supported_version = ['0.4', '0.3', '0.2']
 
         self.assertTrue(ResourcesManager._check_supported_version(current_version=current_version,
                                                                   supported_versions=supported_version))
 
         # version non ok, useer does not confir
         current_version = '0.4.0'
-        supported_version = ['0.3.0', '0.2.0']
+        supported_version = ['0.3', '0.2']
 
         with mock.patch('kalliope.Utils.query_yes_no', return_value=True):
             self.assertTrue(ResourcesManager._check_supported_version(current_version=current_version,

+ 10 - 0
kalliope/core/ConfigurationManager/DnaLoader.py

@@ -1,3 +1,5 @@
+import re
+
 from kalliope.core import Utils
 from kalliope.core.ConfigurationManager import YAMLLoader
 from kalliope.core.Models.Dna import Dna
@@ -89,5 +91,13 @@ class DnaLoader(object):
                 if not dna_file["kalliope_supported_version"]:
                     Utils.print_danger("kalliope_supported_version cannot be empty")
                     success_loading = False
+                else:
+                    for supported_version in dna_file["kalliope_supported_version"]:
+                        # check if major version is provided
+                        if not len(str(supported_version)) == 3:
+                            Utils.print_danger("kalliope_supported_version cannot handle this format of version %s. "
+                                               "Only major version should be provided" % supported_version)
+                            success_loading = False
+
 
         return success_loading

+ 11 - 5
kalliope/core/ResourcesManager.py

@@ -2,6 +2,7 @@ import getpass
 import logging
 import os
 import shutil
+import re
 
 from git import Repo
 from packaging import version
@@ -257,11 +258,16 @@ class ResourcesManager(object):
         logger.debug("[ResourcesManager] Module supported version: %s" % str(supported_versions))
 
         supported_version_found = False
-        for supported_version in supported_versions:
-            if version.parse(current_version) == version.parse(supported_version):
-                # we found the exact version
-                supported_version_found = True
-                break
+        # Extract major version
+        match_current_version = re.search('^[\d][.][\d]', current_version)
+        if match_current_version:
+            current_version = match_current_version.group(0)
+
+            for supported_version in supported_versions:
+                if version.parse(current_version) == version.parse(supported_version):
+                    # we found the exact version
+                    supported_version_found = True
+                    break
 
         if not supported_version_found:
             # we ask the user if we want to install the module even if the version doesn't match