Skip to content

Add support for composing strings - #2202

Open
aleixpol wants to merge 2 commits into
apache:masterfrom
aleixpol:aleixpol/support-composing-strings
Open

aleixpol wants to merge 2 commits into
apache:masterfrom
aleixpol:aleixpol/support-composing-strings

Conversation

@aleixpol

Copy link
Copy Markdown
Contributor

When composing onto a string allow prepending and appending onto them.

It uses the same operators we use for lists (<), (=) and (>).

Comment thread src/buildstream/node.pyx Resolved
@aleixpol
aleixpol force-pushed the aleixpol/support-composing-strings branch from 95684f5 to 7f81363 Compare October 16, 2026 16:20
@nathanwilliams-ct

Copy link
Copy Markdown
Contributor

@aleixpol
aleixpol force-pushed the aleixpol/support-composing-strings branch from 7f81363 to fdff60d Compare October 22, 2026 01:50
@aleixpol

aleixpol commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Need to update the documentation: https://github.com/apache/buildstream/blob/master/doc/source/format_intro.rst#-list-prepend

I gave it a go, please see what it looks like. Don't be afraid of saying it's a bit shit, it's always harder to document something more abstract. Ideas welcome.

Comment thread doc/source/format_intro.rst Resolved
Comment thread doc/source/format_intro.rst Resolved
Comment thread doc/source/format_intro.rst Resolved
Comment thread doc/source/format_intro.rst Resolved
@aleixpol
aleixpol force-pushed the aleixpol/support-composing-strings branch 2 times, most recently from 83661df to b23345e Compare October 23, 2026 08:34
@aleixpol

Copy link
Copy Markdown
Contributor Author

I think all the concerns have been addressed now.

@nathanwilliams-ct nathanwilliams-ct left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@aleixpol
aleixpol force-pushed the aleixpol/support-composing-strings branch from b23345e to dc75e2a Compare October 27, 2026 10:52
When composing onto a string allow prepending and appending onto them.

It uses the same operators we use for lists (<), (=) and (>).
@aleixpol
aleixpol force-pushed the aleixpol/support-composing-strings branch from dc75e2a to 40bc464 Compare October 27, 2026 12:40
@aleixpol
aleixpol force-pushed the aleixpol/support-composing-strings branch from 40bc464 to 9159523 Compare October 29, 2026 16:31
Comment thread src/buildstream/node.pyx
Comment on lines +1035 to +1036
target.value.clear()
target.value.extend(clobber.value)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This doesn't look right for strings. I'd expect a simple assignment to work fine, though.

Suggested change
target.value.clear()
target.value.extend(clobber.value)
target.value = clobber.value

Comment thread src/buildstream/node.pyx
if type(target_value) is SequenceNode:
# Composite list composes into a list
self._compose_on_list(target_value)
elif isinstance((<ScalarNode> target_value).value, str):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Doesn't this require a type check before the cast to ScalarNode?

Comment thread src/buildstream/node.pyx
self._compose_on_string(target_value)
elif target_value._is_composite_list():
# Composite list merges into composite list
self._compose_on_composite_dict(target_value)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

_compose_on_composite_dict only knows about list, not string composition. Couldn't this be hit via multiple includes? It may be acceptable to start with this as known limitation, if there is a reasonable error.

Comment thread src/buildstream/node.pyx
# Compose the current node on the given string.
#
# Args:
# target (.SequenceNode): sequence on which to compose the current composite dict

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: Not a SequenceNode

.. _format_directives_list_append:

(>) List Append
For strings:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is an example for prepend, so it should be above the _format_directives_list_append marker (and I think the _format_directives_string_append marker is unused.

Comment thread src/buildstream/node.pyx
if prefix is not None:
target.value = prefix.value + target.value
if suffix is not None:
target.value += suffix.value

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As ScalarNode strips whitespace from the start and end of strings (even if they're quoted), it won't be possible to append e.g. " -foo" to a flags variable, as far as I can tell. Not sure what the best solution is for this, especially considering backwards compatibility, but this might block real use cases.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants