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 2 commits 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
@carlescufi carlescufi requested a review from pdgendt 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?

@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".

src/west/app/config.py Outdated Show resolved Hide resolved
src/west/app/config.py Outdated Show resolved Hide resolved
src/west/app/config.py Outdated Show resolved Hide resolved
src/west/app/config.py Outdated Show resolved Hide resolved
src/west/app/config.py Show resolved Hide resolved
src/west/app/config.py Show resolved Hide resolved
@@ -229,6 +229,9 @@ def test_local_creation_with_topdir():
assert 'pytest' not in cfg(f=GLOBAL)
assert cfg(f=LOCAL, topdir=str(topdir))['pytest']['key'] == 'val'

def test_append_basic():
Copy link
Member Author

Choose a reason for hiding this comment

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

tests are WIP!

src/west/app/config.py Show resolved Hide resolved
src/west/app/config.py Outdated Show resolved Hide resolved
Simplify the error handling of the different action flags (-l, -d and
-D) by using a parser mutually exclusive group.

Signed-off-by: Carles Cufi <[email protected]>
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 <[email protected]>
pdgendt
pdgendt previously approved these changes Nov 26, 2024
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.

TEST APPROVAL, DO NOT MERGE

@pdgendt pdgendt dismissed their stale review November 26, 2024 13:27

It was only a test, PR can be merged with formatting failures, as expected.

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.

@carlescufi please try to follow the formatting suggestions from ruff for NEW or CHANGED code but please avoid git churn in unchanged code, thanks!

src/west/app/config.py Show resolved Hide resolved
@carlescufi
Copy link
Member Author

@carlescufi please try to follow the formatting suggestions from ruff for NEW or CHANGED code but please avoid git churn in unchanged code, thanks!

Honestly I have to say I disagree with this approach, and I already told @pdgendt. I think we either reformat the codebase to match ruff or we don't add the (IMHO misleading) check that is there today in CI.

@kartben
Copy link

kartben commented Nov 29, 2024

@carlescufi please try to follow the formatting suggestions from ruff for NEW or CHANGED code but please avoid git churn in unchanged code, thanks!

Honestly I have to say I disagree with this approach, and I already told @pdgendt. I think we either reformat the codebase to match ruff or we don't add the (IMHO misleading) check that is there today in CI.

@pdgendt my guess is you just forgot to add a ruff-excludes.toml file, did you not? The way it's done today it's preventing folks to contribute until they fix the entire file they're touching, which sounds broken (and unintentional). FWIW this bit me here #713 too.

@pdgendt
Copy link
Collaborator

pdgendt commented Nov 29, 2024

@pdgendt my guess is you just forgot to add a ruff-excludes.toml file, did you not? The way it's done today it's preventing folks to contribute until they fix the entire file they're touching, which sounds broken (and unintentional). FWIW this bit me here #713 too.

Not really, this was the outcome after some offline discussions with @marc-hb, which were also reasonable, but not the same as the approach that was taken for Zephyr itself.

@kartben
Copy link

kartben commented Nov 29, 2024

@pdgendt my guess is you just forgot to add a ruff-excludes.toml file, did you not? The way it's done today it's preventing folks to contribute until they fix the entire file they're touching, which sounds broken (and unintentional). FWIW this bit me here #713 too.

Not really, this was the outcome after some offline discussions with @marc-hb, which were also reasonable, but not the same as the approach that was taken for Zephyr itself.

So you mean you will be just ignoring the CI failures for the time being if they are for lines that were not changed by the contributor? Sorry if I am missing something obvious, but I don't understand why it was done differently than for Zephyr itself (plus, of course, I have no idea about the content and outcome of the offline discussions you're referring to ;))

@pdgendt
Copy link
Collaborator

pdgendt commented Nov 29, 2024

So you mean you will be just ignoring the CI failures for the time being if they are for lines that were not changed by the contributor? Sorry if I am missing something obvious, but I don't understand why it was done differently than for Zephyr itself (plus, of course, I have no idea about the content and outcome of the offline discussions you're referring to ;))

Yeah, I understand the confusion, a GH job can only be green or red, nothing in between. The current idea was; contributors can be asked to update the format, but if only a few lines are touched, it can get merged without it.

There aren't as many contributors to west as there are for Zephyr luckily...

@pdgendt
Copy link
Collaborator

pdgendt commented Nov 29, 2024

A large part of the discussion is online: #766

@marc-hb
Copy link
Collaborator

marc-hb commented Nov 30, 2024

I think we (1) either reformat the codebase to match ruff or we don't add the (IMHO misleading) check that is there today in CI.

(1) means the git history is practically destroyed. Especially problematic considering the main author left.
(2) means no formatting progress.

So you mean you will be just ignoring the CI failures for the time being if they are for lines that were not changed by the contributor?

Yes, formatting issues are obviously not blocking. As mentioned by Pieter, Github has unfortunately no yellow color. BTW this is not just a problem with formatting; every warning in every linter has the same CI problem.

Sorry if I am missing something obvious,

Agree it could/should be more obvious. Pieter could you maybe rename "Format check" to "Format _suggestion"? Basically: try to express "yellow" in words.

but I don't understand why it was done differently than for Zephyr itself (plus, of course, I have no idea about the content and outcome of the offline discussions you're referring to ;))

We're even then because I don't know how it was done for Zephyr itself :-)

In #766 I gave a real-world example where this approach worked well. It was not formatting but pylint and shellcheck; from a CI perspective the process is the same.

my guess is you just forgot to add a ruff-excludes.toml file

An exclude file is interesting, is that how Zephyr solves this problem in general? Not just with formatting but with every linter? Unlike (1) and (2), this allows some form of incremental progress but there are still smaller "big bangs" where the entire git history gets broken on a file-by-file basis. west has unfortunately a small number of giant files.

An exclude file does not solve the problem of changes in the code or the configuration of the formatting tool itself.

@marc-hb
Copy link
Collaborator

marc-hb commented Nov 30, 2024

To be clear: I do not share Pieter's (and others') "enthusiasm" for formatting. Unlike C/C++, Python already enforces indentation = a little bit of formatting and in practice that seems enough to me, I mean I rarely ever scratch my head trying to understand badly formatted Python code. So, ruff only looks like a nice-to-have but nothing more.

On the other hand, I use git blame/rebase/cherry-pick/merge all the time and degrading those commands affects productivity greatly. Even worse when there's a reformatting every year because of some ruff upgrade or configuration change.

@pdgendt
Copy link
Collaborator

pdgendt commented Dec 2, 2024

To be clear: I do not share Pieter's (and others') "enthusiasm" for formatting. Unlike C/C++, Python already enforces indentation = a little bit of formatting and in practice that seems enough to me, I mean I rarely ever scratch my head trying to understand badly formatted Python code. So, ruff only looks like a nice-to-have but nothing more.

I would say the opposite, I "hate" formatting, as in, I don't want to spend time on it. Working on a project where code is in a certain style, I need to "learn" how formatting is done, and carefully curate whatever modifications or additions I do.
I want to focus on the content rather than the looks, and in the best case scenario, tools to do formatting for me.

For python projects I have worked with black in the past, and the ruff formatter is like black, but faster. They have a commitment towards compatibility too, so I have some trust in that the formatting doesn't change drastically.

On the other hand, I use git blame/rebase/cherry-pick/merge all the time and degrading those commands affects productivity greatly. Even worse when there's a reformatting every year because of some ruff upgrade or configuration change.

And I agree, that's why I'm not a fan of blindly applying it to all files, but gradually. Either by exclusion or non-forcing checks. Both have downsides, but I'm happy to adjust.

Currently tooling in and around Zephyr is the wild-wild-west. Maintainers get to call the shots, and for good reason, but this does have the downside of different approaches in each. I introduced ruff in west and Zephyr hoping to get a more uniform tooling codebase. And formatting in an uncompromising way.

@marc-hb
Copy link
Collaborator

marc-hb commented Dec 2, 2024

I would say the opposite, I "hate" formatting, as in, I don't want to spend time on it.
[...]
Currently tooling in and around Zephyr is the wild-wild-west. Maintainers get to call the shots, and for good reason, but this does have the downside of different approaches in each.

I don't know about Zephyr more broadly, but in west there had never been a formatter and there was no "time spent" on formatting either. There could have been some suggestions to try this or that formatting tool to help with "extreme" cases (e.g. very long lines) but if there were, it was so rare that I don't remember any such event. So I don't think formatting has ever caused anyone to "spend any time" in west. I don't remember that for Python in Zephyr either.

As I said, C/C++ offers a lot more editing "creativity" than Python so maybe formatting has been a problem there but for west specifically I'm afraid ruff is a solution in search of a problem.

What would be perfectly non-intrusive is some sort of ruff_format_patch tool that touches only new or changed code like checkpatch.pl does. BTW that's what allows checkpatch not to be worried about being "--subjective", or having contradictions or inconsistencies across checkpatch versions: because it looks only at changed lines. This makes a massive... difference! (pun intended)
From https://www.kernel.org/doc/html/latest/dev-tools/checkpatch.html

Checkpatch is not always right. Your judgement takes precedence over checkpatch messages. If your code looks better with the violations, then its probably best left alone.

@pdgendt
Copy link
Collaborator

pdgendt commented Dec 2, 2024

I don't know about Zephyr more broadly, but in west there had never been a formatter and there was no "time spent" on formatting either. There could have been some suggestions to try this or that formatting tool to help with "extreme" cases (e.g. very long lines) but if there were, it was so rare that I don't remember any such event. So I don't think formatting has ever caused anyone to "spend any time" in west. I don't remember that for Python in Zephyr either.

By "time spent", I meant what I do while developing, not commenting on contributions. I have developed in many different languages, mostly out of curiosity and learning new things. And languages like go, rust, zig, ... (yes all the new kids) come with formatting guidelines and tooling out of the box.
There is no nit-picking, or preference of appearance as the language has set clear defaults.

Python has the PEP8 guideline which allows much more than what black or ruff currently output, but we currently don't comply either.

As I said, C/C++ offers a lot more editing "creativity" than Python so maybe formatting has been a problem there but for west specifically I'm afraid ruff is a solution in search of a problem.

That was my earlier point on trying have uniform code across projects under the Zephyr umbrella, and without tooling to enforce it, it's always a never-ending discussion.

What would be perfectly non-intrusive is some sort of ruff_format_patch tool that touches only new or changed code like checkpatch.pl does. BTW that's what allows checkpatch not to be worried about being "subjective", or having contradictions or inconsistencies across checkpatch versions: because it looks only at changed lines. It makes a massive... difference! (pun intended)

kernel.org/doc/html/latest/dev-tools/checkpatch.html

Checkpatch is not always right. Your judgement takes precedence over checkpatch messages. If your code looks better with the violations, then its probably best left alone.

You can turn off formatting just as easy for code blocks, but this shouldn't be the default IMO.

@marc-hb
Copy link
Collaborator

marc-hb commented Dec 2, 2024

And languages like go, rust, zig, ... (yes all the new kids) come with formatting guidelines and tooling out of the box.

I like that too - but as you know that's not the reality for Python. Except for one very important thing: indentation.

and without tooling to enforce it, it's always a never-ending discussion.

I agree it becomes a never-ending discussion without tooling BUT only if maintainers decide to engage in that discussion in the first place. That has never been the case with west until now. I've been around for a few years and I didn't see any formatting discussion with Python in Zephyr either. Indentation likely helped.

@marc-hb
Copy link
Collaborator

marc-hb commented Dec 2, 2024

... engage in that discussion in the first place. That has never been the case with west until now. [...] Indentation likely helped.

I just remembered that west had some codestyle checks in CI since forever. That likely helped with readability and reduced formatting needs even more. Formatting is just a small, less important part of code style and readability.

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.

4 participants