-
Notifications
You must be signed in to change notification settings - Fork 13
Add the ability to specify custom build steps when adding modules #265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
11b2c15
aae7a7b
35dbb54
95abfca
c8f0083
86679ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,7 @@ | |
| import glob | ||
| import logging as log | ||
| from collections import OrderedDict | ||
| from typing import List | ||
| from typing import List, Optional | ||
|
|
||
| from cfbs.types import CFBSCommandGitResult | ||
| from cfbs.utils import ( | ||
|
|
@@ -37,7 +37,7 @@ | |
| ) | ||
| from cfbs.pretty import pretty, CFBS_DEFAULT_SORTING_RULES | ||
| from cfbs.cfbs_json import CFBSJson | ||
| from cfbs.module import Module, is_module_added_manually | ||
| from cfbs.module import Module, is_module_added_manually, is_module_local | ||
| from cfbs.prompts import prompt_user, prompt_user_yesno | ||
| from cfbs.validate import validate_single_module | ||
|
|
||
|
|
@@ -106,17 +106,15 @@ def longest_module_key_length(self, key) -> int: | |
| else 0 | ||
| ) | ||
|
|
||
| def add_with_dependencies( | ||
| self, module, remote_config=None, str_added_by="cfbs add" | ||
| ): | ||
| def add_with_dependencies(self, module, remote_config=None, 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, str_added_by) | ||
| self.add_with_dependencies(m, remote_config, added_by) | ||
| return | ||
| if type(module) is str: | ||
| module_str = module | ||
| module = (remote_config or self).get_module_for_build(module, str_added_by) | ||
| module = (remote_config or self).get_module_for_build(module, added_by) | ||
| if not module: | ||
| raise CFBSExitError("Module '%s' not found" % module_str) | ||
| if not module: | ||
|
|
@@ -125,7 +123,7 @@ def add_with_dependencies( | |
| name = module["name"] | ||
| assert "steps" in module | ||
| if self._module_is_in_build(module): | ||
| if is_module_added_manually(str_added_by): | ||
| if is_module_added_manually(added_by): | ||
| print("Skipping already added module '%s'" % name) | ||
| return | ||
| if "dependencies" in module: | ||
|
|
@@ -145,10 +143,11 @@ def add_with_dependencies( | |
|
|
||
| def _add_using_url( | ||
| self, | ||
| url, | ||
| url: str, | ||
| to_add: list, | ||
| added_by="cfbs add", | ||
| checksum=None, | ||
| explicit_build_steps=None, | ||
| ): | ||
| url_commit = None | ||
| if url.endswith(SUPPORTED_ARCHIVES): | ||
|
|
@@ -195,7 +194,7 @@ def _add_using_url( | |
| % (i, len(modules), module["name"]), | ||
| ): | ||
| continue | ||
| self.add_with_dependencies(module, remote_config, str_added_by=added_by) | ||
| self.add_with_dependencies(module, remote_config, added_by) | ||
|
|
||
| @staticmethod | ||
| def _convert_added_by(added_by, to_add): | ||
|
|
@@ -297,7 +296,7 @@ def _add_bundles_build_step(self, module, policy_files): | |
| module["steps"].append(step) | ||
| log.debug("Added build step '%s' for module '%s'" % (step, name)) | ||
|
|
||
| def _handle_local_module(self, module): | ||
| def _handle_local_module(self, module, use_default_build_steps=True): | ||
| name = module["name"] | ||
| if not ( | ||
| name.startswith("./") | ||
|
|
@@ -329,10 +328,17 @@ def _handle_local_module(self, module): | |
| ) | ||
| # TODO: Support adding local modules with autorun tag | ||
|
|
||
| self._add_policy_files_build_step(module) | ||
| self._add_bundles_build_step(module, policy_files) | ||
| if use_default_build_steps: | ||
| self._add_policy_files_build_step(module) | ||
| self._add_bundles_build_step(module, policy_files) | ||
|
Comment on lines
+331
to
+333
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This leaves the module object in a "half done" state, I think one of these would be preferable:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't see how that would be the case after and not be the case before. The argument to this function is a
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, are these methods the ones which prompt user about bundle and policy files? If so, we should add a comment about that here.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, those are the methods. I still don't see what you would ideally like to see here, so feel free to suggest.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I found this function a bit strange/unclear (e.g. how it appears in a general |
||
|
|
||
| def _add_without_dependencies(self, modules, use_default_build_steps=True): | ||
| """Note: `use_default_build_steps` is only relevant for local modules.""" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This docstring note could be replaced by an assert.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would say the note is for the users of the function, for them to learn what the function parameter does. This is why it's in the docstring. An assert is only readable inside of the function.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could have both. An assert is much more important IMO, and less likely to go stale. |
||
| if not use_default_build_steps: | ||
| assert len(modules) == 1 and modules[0]["name"].startswith( | ||
| "./" | ||
| ), "`use_default_build_steps` is currently only expected to be explicitly used for adding a single local module" | ||
|
|
||
| def _add_without_dependencies(self, modules): | ||
| assert modules | ||
| assert len(modules) > 0 | ||
| assert modules[0]["name"] | ||
|
|
@@ -350,7 +356,7 @@ def _add_without_dependencies(self, modules): | |
| context="build", name=name, module=module, config=None, local_check=True | ||
| ) | ||
| self["build"].append(module) | ||
| self._handle_local_module(module) | ||
| self._handle_local_module(module, use_default_build_steps) | ||
|
|
||
| assert "added_by" in module | ||
| added_by = module["added_by"] | ||
|
|
@@ -364,7 +370,17 @@ def _add_modules( | |
| to_add: list, | ||
| added_by="cfbs add", | ||
| checksum=None, | ||
| ) -> int: | ||
| explicit_build_steps: Optional[List[str]] = None, | ||
| ): | ||
| """Note: explicit build steps are currently limited to single local modules without dependencies, see the asserts.""" | ||
| if explicit_build_steps is not None: | ||
| assert ( | ||
| len(to_add) == 1 | ||
| ), "explicit_build_steps is only for adding a single module" | ||
| assert is_module_local( | ||
| to_add[0] | ||
| ), "explicit_build_steps is only for adding a local module" | ||
|
|
||
| index = self.index | ||
|
|
||
| modules = [Module(m) for m in to_add] | ||
|
|
@@ -380,10 +396,14 @@ def _add_modules( | |
| # Filter modules which are already added: | ||
| to_add = self._filter_modules_to_add(modules) | ||
| if not to_add: | ||
| return 0 # Everything already added | ||
| # Everything already added | ||
| return | ||
|
|
||
| # Convert names to objects: | ||
| modules_to_add = [index.get_module_object(m, added_by[m.name]) for m in to_add] | ||
| modules_to_add = [ | ||
| index.get_module_object(m, added_by[m.name], explicit_build_steps) | ||
| for m in to_add | ||
| ] | ||
| modules_already_added = self["build"] | ||
|
|
||
| assert not any(m for m in modules_to_add if "name" not in m) | ||
|
|
@@ -393,16 +413,21 @@ def _add_modules( | |
| dependencies = self._find_dependencies(modules_to_add, modules_already_added) | ||
|
|
||
| if dependencies: | ||
| assert ( | ||
| explicit_build_steps is None | ||
| ), "explicit build steps do not apply to dependencies" | ||
| self._add_without_dependencies(dependencies) | ||
|
|
||
| self._add_without_dependencies(modules_to_add) | ||
| return 0 | ||
| self._add_without_dependencies( | ||
| modules_to_add, use_default_build_steps=explicit_build_steps is None | ||
| ) | ||
|
|
||
| def add_command( | ||
| self, | ||
| to_add: List[str], | ||
| added_by="cfbs add", | ||
| checksum=None, | ||
| explicit_build_steps: Optional[List[str]] = None, | ||
| ) -> CFBSCommandGitResult: | ||
| if not to_add: | ||
| raise CFBSUserError("Must specify at least one module to add") | ||
|
|
@@ -417,6 +442,7 @@ def add_command( | |
| to_add=to_add[1:], | ||
| added_by=added_by, | ||
| checksum=checksum, | ||
| explicit_build_steps=explicit_build_steps, | ||
| ) | ||
| else: | ||
| # for this `if` to be valid, module names containing `://` should be illegal | ||
|
|
@@ -425,7 +451,7 @@ def add_command( | |
| "URI scheme not supported. The supported URI schemes are: " | ||
| + ", ".join(SUPPORTED_URI_SCHEMES) | ||
| ) | ||
| self._add_modules(to_add, added_by, checksum) | ||
| self._add_modules(to_add, added_by, checksum, explicit_build_steps) | ||
|
|
||
| added = {m["name"] for m in self["build"]}.difference(before) | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's necessary to switch from
explicit_build_stepstouse_default_build_steps. Just useexplicit_build_stepsall the way down where needed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The actual build step values would be unused then, there would only be a check whether they're
Noneor not. That would read weird. Dunno.