| Message ID | 20250912204559.10360-1-reatmon@ti.com |
|---|---|
| State | New |
| Headers | show |
| Series | [1/3] bitbake-setup: Tweak user inputs | expand |
On Fri Sep 12, 2025 at 10:45 PM CEST, Ryan Eatmon via lists.openembedded.org wrote: > Create a common function to get the user input when choosing an item > from a list. Add support for not returning from the function until the > user has selected a number. > > When choosing items from the option list, if there is only one item, > then auto select it. This is similar to code when picking the > configuration. > > Signed-off-by: Ryan Eatmon <reatmon@ti.com> > --- Hi Ryan, Thanks for your patches. I suspect one of them is responsible of this error we got on the autobuilder: FAIL: test_setup (bb.tests.setup.BitbakeSetupTest.test_setup) ---------------------------------------------------------------------- Traceback (most recent call last): File "/srv/pokybuild/yocto-worker/oe-selftest-armhost/build/bitbake/lib/bb/tests/setup.py", line 222, in test_setup self.assertIn("test-config-1", json_configs) AssertionError: 'test-config-1' not found in {'test-config-1.conf': {'description': 'Test configuration'}, 'test-config-2.conf': {'description': 'Test configuration'}} https://autobuilder.yoctoproject.org/valkyrie/#/builders/48/builds/2252 https://autobuilder.yoctoproject.org/valkyrie/#/builders/35/builds/2324 https://autobuilder.yoctoproject.org/valkyrie/#/builders/23/builds/2469 Can you have a look at this, please? Thanks, Mathieu
On 9/14/2025 4:37 AM, Mathieu Dubois-Briand wrote: > On Fri Sep 12, 2025 at 10:45 PM CEST, Ryan Eatmon via lists.openembedded.org wrote: >> Create a common function to get the user input when choosing an item >> from a list. Add support for not returning from the function until the >> user has selected a number. >> >> When choosing items from the option list, if there is only one item, >> then auto select it. This is similar to code when picking the >> configuration. >> >> Signed-off-by: Ryan Eatmon <reatmon@ti.com> >> --- > > Hi Ryan, > > Thanks for your patches. > > I suspect one of them is responsible of this error we got on the > autobuilder: Likely it is patch 2/3 bitbake-setup: Fix extracting config name. It looks like the test is adding configs named: test-config-1.conf.json test-config-2.conf.json And with my patch instead of the config name being the part before the first '.', now it strips just the extension '.json'. I guess my change needs a little discussion on how we want this part of bitbake-setup to operate. What do we consider the name of a config when extracting it from the file name. I can update the tests to match my change and submit a v2 if we want to go with my change. Thoughts? > FAIL: test_setup (bb.tests.setup.BitbakeSetupTest.test_setup) > ---------------------------------------------------------------------- > Traceback (most recent call last): > File "/srv/pokybuild/yocto-worker/oe-selftest-armhost/build/bitbake/lib/bb/tests/setup.py", line 222, in test_setup > self.assertIn("test-config-1", json_configs) > AssertionError: 'test-config-1' not found in {'test-config-1.conf': {'description': 'Test configuration'}, 'test-config-2.conf': {'description': 'Test configuration'}} > > https://autobuilder.yoctoproject.org/valkyrie/#/builders/48/builds/2252 > https://autobuilder.yoctoproject.org/valkyrie/#/builders/35/builds/2324 > https://autobuilder.yoctoproject.org/valkyrie/#/builders/23/builds/2469 > > Can you have a look at this, please? > > Thanks, > Mathieu >
On Fri, 12 Sept 2025 at 22:46, Ryan Eatmon via lists.openembedded.org <reatmon=ti.com@lists.openembedded.org> wrote: > +def get_user_input(prompt): > + choice_s = '' > + while choice_s.isdigit() == False: > + print("\n{}:".format(prompt)) > + choice_s = input() > + choice_n = int(choice_s) > + return choice_n Thanks, I already have an implementation that also checks that the input is in valid range, and tries to guide the user to input something sensible (not yet pushed): def int_input(allowed_values): n = None while not n: try: n = int(input()) except ValueError: print('Not a valid number, please try again:') continue if n not in allowed_values: print('Number {} not one of {}, please try again:'.format(n, allowed_values)) n = None return n > + > + if len(options_enumerated) == 1: > + only_config = options_enumerated[0] > + print("\nSelecting the only available option {}".format(only_config)) > + choices[k] = options_enumerated[only_config[0]][1] > + continue This should be fixed in the configuration: move the only option to 'oe-fragments'. Alex
diff --git a/bin/bitbake-setup b/bin/bitbake-setup index dc2de30a8..36103f1e8 100755 --- a/bin/bitbake-setup +++ b/bin/bitbake-setup @@ -252,6 +252,14 @@ def flatten_bitbake_configs(configs): flattened_configs.append(merge_configs(c, sub_c)) return flattened_configs +def get_user_input(prompt): + choice_s = '' + while choice_s.isdigit() == False: + print("\n{}:".format(prompt)) + choice_s = input() + choice_n = int(choice_s) + return choice_n + def choose_bitbake_config(configs, parameters, non_interactive): flattened_configs = flatten_bitbake_configs(configs) configs_dict = {i["name"]:i for i in flattened_configs} @@ -274,8 +282,7 @@ def choose_bitbake_config(configs, parameters, non_interactive): print("\nAvailable bitbake configurations:") for n, config_data in enumerated_configs: print("{}. {}\t{}".format(n, config_data["name"], config_data["description"])) - print("\nPlease select one of the above bitbake configurations by its number:") - config_n = int(input()) + config_n = get_user_input('Please select one of the above bitbake configurations by its number') return flattened_configs[config_n] def choose_config(configs, non_interactive): @@ -298,8 +305,7 @@ def choose_config(configs, non_interactive): print("{}. {}\t{} (supported until {})".format(n, config_name, config_desc, expiry_date)) else: print("{}. {}\t{}".format(n, config_name, config_desc)) - print("\nPlease select one of the above configurations by its number:") - config_n = int(input()) + config_n = get_user_input('Please select one of the above configurations by its number') return config_list[config_n][1] def choose_fragments(possibilities, parameters, non_interactive): @@ -317,10 +323,16 @@ def choose_fragments(possibilities, parameters, non_interactive): print("\n" + v["description"] + ":") options_enumerated = list(enumerate(v["options"])) + + if len(options_enumerated) == 1: + only_config = options_enumerated[0] + print("\nSelecting the only available option {}".format(only_config)) + choices[k] = options_enumerated[only_config[0]][1] + continue + for n,o in options_enumerated: print("{}. {}".format(n, o)) - print("\nPlease select one of the above options by its number:") - option_n = int(input()) + option_n = get_user_input('Please select one of the above options by its number') choices[k] = options_enumerated[option_n][1] return choices
Create a common function to get the user input when choosing an item from a list. Add support for not returning from the function until the user has selected a number. When choosing items from the option list, if there is only one item, then auto select it. This is similar to code when picking the configuration. Signed-off-by: Ryan Eatmon <reatmon@ti.com> --- bin/bitbake-setup | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-)