From: Zbigniew Jędrzejewski-Szmek Date: Mon, 5 Jun 2023 13:47:00 +0000 (+0200) Subject: ukify: simplify creation of parser X-Git-Tag: v254-rc1~274^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1df35a4638f9869b823b71ec27bcff1e510ef26c;p=thirdparty%2Fsystemd.git ukify: simplify creation of parser 00e5933f57c6e336ebed18601299acc6855bb3c2 made all the positional arguments optional, so let's take advantage of this to simplify variuos callers. --- diff --git a/src/kernel-install/60-ukify.install.in b/src/kernel-install/60-ukify.install.in index 7c29f7e8af0..0927bd7a2e8 100755 --- a/src/kernel-install/60-ukify.install.in +++ b/src/kernel-install/60-ukify.install.in @@ -183,11 +183,10 @@ def call_ukify(opts): # The solution with runpy gives a dictionary, which isn't great, but will do. ukify = runpy.run_path(UKIFY, run_name='ukify') - # Create "empty" namespace. We want to override just a few settings, - # so it doesn't make sense to duplicate all the fields. We use a hack - # to pre-populate the namespace like argparse would, all defaults. - # We need to specify the two mandatory arguments to not get an error. - opts2 = ukify['create_parser']().parse_args(('A','B')) + # Create "empty" namespace. We want to override just a few settings, so it + # doesn't make sense to configure everything. We pretend to parse an empty + # argument set to prepopulate the namespace with the defaults. + opts2 = ukify['create_parser']().parse_args(()) opts2.config = config_file_location() opts2.uname = opts.kernel_version diff --git a/src/ukify/test/test_ukify.py b/src/ukify/test/test_ukify.py index 692b7a384bb..ab89e11b73d 100755 --- a/src/ukify/test/test_ukify.py +++ b/src/ukify/test/test_ukify.py @@ -50,9 +50,9 @@ def test_round_up(): assert ukify.round_up(4097) == 8192 def test_namespace_creation(): - ns = ukify.create_parser().parse_args(('A','B')) - assert ns.linux == pathlib.Path('A') - assert ns.initrd == [pathlib.Path('B')] + ns = ukify.create_parser().parse_args(()) + assert ns.linux is None + assert ns.initrd == [] def test_config_example(): ex = ukify.config_example() @@ -87,7 +87,7 @@ def test_apply_config(tmp_path): Phases = {':'.join(ukify.KNOWN_PHASES)} ''')) - ns = ukify.create_parser().parse_args(('A','B')) + ns = ukify.create_parser().parse_args(()) ns.linux = None ns.initrd = [] ukify.apply_config(ns, config)