Skip to content

Commit

Permalink
Bugfix/coreversion (#143)
Browse files Browse the repository at this point in the history
* bugfix: project.json core on level0 breaks deployment

* refactor, deleted unused code

* removed project.json core usage completely

* removed obsolete comments
  • Loading branch information
Grashalmbeisser authored May 6, 2024
1 parent b0dbfad commit 7995330
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 39 deletions.
20 changes: 9 additions & 11 deletions src/viur_cli/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,22 @@ 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"]:
self.find_key(self, target_key="application_name", target="default", keep=True)
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"):
Expand Down Expand Up @@ -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()


Expand Down
51 changes: 23 additions & 28 deletions src/viur_cli/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand All @@ -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.
Expand All @@ -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):
Expand Down

0 comments on commit 7995330

Please sign in to comment.