diff --git a/cfbs/cfbs_config.py b/cfbs/cfbs_config.py index edbe323..ad3a825 100644 --- a/cfbs/cfbs_config.py +++ b/cfbs/cfbs_config.py @@ -19,7 +19,7 @@ ) from cfbs.pretty import pretty, CFBS_DEFAULT_SORTING_RULES from cfbs.cfbs_json import CFBSJson -from cfbs.module import Module +from cfbs.module import Module, is_module_added_manually from cfbs.prompts import prompt_user, YES_NO_CHOICES @@ -101,22 +101,24 @@ def add_with_dependencies( if not module: user_error("Module '%s' not found" % module_str) assert "name" in module + name = module["name"] assert "steps" in module if self._module_is_in_build(module): - print("Skipping already added module '%s'" % module["name"]) + print("Skipping already added module '%s'" % name) return if "dependencies" in module: for dep in module["dependencies"]: - self.add_with_dependencies(dep, remote_config, module["name"]) + self.add_with_dependencies(dep, remote_config, name) if "build" not in self._data: self._data["build"] = [] self._data["build"].append(module) - if str_added_by != "cfbs add": - print( - "Added module: %s (Dependency of %s)" % (module["name"], str_added_by) - ) + + assert "added_by" in module + added_by = module["added_by"] + if not is_module_added_manually(added_by): + print("Added module: %s (Dependency of %s)" % (name, added_by)) else: - print("Added module: %s" % module["name"]) + print("Added module: %s" % name) def _add_using_url( self, @@ -326,11 +328,12 @@ def _add_without_dependencies(self, modules): self["build"].append(module) self._handle_local_module(module) + assert "added_by" in module added_by = module["added_by"] - if added_by == "cfbs add": - print("Added module: %s" % name) - else: + if not is_module_added_manually(added_by): print("Added module: %s (Dependency of %s)" % (name, added_by)) + else: + print("Added module: %s" % name) def _add_modules( self, diff --git a/cfbs/commands.py b/cfbs/commands.py index 0966edb..f530d0b 100644 --- a/cfbs/commands.py +++ b/cfbs/commands.py @@ -64,7 +64,7 @@ ) from cfbs.git_magic import Result, commit_after_command, git_commit_maybe_prompt from cfbs.prompts import YES_NO_CHOICES, prompt_user -from cfbs.module import Module +from cfbs.module import Module, is_module_added_manually class InputDataUpdateFailed(Exception): @@ -521,7 +521,7 @@ def _clean_unused_modules(config=None): return 0 def _someone_needs_me(this) -> bool: - if "added_by" not in this or this["added_by"] == "cfbs add": + if "added_by" not in this or is_module_added_manually(this["added_by"]): return True for other in modules: if not "dependencies" in other: diff --git a/cfbs/module.py b/cfbs/module.py index fa74bd5..c21358f 100644 --- a/cfbs/module.py +++ b/cfbs/module.py @@ -3,6 +3,10 @@ from cfbs.pretty import pretty +def is_module_added_manually(added_by: str): + return (added_by == "cfbs add") or (added_by == "cfbs init") + + class Module: """Class representing a module in cfbs.json"""