Skip to content

Commit

Permalink
Initial policy set modules are now correctly treated like manually ad…
Browse files Browse the repository at this point in the history
…ded modules, rather than dependencies

Signed-off-by: jakub-nt <175944085+jakub-nt@users.noreply.github.com>
  • Loading branch information
jakub-nt committed Aug 28, 2024
1 parent 48f4267 commit 3953340
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
25 changes: 14 additions & 11 deletions cfbs/cfbs_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions cfbs/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions cfbs/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
from cfbs.pretty import pretty


def is_module_added_manually(added_by: str):
return added_by in ("cfbs add", "cfbs init")


class Module:
"""Class representing a module in cfbs.json"""

Expand Down

0 comments on commit 3953340

Please sign in to comment.