From 79953302fe43876cfcb536c8d014e8006b7e115f Mon Sep 17 00:00:00 2001 From: Grashalmbeisser <57599830+Grashalmbeisser@users.noreply.github.com> Date: Mon, 6 May 2024 12:33:46 +0200 Subject: [PATCH] Bugfix/coreversion (#143) * bugfix: project.json core on level0 breaks deployment * refactor, deleted unused code * removed project.json core usage completely * removed obsolete comments --- src/viur_cli/conf.py | 20 ++++++++--------- src/viur_cli/update.py | 51 +++++++++++++++++++----------------------- 2 files changed, 32 insertions(+), 39 deletions(-) diff --git a/src/viur_cli/conf.py b/src/viur_cli/conf.py index 0b6b892..d5004b6 100644 --- a/src/viur_cli/conf.py +++ b/src/viur_cli/conf.py @@ -105,6 +105,14 @@ def find_key(self, dictionary, target_key, target, keep=False): self.find_key(value, target_key, target, keep=keep) + def remove_key(self, dictionary, target_key): + if target_key in dictionary: + del dictionary[target_key] + + for value in list(dictionary.values()): + if isinstance(value, dict): + self.remove_key(value, target_key) + def migrate(self): if "application_name" not in self["default"]: @@ -112,9 +120,7 @@ def migrate(self): if "application_name" in self: del self["application_name"] - #check if core is in any profile - if "core" not in self: - self.find_key(self, target_key="core", target=None) + self.remove_key(self, target_key="core") if old_format := self["default"].get("format"): @@ -202,15 +208,7 @@ def migrate(self): :return: None """ - try: - result = os.popen('pip list --format=json').read() - core_version = [x for x in json.loads(result) if x["name"] == "viur-core"][0]["version"] - self["core"] = core_version - - except: - self["core"] = "submodule" - # conf updates must increase format version self.save() diff --git a/src/viur_cli/update.py b/src/viur_cli/update.py index bc3b417..40804fd 100644 --- a/src/viur_cli/update.py +++ b/src/viur_cli/update.py @@ -3,7 +3,7 @@ import sys import re from .conf import config -from . import cli, echo_error, echo_positive, echo_info, utils +from . import cli, echo_error, echo_info, utils @cli.command(context_settings={"ignore_unknown_options": True}) @@ -20,20 +20,14 @@ def update(action, profile, additional_args): that the specified project configuration exists. Note: - - Ensure that the specified project configuration ('name') is valid and defined in your project's configuration. - - Additional arguments can be used to customize the update process if supported by the action. - """ - conf = config.get_profile(profile) if action == "requirements": create_req(True, profile) - - def create_req(yes, profile, confirm_value=True): """ Load project's pipenv and build a requirements.txt. @@ -53,27 +47,28 @@ def create_req(yes, profile, confirm_value=True): """ conf = config.get_profile(profile) dist_folder = conf["distribution_folder"] - if conf["core"] != "submodule": - if yes or click.confirm( - text=f"Do you want to regenerate the requirements.txt located in the {dist_folder}?", - default=confirm_value): - os.system(f"pipfile2req --hashes > {dist_folder}/requirements.txt") - file_object = open(f"{dist_folder}/requirements.txt", 'r') - generated_requirements = file_object.read() - for line in generated_requirements.splitlines(): - if "]==" in line: - # we got a dependency with extras - generated_requirements += re.sub(r"\[.*?\]", "", line) + "\n" - file_object.close() - - file_obj = open(f"{dist_folder}/requirements.txt", 'w') - file_obj.write(generated_requirements) - file_obj.close() - echo_info("requirements.txt successfully generated") - - if check_req(f"{dist_folder}/requirements.txt"): - if not click.confirm(f"There are some depencency errors, are you sure you want to continue?"): - sys.exit(0) + + if yes or click.confirm( text=f"Do you want to regenerate the requirements.txt located in the {dist_folder}?", + default=confirm_value): + os.system(f"pipfile2req --hashes > {dist_folder}/requirements.txt") + file_object = open(f"{dist_folder}/requirements.txt", 'r') + generated_requirements = file_object.read() + + for line in generated_requirements.splitlines(): + if "]==" in line: + # we got a dependency with extras + generated_requirements += re.sub(r"\[.*?\]", "", line) + "\n" + file_object.close() + + + file_obj = open(f"{dist_folder}/requirements.txt", 'w') + file_obj.write(generated_requirements) + file_obj.close() + echo_info("requirements.txt successfully generated") + + if check_req(f"{dist_folder}/requirements.txt"): + if not click.confirm(f"There are some depencency errors, are you sure you want to continue?"): + sys.exit(0) def check_req(projects_requirements_path):