From dc86e2816d22cebbf077c2615f002e09c5cac509 Mon Sep 17 00:00:00 2001 From: Chaoyi Yuan Date: Thu, 11 Jul 2019 15:15:27 +0800 Subject: [PATCH] allow non module project (#400) * Allow non-module project in modules folder * Fix py27 unicode issue * Remove language property for module --- iotedgedev/module.py | 6 ------ iotedgedev/modules.py | 12 +++++++++--- .../modules/non_module_project/placeholder.txt | 0 3 files changed, 9 insertions(+), 9 deletions(-) create mode 100644 tests/assets/test_solution_shared_lib/modules/non_module_project/placeholder.txt diff --git a/iotedgedev/module.py b/iotedgedev/module.py index a4d954c..d442ad6 100644 --- a/iotedgedev/module.py +++ b/iotedgedev/module.py @@ -13,7 +13,6 @@ class Module(object): self.utility = utility self.module_dir = module_dir self.module_json_file = os.path.join(self.module_dir, "module.json") - self.module_language = "csharp" self.file_json_content = None self.load_module_json() @@ -21,7 +20,6 @@ class Module(object): if os.path.exists(self.module_json_file): try: self.file_json_content = json.loads(Utility.get_file_contents(self.module_json_file, expandvars=True)) - self.module_language = self.file_json_content.get("language").lower() except KeyError as e: raise KeyError("Error parsing {0} from module.json file : {1}".format(str(e), self.module_json_file)) except IOError: @@ -29,10 +27,6 @@ class Module(object): else: raise FileNotFoundError("No module.json file found. module.json file is required in the root of your module folder") - @property - def language(self): - return self.module_language - @property def platforms(self): return self.file_json_content.get("image", {}).get("tag", {}).get("platforms", "") diff --git a/iotedgedev/modules.py b/iotedgedev/modules.py index 4ac6970..cb732c9 100644 --- a/iotedgedev/modules.py +++ b/iotedgedev/modules.py @@ -5,6 +5,7 @@ import sys from zipfile import ZipFile import commentjson +import six from six import BytesIO from six.moves.urllib.request import urlopen @@ -145,8 +146,10 @@ class Modules: modules_path = os.path.join(template_file_folder, self.envvars.MODULES_PATH) if os.path.isdir(modules_path): for folder_name in os.listdir(modules_path): - module = Module(self.envvars, self.utility, os.path.join(modules_path, folder_name)) - self._update_module_maps("MODULES.{0}".format(folder_name), module, placeholder_tag_map, tag_build_profile_map, default_platform) + project_folder = os.path.join(modules_path, folder_name) + if os.path.exists(os.path.join(project_folder, "module.json")): + module = Module(self.envvars, self.utility, project_folder) + self._update_module_maps("MODULES.{0}".format(folder_name), module, placeholder_tag_map, tag_build_profile_map, default_platform) # get image tags for ${MODULEDIR.xxx} placeholder user_modules = deployment_manifest.get_user_modules() @@ -301,7 +304,10 @@ class Modules: launch_json_content = Utility.get_file_contents(launch_json_file) for key, value in replacements.items(): launch_json_content = launch_json_content.replace(key, value) - launch_json = commentjson.loads(launch_json_content) + if PY2: + launch_json = commentjson.loads(six.binary_type(launch_json_content)) + else: + launch_json = commentjson.loads(launch_json_content) if is_function and launch_json is not None and "configurations" in launch_json: # for Function modules, there shouldn't be launch config for local debug launch_json["configurations"] = list(filter(lambda x: x["request"] != "launch", launch_json["configurations"])) diff --git a/tests/assets/test_solution_shared_lib/modules/non_module_project/placeholder.txt b/tests/assets/test_solution_shared_lib/modules/non_module_project/placeholder.txt new file mode 100644 index 0000000..e69de29