Skip to content
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

app: config: Add support for appending to the config string #768

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

carlescufi
Copy link
Member

@carlescufi carlescufi commented Nov 14, 2024

In some cases, and specifically in the manifest.group-filter and manifest.project-filter options, it is sometimes useful to be able to append to a value instead of replacing it completely.

For example, assuming one wants to add to an existing group filter, without this patch the user needs to do:

(assuming the group filter is currently +unstable,-optional, and the
user wants to add +extras).
$ west config manifest.group-filter
$ west config manifest.group-filter +unstable,-optional,+extras

With this patch instead:

$ west config -a manifest.group-filter ,+extras

src/west/app/config.py Outdated Show resolved Hide resolved
@pdgendt
Copy link
Collaborator

pdgendt commented Nov 14, 2024

I do have a concern about the appending if the value doesn't exist yet.

Something like:

$ west config -a manifest.group-filter ,+extras

Could result in an error because of the leading comma.

@carlescufi
Copy link
Member Author

I do have a concern about the appending if the value doesn't exist yet.

I also thought about that, but did not want to overcomplicate the code. But yes, let me do that as well.

src/west/app/config.py Outdated Show resolved Hide resolved
src/west/app/config.py Outdated Show resolved Hide resolved
@carlescufi carlescufi force-pushed the config-append branch 3 times, most recently from 37e03bc to 69ac4f1 Compare November 14, 2024 12:17
src/west/app/config.py Outdated Show resolved Hide resolved
src/west/app/config.py Outdated Show resolved Hide resolved
@carlescufi carlescufi force-pushed the config-append branch 3 times, most recently from c8d62f6 to 3cf5a27 Compare November 14, 2024 14:21
Copy link
Collaborator

@pdgendt pdgendt left a comment

Choose a reason for hiding this comment

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

LGTM, can you add tests?

In some cases, and specifically in the manifest.group-filter and
manifest.project-filter options, it is sometimes useful to be able to
append to a value instead of replacing it completely.

For example, assuming one wants to add to an existing group filter,
without this patch the user needs to do:

(assuming the group filter is currently +unstable,-optional, and the
user wants to add +extras).
> west config manifest.group-filter
> west config manifest.group-filter +unstable,-optional,+extras

With this patch instead:

> west config -a manifest.group-filter ,+extras

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
@carlescufi
Copy link
Member Author

LGTM, can you add tests?

yep, on it!

Copy link
Collaborator

@marc-hb marc-hb left a comment

Choose a reason for hiding this comment

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

LGTM, can you add tests?

yep, on it!

I think these won't involve shlex.split() because Zephyr will not be involved but please use some whitespace anyway in test data for more "stress".

To append to a value for <name>, type:
west config -a <name> <value>
A value must exist in the selected configuration file in order to be able
to append to it.
Copy link
Collaborator

@marc-hb marc-hb Nov 14, 2024

Choose a reason for hiding this comment

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

Can you please add a short example? One with whitespace, quoting and shlex.split() to warn the user about the usual whitespace and quoting perils. Something like west config -a build.cmake-args -- "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_VERBOSE_MAKEFILE=ON" (UNTESTED)

See https://docs.zephyrproject.org/latest/develop/west/build-flash-debug.html#permanent-cmake-arguments and 0186eade513a

elif args.delete and args.delete_all:
self.parser.error('-d cannot be combined with -D')
elif args.value is None and args.append:
self.parser.error('-a requires a value')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
self.parser.error('-a requires a value')
self.parser.error('-a requires both name and value')

@@ -179,6 +190,16 @@ def read(self, args):
self.dbg(f'{args.name} is unset')
raise CommandError(returncode=1)

def append(self, args):
self.check_config(args.name)
what = args.configfile or LOCAL
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
what = args.configfile or LOCAL
where = args.configfile or LOCAL

To append to a value for <name>, type:
west config -a <name> <value>
A value must exist in the selected configuration file in order to be able
to append to it.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
to append to it.
to append to it. The existing value can be empty.

@@ -64,7 +69,7 @@

CONFIG_EPILOG = '''\
If the configuration file to use is not set, reads use all three in
precedence order, and writes use the local file.'''
precedence order, and writes (including appends) use the local file.'''
Copy link
Collaborator

@marc-hb marc-hb Nov 14, 2024

Choose a reason for hiding this comment

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

I'm afraid you just discovered a documentation bug (or worse). The west config command works just fine outside of any workspace - when there is no "local file"! What happens then?

group.add_argument('-D', '--delete-all', action='store_true',
help="delete an option everywhere it's set")
group.add_argument('-a', '--append', action='store_true',
help='append to an existing value')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice simplification thanks to add_mutually_exclusive_group() but I don't find it trivial enough to be combined with the addition of a feature that is not really trivial either. Please use (at least) 2 separate commits.

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