From b1224c7deed9cf6ff9cf168917992e9e6e2bed2f Mon Sep 17 00:00:00 2001 From: jakub-nt <175944085+jakub-nt@users.noreply.github.com> Date: Mon, 12 Aug 2024 20:28:20 +0200 Subject: [PATCH] Added dependencies of modules added by URL through the index now correctly have `"added_by"` keys in `cfbs.json` Signed-off-by: jakub-nt <175944085+jakub-nt@users.noreply.github.com> --- cfbs/cfbs_config.py | 18 +++++++++++------- cfbs/cfbs_json.py | 18 +++++++++++------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/cfbs/cfbs_config.py b/cfbs/cfbs_config.py index 3147eba..edbe323 100644 --- a/cfbs/cfbs_config.py +++ b/cfbs/cfbs_config.py @@ -87,15 +87,17 @@ def longest_module_key_length(self, key) -> int: else 0 ) - def add_with_dependencies(self, module, remote_config=None, dependent=None): + def add_with_dependencies( + self, module, remote_config=None, str_added_by="cfbs add" + ): if type(module) is list: # TODO: reuse logic from _add_modules instead for m in module: - self.add_with_dependencies(m, remote_config, dependent) + self.add_with_dependencies(m, remote_config, str_added_by) return if type(module) is str: module_str = module - module = (remote_config or self).get_module_for_build(module, dependent) + module = (remote_config or self).get_module_for_build(module, str_added_by) if not module: user_error("Module '%s' not found" % module_str) assert "name" in module @@ -109,8 +111,10 @@ def add_with_dependencies(self, module, remote_config=None, dependent=None): if "build" not in self._data: self._data["build"] = [] self._data["build"].append(module) - if dependent: - print("Added module: %s (Dependency of %s)" % (module["name"], dependent)) + if str_added_by != "cfbs add": + print( + "Added module: %s (Dependency of %s)" % (module["name"], str_added_by) + ) else: print("Added module: %s" % module["name"]) @@ -134,7 +138,7 @@ def _add_using_url( remote_config = CFBSJson(path=config_path, url=url, url_commit=url_commit) - provides = remote_config.get_provides() + provides = remote_config.get_provides(added_by) add_all = True # URL specified in to_add, but no specific modules => let's add all (with a prompt) if len(to_add) == 0: @@ -172,7 +176,7 @@ def _add_using_url( ) if answer.lower() not in ("y", "yes"): continue - self.add_with_dependencies(module, remote_config) + self.add_with_dependencies(module, remote_config, str_added_by=added_by) @staticmethod def _convert_added_by(added_by, to_add): diff --git a/cfbs/cfbs_json.py b/cfbs/cfbs_json.py index 804a46d..53cff6f 100644 --- a/cfbs/cfbs_json.py +++ b/cfbs/cfbs_json.py @@ -7,7 +7,7 @@ from cfbs.utils import read_json, user_error -def _construct_provided_module(name, data, url, commit): +def _construct_provided_module(name, data, url, commit, added_by="cfbs add"): # At this point the @commmit part should be removed from url so: # either url should not have an @, # or the @ should be for user@host.something @@ -35,7 +35,7 @@ def _construct_provided_module(name, data, url, commit): "missing required key 'steps' in module definition: %s" % pretty(data) ) module["steps"] = data["steps"] - module["added_by"] = "cfbs add" + module["added_by"] = added_by return module @@ -123,7 +123,7 @@ def __getitem__(self, key): def __contains__(self, key): return key in self._data - def get_provides(self): + def get_provides(self, added_by="cfbs add"): modules = OrderedDict() if "provides" not in self._data: user_error( @@ -131,16 +131,20 @@ def get_provides(self): % pretty(self._data) ) for k, v in self._data["provides"].items(): - module = _construct_provided_module(k, v, self.url, self.url_commit) + module = _construct_provided_module( + k, v, self.url, self.url_commit, added_by + ) modules[k] = module return modules - def get_module_for_build(self, name, dependent): + def get_module_for_build(self, name, added_by="cfbs add"): if "provides" in self._data and name in self._data["provides"]: module = self._data["provides"][name] - return _construct_provided_module(name, module, self.url, self.url_commit) + return _construct_provided_module( + name, module, self.url, self.url_commit, added_by + ) if name in self.index: - return self.index.get_module_object(name) + return self.index.get_module_object(name, added_by) return None def _module_is_in_build(self, module):