utils/generate-cyclonedx: avoid f-string usage
PATCH v2 1/3 utils/generate-cyclonedx: avoid f-string usage
The argparse library documentation [1] suggest the usage of 'ArgumentDefaultsHelpFormatter' in the ArgumentParser declaration to show the default value of every arguments.
Use this to avoid declaring this value ourself.
[1] https://docs.python.org/3/library/argparse.html#argparse.ArgumentDefaultsHelpFormatter
--- utils/generate-cyclonedx | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
utils/generate-cyclonedx +9 -8
@@ -529,23 +529,24 @@ def br2_root_deps(show_info_dict, virtual=False) -> list: def main(): parser = argparse.ArgumentParser( - description='''Create a CycloneDX SBoM for the Buildroot configuration. - Example usage: make show-info | utils/generate-cyclonedx > sbom.json - ''' - ) + description='''Create a CycloneDX SBoM for the Buildroot configuration. + Example usage: make show-info | utils/generate-cyclonedx > sbom.json + ''', + formatter_class=argparse.ArgumentDefaultsHelpFormatter + ) parser.add_argument("-i", "--in-file", nargs="?", type=argparse.FileType("r"), default=(None if sys.stdin.isatty() else sys.stdin)) parser.add_argument("-o", "--out-file", nargs="?", type=argparse.FileType("w"), default=sys.stdout) - parser.add_argument("--virtual", default=False, action='store_true', + parser.add_argument("--virtual", action='store_true', help="This option includes virtual packages to the CycloneDX output") parser.add_argument("--project-name", type=str, default="buildroot", - help="Specify the project name to use in the SBOM metadata (default:'buildroot')") + help="Specify the project name to use in the SBOM metadata") parser.add_argument("--project-version", type=str, default=f"{BR2_VERSION_FULL}", - help="Specify the project version to use in the SBOM metadata (default: builroot version)") + help="Specify the project version to use in the SBOM metadata") parser.add_argument("--cdx-version", type=str, default=DEFAULT_CYCLONEDX_VERSION, choices=["1.6", "1.6.1", "1.6.2", "1.7", "1.7.1"], - help=f"Set CycloneDX version (default: {DEFAULT_CYCLONEDX_VERSION})") + help="Set CycloneDX version") args = parser.parse_args()
Signature · 6 lines
2.55.0 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
PATCH v2 2/3 utils/generate-cyclonedx: improve help text
The argparse has a set of arguments you can pass to the ArgumentParser object to improve the looks of the help message.
The example usage used to be defined in the "description" but a "usage" field exists [1].
Also link to the documentation in the epilog [2].
[1] https://docs.python.org/3/library/argparse.html#usage
[2] https://docs.python.org/3/library/argparse.html#epilog
--- utils/generate-cyclonedx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
utils/generate-cyclonedx +3 -3
@@ -529,9 +529,9 @@ def br2_root_deps(show_info_dict, virtual=False) -> list: def main(): parser = argparse.ArgumentParser( - description='''Create a CycloneDX SBoM for the Buildroot configuration. - Example usage: make show-info | utils/generate-cyclonedx > sbom.json - ''', + description="Create a CycloneDX SBoM for the Buildroot configuration.", + usage="make show-info | utils/%(prog)s > sbom.json", + epilog="For more information see https://buildroot.org/downloads/manual/manual.html#_generating_cyclonedx_sbom", formatter_class=argparse.ArgumentDefaultsHelpFormatter ) parser.add_argument("-i", "--in-file", nargs="?", type=argparse.FileType("r"),
Signature · 6 lines
2.55.0 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Raphaël Mélotte via buildroot
AppliedRe: [Buildroot] [PATCH v2 2/3] utils/generate-cyclonedx: improve help text
In reply of:
Quoted 6 lines
The argparse has a set of arguments you can pass to the ArgumentParser object to improve the looks of the help message.
The example usage used to be defined in the "description" but a "usage" field exists [1].
Quoted 6 lines
Also link to the documentation in the epilog [2].
[1] https://docs.python.org/3/library/argparse.html#usage
[2] https://docs.python.org/3/library/argparse.html#epilogSigned-off-by Thomas Perale <[email protected]>
Applied to 2025.02.x, 2026.08.x. Thanks
Quoted 11 lines
--- utils/generate-cyclonedx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)utils/generate-cyclonedx +0
-0@@ -529,9 +529,9 @@ def br2_root_deps(show_info_dict, virtual=False) -> list: def main():
utils/generate-cyclonedx def br2_root_deps(show_info_dict, virtual=False) -> list: · line 537
Quoted 10 lines
utils/generate-cyclonedx +3
-3parser = argparse.ArgumentParser( - description='''Create a CycloneDX SBoM for the Buildroot configuration. - Example usage: make show-info | utils/generate-cyclonedx > sbom.json - ''', + description="Create a CycloneDX SBoM for the Buildroot configuration.", + usage="make show-info | utils/%(prog)s > sbom.json", + epilog="For more information see https://buildroot.org/downloads/manual/manual.html#_generating_cyclonedx_sbom", formatter_class=argparse.ArgumentDefaultsHelpFormatter ) parser.add_argument("-i", "--in-file", nargs="?", type=argparse.FileType("r"),
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
PATCH v2 3/3 utils/generate-cyclonedx: add comment to explain spec_version
In reply to Thomas Perale via buildrootThe commit [1] introduced the cdx_spec_version variable. The reason for that variable is not immediately clear. Only the license schema can use patch revision while the spec version should always exclude the patch revision.
This commit adds a comment clarifying this.
[1] 504bb61bc6 utils/generate-cyclonedx: support custom schema version
--- utils/generate-cyclonedx | 4 ++++ 1 file changed, 4 insertions(+)
utils/generate-cyclonedx +4 -0
@@ -562,6 +562,10 @@ def main(): filtered_show_info_dict = {k: v for k, v in show_info_dict.items() if ("rootfs" not in v["type"]) and (args.virtual or v["virtual"] is False)} + # Only keep the first two numbers of the 'cdx-version' argument. + # While the patch revision (e.g. 1.6.2) can be used for the license list, + # only the first two numbers (e.g. 1.6) are valid in the schema and the + # 'specVersion'. cdx_spec_version = ".".join(args.cdx_version.split(".")[:2]) cyclonedx_dict = { "bomFormat": "CycloneDX",
Signature · 6 lines
2.55.0 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Raphaël Mélotte via buildroot
AppliedRe: [Buildroot] [PATCH v2 3/3] utils/generate-cyclonedx: add comment to explain spec_version
In reply of:
Quoted 11 lines
The commit [1] introduced the
cdx_spec_versionvariable. The reason for that variable is not immediately clear. Only the license schema can use patch revision while the spec version should always exclude the patch revision.This commit adds a comment clarifying this.
[1]
504bb61bc6utils/generate-cyclonedx: support custom schema versionSuggested-by Quentin Schulz <[email protected]>Signed-off-by Thomas Perale <[email protected]>
Applied to 2025.02.x, 2026.08.x. Thanks
Quoted 9 lines
--- utils/generate-cyclonedx | 4 ++++ 1 file changed, 4 insertions(+)utils/generate-cyclonedx +0
-0
utils/generate-cyclonedx def main(): · line 571
Quoted 10 lines
utils/generate-cyclonedx +4
-0@@ -562,6 +562,10 @@ def main(): filtered_show_info_dict = {k: v for k, v in show_info_dict.items() if ("rootfs" not in v["type"]) and (args.virtual or v["virtual"] is False)} + # Only keep the first two numbers of the 'cdx-version' argument. + # While the patch revision (e.g. 1.6.2) can be used for the license list, + # only the first two numbers (e.g. 1.6) are valid in the schema and the + # 'specVersion'. cdx_spec_version = ".".join(args.cdx_version.split(".")[:2]) cyclonedx_dict = { "bomFormat": "CycloneDX",
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
Quoted 11 lines · Thomas Perale via buildroot
The argparse library documentation [1] suggest the usage of 'ArgumentDefaultsHelpFormatter' in the ArgumentParser declaration to show the default value of every arguments.
Use this to avoid declaring this value ourself.
[1] https://docs.python.org/3/library/argparse.html#argparse.ArgumentDefaultsHelpFormatter
Suggested-by Quentin Schulz <[email protected]>Suggested-by Titouan Christophe <[email protected]>Signed-off-by Thomas Perale <[email protected]>
Applied to master, thanks!
Regards,
Arnout
Quoted 43 lines
--- utils/generate-cyclonedx | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)utils/generate-cyclonedx +9
-8@@ -529,23 +529,24 @@ def br2_root_deps(show_info_dict, virtual=False) -> list: def main(): parser = argparse.ArgumentParser( - description='''Create a CycloneDX SBoM for the Buildroot configuration. - Example usage: make show-info | utils/generate-cyclonedx > sbom.json - ''' - ) + description='''Create a CycloneDX SBoM for the Buildroot configuration. + Example usage: make show-info | utils/generate-cyclonedx > sbom.json + ''', + formatter_class=argparse.ArgumentDefaultsHelpFormatter + ) parser.add_argument("-i", "--in-file", nargs="?", type=argparse.FileType("r"), default=(None if sys.stdin.isatty() else sys.stdin)) parser.add_argument("-o", "--out-file", nargs="?", type=argparse.FileType("w"), default=sys.stdout) - parser.add_argument("--virtual", default=False, action='store_true', + parser.add_argument("--virtual", action='store_true', help="This option includes virtual packages to the CycloneDX output") parser.add_argument("--project-name", type=str, default="buildroot", - help="Specify the project name to use in the SBOM metadata (default:'buildroot')") + help="Specify the project name to use in the SBOM metadata") parser.add_argument("--project-version", type=str, default=f"{BR2_VERSION_FULL}", - help="Specify the project version to use in the SBOM metadata (default: builroot version)") + help="Specify the project version to use in the SBOM metadata") parser.add_argument("--cdx-version", type=str, default=DEFAULT_CYCLONEDX_VERSION, choices=["1.6", "1.6.1", "1.6.2", "1.7", "1.7.1"], - help=f"Set CycloneDX version (default: {DEFAULT_CYCLONEDX_VERSION})") + help="Set CycloneDX version") args = parser.parse_args()Signature · 1 line
2.55.0
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
Raphaël Mélotte via buildroot
AppliedIn reply of:
Quoted 11 lines
The argparse library documentation [1] suggest the usage of 'ArgumentDefaultsHelpFormatter' in the ArgumentParser declaration to show the default value of every arguments.
Use this to avoid declaring this value ourself.
[1] https://docs.python.org/3/library/argparse.html#argparse.ArgumentDefaultsHelpFormatter
Suggested-by Quentin Schulz <[email protected]>Suggested-by Titouan Christophe <[email protected]>Signed-off-by Thomas Perale <[email protected]>
Applied to 2025.02.x, 2026.08.x. Thanks
Quoted 31 lines
--- utils/generate-cyclonedx | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)utils/generate-cyclonedx +7
-6@@ -529,23 +529,24 @@ def br2_root_deps(show_info_dict, virtual=False) -> list: def main(): parser = argparse.ArgumentParser( - description='''Create a CycloneDX SBoM for the Buildroot configuration. - Example usage: make show-info | utils/generate-cyclonedx > sbom.json - ''' - ) + description='''Create a CycloneDX SBoM for the Buildroot configuration. + Example usage: make show-info | utils/generate-cyclonedx > sbom.json + ''', + formatter_class=argparse.ArgumentDefaultsHelpFormatter + ) parser.add_argument("-i", "--in-file", nargs="?", type=argparse.FileType("r"), default=(None if sys.stdin.isatty() else sys.stdin)) parser.add_argument("-o", "--out-file", nargs="?", type=argparse.FileType("w"), default=sys.stdout) - parser.add_argument("--virtual", default=False, action='store_true', + parser.add_argument("--virtual", action='store_true', help="This option includes virtual packages to the CycloneDX output") parser.add_argument("--project-name", type=str, default="buildroot", - help="Specify the project name to use in the SBOM metadata (default:'buildroot')") + help="Specify the project name to use in the SBOM metadata")
utils/generate-cyclonedx def br2_root_deps(show_info_dict, virtual=False) -> list: · line 552
Quoted 10 lines
utils/generate-cyclonedx +2
-2parser.add_argument("--project-version", type=str, default=f"{BR2_VERSION_FULL}", - help="Specify the project version to use in the SBOM metadata (default: builroot version)") + help="Specify the project version to use in the SBOM metadata") parser.add_argument("--cdx-version", type=str, default=DEFAULT_CYCLONEDX_VERSION, choices=["1.6", "1.6.1", "1.6.2", "1.7", "1.7.1"], - help=f"Set CycloneDX version (default: {DEFAULT_CYCLONEDX_VERSION})") + help="Set CycloneDX version") args = parser.parse_args()
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot