Skip to content

Commit

Permalink
Merge pull request #204 from jakub-nt/CFE-4051
Browse files Browse the repository at this point in the history
CFE-4051: Added dependencies of modules added by URL through the index now correctly have `"added_by"` keys in `cfbs.json`
  • Loading branch information
olehermanse authored Aug 14, 2024
2 parents 7c40f7f + b1224c7 commit 48f4267
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
18 changes: 11 additions & 7 deletions cfbs/cfbs_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"])

Expand All @@ -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:
Expand Down Expand Up @@ -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):
Expand Down
18 changes: 11 additions & 7 deletions cfbs/cfbs_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -123,24 +123,28 @@ 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(
"missing required key 'provides' in module definition: %s"
% 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):
Expand Down

0 comments on commit 48f4267

Please sign in to comment.