Skip to content

Conversation

@jakub-nt
Copy link
Contributor

@jakub-nt jakub-nt commented Aug 4, 2025

No description provided.

This value was unused and the signature now matches `_add_using_url`

Signed-off-by: jakub-nt <175944085+jakub-nt@users.noreply.github.com>
Signed-off-by: jakub-nt <175944085+jakub-nt@users.noreply.github.com>
It had a subnormal name.

Signed-off-by: jakub-nt <175944085+jakub-nt@users.noreply.github.com>
This makes it clear that the functions take a module name, not an entire module object

Signed-off-by: jakub-nt <175944085+jakub-nt@users.noreply.github.com>
Signed-off-by: jakub-nt <175944085+jakub-nt@users.noreply.github.com>
@jakub-nt jakub-nt force-pushed the explicit-build-steps branch from f13c73a to c8f0083 Compare August 4, 2025 19:42
@jakub-nt jakub-nt requested review from larsewi and olehermanse August 4, 2025 19:47
@larsewi
Copy link
Contributor

larsewi commented Aug 5, 2025

Please explain how this should work.

Do you need it for cfbs convert? If so, please explain why.

Is there a ticket? If so could you link it to the PR and in the last commit?

@jakub-nt
Copy link
Contributor Author

jakub-nt commented Aug 5, 2025

It should work by using a provided steps list as the added module's "steps" field in cfbs.json.

Yes, it's for cfbs convert, for adding the local module. The usual build steps are not what is desired.

Copy link
Member

@olehermanse olehermanse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just some smaller things to fix.

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):
Copy link
Member

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_steps to use_default_build_steps. Just use explicit_build_steps all the way down where needed.

Copy link
Contributor Author

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 None or not. That would read weird. Dunno.

Comment on lines +331 to +333
if use_default_build_steps:
self._add_policy_files_build_step(module)
self._add_bundles_build_step(module, policy_files)
Copy link
Member

Choose a reason for hiding this comment

The 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:

  1. Just add the defaults, and you can overwrite module["steps"] in the calling code.
  2. Or, send explicit_build_steps all the way down to this function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This leaves the module object in a "half done" state

I don't see how that would be the case after and not be the case before. The argument to this function is a Module object, which at the time of entering this function will already have some build steps from when it was constructed (and that construction will now use explicit_build_steps, too, so all the required steps should be there already).

Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like _handle_local_module() is not really needed for our case? Maybe a better approach is to clarify it a bit (give it a better name / docstring), and avoid calling it in this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 _add_without_dependencies function) at first. The current code is setting build steps in a few separate places, maybe there could be improvements, I avoided changing the structure for now, since optional params in existing places could do the job.


def _add_without_dependencies(self, modules):
def _add_without_dependencies(self, modules, use_default_build_steps=True):
"""Note: `use_default_build_steps` is only relevant for local modules."""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This docstring note could be replaced by an assert.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The 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.

checksum=None,
explicit_build_steps: Optional[List[str]] = None,
):
"""Note: explicit build steps are applied only to directly added modules, not their dependencies."""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here;

if explicit_build_steps is not None:
    assert len(to_add) == 1, "explicit_build_steps is only for adding a single module"
    assert is_local(to_add[0]), "explicit_build_steps is only for adding a local module"

Copy link
Contributor Author

@jakub-nt jakub-nt Aug 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the same. Are you saying the ability to provide explicit build steps should be limited to adding single local modules only? It seems like it could be useful for adding multiple local modules at once, or for providing custom build steps for modules added from an index or URL.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's not exactly the same, but I would add restrictions to try to catch programmer mistakes, rather than notes that look like they could be missed or go stale in the future.

In this case, I think we could place very strict restritctions, yes, only one module, no dependencies, has to be local.

AFAIK that's what we need (for now). The pre-existing add code is a bit messy (not your fault), so it would be nice to have asserts which protect against the unexpected.

If in the future we want to expand it to multiple modules or non-local modules, that is easily doable - remove one assert and ensure it works correctly.

… scenarios

Signed-off-by: jakub-nt <175944085+jakub-nt@users.noreply.github.com>
@jakub-nt jakub-nt requested a review from olehermanse August 5, 2025 16:42
@olehermanse olehermanse merged commit 999aa6e into cfengine:master Aug 6, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants