create-spdx.bbclass: Search all license directories for licenses
PATCH 1/1 create-spdx.bbclass: Search all license directories for licenses
Before, even if the code was seemingly written to search through all licenses in ${COMMON_LICENSE_DIR} and ${LICENSE_PATH}, it would actually bail out after only searching ${COMMON_LICENSE_DIR} due to the exception handling.
Also refrain from using f-strings.
--- meta/classes/create-spdx.bbclass | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
meta/classes/create-spdx.bbclass +8 -5
@@ -67,6 +67,7 @@ def convert_license_to_spdx(lic, document, d, existing={}): extracted_info = oe.spdx.SPDXExtractedLicensingInfo() extracted_info.name = name extracted_info.licenseId = ident + extracted_info.extractedText = None if name == "PD": # Special-case this.
@@ -78,10 +79,12 @@ def convert_license_to_spdx(lic, document, d, existing={}): with (Path(directory) / name).open(errors="replace") as f: extracted_info.extractedText = f.read() break - except Exception as e: - # Error out, as the license was in available_licenses so - # should be on disk somewhere. - bb.error(f"Cannot find text for license {name}: {e}") + except FileNotFoundError: + pass + if extracted_info.extractedText is None: + # Error out, as the license was in available_licenses so should + # be on disk somewhere. + bb.error("Cannot find text for license %s" % name) else: # If it's not SPDX, or PD, or in available licenses, then NO_GENERIC_LICENSE must be set filename = d.getVarFlag('NO_GENERIC_LICENSE', name)
@@ -90,7 +93,7 @@ def convert_license_to_spdx(lic, document, d, existing={}): with open(filename, errors="replace") as f: extracted_info.extractedText = f.read() else: - bb.error(f"Cannot find any text for license {name}") + bb.error("Cannot find any text for license %s" % name) extracted[name] = extracted_info document.hasExtractedLicensingInfos.append(extracted_info)
Quoted 6 lines · Peter Kjellerstedt
Before, even if the code was seemingly written to search through all licenses in ${COMMON_LICENSE_DIR} and ${LICENSE_PATH}, it would actually bail out after only searching ${COMMON_LICENSE_DIR} due to the exception handling.
Also refrain from using f-strings.
Just out of interest: why that? - I think with the recent bump to python 3.6 as the minimum required version, there isn't any technical reason to avoid usage of f-strings in the class code
Quoted 49 lines
Signed-off-by Peter Kjellerstedt <[email protected]>--- meta/classes/create-spdx.bbclass | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)meta/classes/create-spdx.bbclass +8
-5@@ -67,6 +67,7 @@ def convert_license_to_spdx(lic, document, d, existing={}): extracted_info = oe.spdx.SPDXExtractedLicensingInfo() extracted_info.name = name extracted_info.licenseId = ident + extracted_info.extractedText = None if name == "PD": # Special-case this.@@ -78,10 +79,12 @@ def convert_license_to_spdx(lic, document, d, existing={}): with (Path(directory) / name).open(errors="replace") as f: extracted_info.extractedText = f.read() break - except Exception as e: - # Error out, as the license was in available_licenses so - # should be on disk somewhere. - bb.error(f"Cannot find text for license {name}: {e}") + except FileNotFoundError: + pass + if extracted_info.extractedText is None: + # Error out, as the license was in available_licenses so should + # be on disk somewhere. + bb.error("Cannot find text for license %s" % name) else: # If it's not SPDX, or PD, or in available licenses, then NO_GENERIC_LICENSE must be set filename = d.getVarFlag('NO_GENERIC_LICENSE', name)@@ -90,7 +93,7 @@ def convert_license_to_spdx(lic, document, d, existing={}): with open(filename, errors="replace") as f: extracted_info.extractedText = f.read() else: - bb.error(f"Cannot find any text for license {name}") + bb.error("Cannot find any text for license %s" % name) extracted[name] = extracted_info document.hasExtractedLicensingInfos.append(extracted_info)
Quoted 14 lines
-----Original Message-----
From: Konrad Weihmann <[email protected]>
Sent: den 14 september 2021 20:25
To: Peter Kjellerstedt <[email protected]>; openembedded- [email protected]
Subject: Re: [OE-core] [PATCH] create-spdx.bbclass: Search all license directories for licensesQuoted 5 lines · Peter Kjellerstedt
Before, even if the code was seemingly written to search through all licenses in ${COMMON_LICENSE_DIR} and ${LICENSE_PATH}, it would actually bail out after only searching ${COMMON_LICENSE_DIR} due to the exception handling.
Quoted 5 lines
Quoted 1 line
Also refrain from using f-strings.
Just out of interest: why that? - I think with the recent bump to python 3.6 as the minimum required version, there isn't any technical reason to avoid usage of f-strings in the class code
Well, it was mainly due to the discussions we have had about starting to use f-strings in OE-Core where RP has been reluctant to endorse it based on that it may cause problems when backporting code to Dunfell and Hardknott that still have older version of Python as minimum versions.
That said, create-spdx.bbclass is not likely to be backported to any older version of OE-Core so maybe it is ok to leave the use of f-strings as they were.
//Peter
Quoted 43 lines
Quoted 43 lines
Signed-off-by Peter Kjellerstedt <[email protected]>--- meta/classes/create-spdx.bbclass | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)meta/classes/create-spdx.bbclass +8
-5@@ -67,6 +67,7 @@ def convert_license_to_spdx(lic, document, d, existing={}): extracted_info = oe.spdx.SPDXExtractedLicensingInfo() extracted_info.name = name extracted_info.licenseId = ident + extracted_info.extractedText = None if name == "PD": # Special-case this.@@ -78,10 +79,12 @@ def convert_license_to_spdx(lic, document, d, existing={}): with (Path(directory) / name).open(errors="replace") as f: extracted_info.extractedText = f.read() break - except Exception as e: - # Error out, as the license was in available_licenses so - # should be on disk somewhere. - bb.error(f"Cannot find text for license {name}: {e}") + except FileNotFoundError: + pass + if extracted_info.extractedText is None: + # Error out, as the license was in available_licenses so should + # be on disk somewhere. + bb.error("Cannot find text for license %s" % name) else: # If it's not SPDX, or PD, or in available licenses, then NO_GENERIC_LICENSE must be set filename = d.getVarFlag('NO_GENERIC_LICENSE', name)@@ -90,7 +93,7 @@ def convert_license_to_spdx(lic, document, d, existing={}): with open(filename, errors="replace") as f: extracted_info.extractedText = f.read() else: - bb.error(f"Cannot find any text for license {name}") + bb.error("Cannot find any text for license %s" % name) extracted[name] = extracted_info document.hasExtractedLicensingInfos.append(extracted_info)
Quoted 42 lines · Peter Kjellerstedt
Before, even if the code was seemingly written to search through all licenses in ${COMMON_LICENSE_DIR} and ${LICENSE_PATH}, it would actually bail out after only searching ${COMMON_LICENSE_DIR} due to the exception handling.
Also refrain from using f-strings.
Signed-off-by Peter Kjellerstedt <[email protected]>--- meta/classes/create-spdx.bbclass | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)meta/classes/create-spdx.bbclass +7
-4@@ -67,6 +67,7 @@ def convert_license_to_spdx(lic, document, d, existing={}): extracted_info = oe.spdx.SPDXExtractedLicensingInfo() extracted_info.name = name extracted_info.licenseId = ident + extracted_info.extractedText = None if name == "PD": # Special-case this.@@ -78,10 +79,12 @@ def convert_license_to_spdx(lic, document, d, existing={}): with (Path(directory) / name).open(errors="replace") as f: extracted_info.extractedText = f.read() break - except Exception as e: - # Error out, as the license was in available_licenses so - # should be on disk somewhere. - bb.error(f"Cannot find text for license {name}: {e}") + except FileNotFoundError: + pass + if extracted_info.extractedText is None: + # Error out, as the license was in available_licenses so should + # be on disk somewhere. + bb.error("Cannot find text for license %s" % name) else: # If it's not SPDX, or PD, or in available licenses, then NO_GENERIC_LICENSE must be set filename = d.getVarFlag('NO_GENERIC_LICENSE', name)
meta/classes/create-spdx.bbclass def convert_license_to_spdx(lic, document, d, existing={}): · line 99
Quoted 8 lines
meta/classes/create-spdx.bbclass +1
-1@@ -90,7 +93,7 @@ def convert_license_to_spdx(lic, document, d, existing={}): with open(filename, errors="replace") as f: extracted_info.extractedText = f.read() else: - bb.error(f"Cannot find any text for license {name}") + bb.error("Cannot find any text for license %s" % name) extracted[name] = extracted_info document.hasExtractedLicensingInfos.append(extracted_info)
LGTM