diff mbox series

[V2] meta/lib/oe/spdx30.py: make StringProp to decode SPDX alias with actual ID

Message ID 20241216052052.338858-1-hongxu.jia@windriver.com
State New
Headers show
Series [V2] meta/lib/oe/spdx30.py: make StringProp to decode SPDX alias with actual ID | expand

Commit Message

Hongxu Jia Dec. 16, 2024, 5:20 a.m. UTC
After commit [spdx 3.0: Rework how SPDX aliases are linked] applied, it set
license_text_map with SPDX alias other than actual ID

The property of simplelicensing_customIdToUri is ListProp(ObjectProp(DictionaryEntry))),
and class DictionaryEntry has key and value, the property of value is StringProp other
than ObjectProp in which could not support to decode/extract SPDX alias with actual ID
in image jsonld file
-----------
      "simplelicensing_customIdToUri": [
        {
          "type": "DictionaryEntry",
          "key": "LicenseRef-PD",
          "value": "http://spdxdocs.org/openembedded-alias/by-doc-hash/d53e90e23b12c4ad640809a74a810e86f31c76cdbdf36487712d22a33d53362a/sqlite3-native/UNIHASH/license-text/PD"
        }
      ],
-----------

This commit make StringProp to decode string as IRI first in which replace SPDX alias with
actual ID. For other situation, still return string as usual
-----------
      "simplelicensing_customIdToUri": [
        {
          "type": "DictionaryEntry",
          "key": "LicenseRef-PD",
          "value": "http://spdx.org/spdxdocs/sqlite3-native-e5cc0672-d8dd-57e8-a2df-fe4615831fda/162c62b5b011cd3f82f413b3dae4d6d1542201552c964d5ce69fe170e0720b85/license-text/PD"
        }
      ]
-----------

Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
---
 meta/lib/oe/spdx30.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Joshua Watt Dec. 16, 2024, 3:32 p.m. UTC | #1
On Sun, Dec 15, 2024 at 10:20 PM Hongxu Jia <hongxu.jia@windriver.com> wrote:
>
> After commit [spdx 3.0: Rework how SPDX aliases are linked] applied, it set
> license_text_map with SPDX alias other than actual ID
>
> The property of simplelicensing_customIdToUri is ListProp(ObjectProp(DictionaryEntry))),
> and class DictionaryEntry has key and value, the property of value is StringProp other
> than ObjectProp in which could not support to decode/extract SPDX alias with actual ID
> in image jsonld file
> -----------
>       "simplelicensing_customIdToUri": [
>         {
>           "type": "DictionaryEntry",
>           "key": "LicenseRef-PD",
>           "value": "http://spdxdocs.org/openembedded-alias/by-doc-hash/d53e90e23b12c4ad640809a74a810e86f31c76cdbdf36487712d22a33d53362a/sqlite3-native/UNIHASH/license-text/PD"
>         }
>       ],
> -----------
>
> This commit make StringProp to decode string as IRI first in which replace SPDX alias with
> actual ID. For other situation, still return string as usual
> -----------
>       "simplelicensing_customIdToUri": [
>         {
>           "type": "DictionaryEntry",
>           "key": "LicenseRef-PD",
>           "value": "http://spdx.org/spdxdocs/sqlite3-native-e5cc0672-d8dd-57e8-a2df-fe4615831fda/162c62b5b011cd3f82f413b3dae4d6d1542201552c964d5ce69fe170e0720b85/license-text/PD"
>         }
>       ]
> -----------
>
> Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
> ---
>  meta/lib/oe/spdx30.py | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/meta/lib/oe/spdx30.py b/meta/lib/oe/spdx30.py
> index 5cd2eb45c3..160b55f84b 100644
> --- a/meta/lib/oe/spdx30.py
> +++ b/meta/lib/oe/spdx30.py
> @@ -96,7 +96,12 @@ class StringProp(Property):
>          encoder.write_string(value)
>
>      def decode(self, decoder, *, objectset=None):
> -        return decoder.read_string()
> +        s = decoder.read_string()
> +        if is_IRI(s) and objectset:
> +            obj = objectset.find_by_id(s)
> +            if obj is not None:
> +                return obj._id
> +        return s

Sorry, this can't be done this way. These bindings are autogenerated
using a tool (shacl2code, see scripts/contrib/make-spdx-bindings.sh),
so it will be overwritten next time the bindings are generated

>
>
>  class AnyURIProp(StringProp):
> --
> 2.25.1
>
Hongxu Jia Dec. 17, 2024, 2:48 a.m. UTC | #2
Got it, submitted PR [1] to shacl2code repo to make StringProp to decode SPDX alias with actual ID

[1] https://github.com/JPEWdev/shacl2code/pull/34 to shacl2code

//Hongxu
________________________________
From: Joshua Watt <jpewhacker@gmail.com>
Sent: Monday, December 16, 2024 11:32 PM
To: Jia, Hongxu <Hongxu.Jia@windriver.com>
Cc: openembedded-core@lists.openembedded.org <openembedded-core@lists.openembedded.org>
Subject: Re: [PATCH V2] meta/lib/oe/spdx30.py: make StringProp to decode SPDX alias with actual ID

CAUTION: This email comes from a non Wind River email account!
Do not click links or open attachments unless you recognize the sender and know the content is safe.

On Sun, Dec 15, 2024 at 10:20 PM Hongxu Jia <hongxu.jia@windriver.com> wrote:
>
> After commit [spdx 3.0: Rework how SPDX aliases are linked] applied, it set
> license_text_map with SPDX alias other than actual ID
>
> The property of simplelicensing_customIdToUri is ListProp(ObjectProp(DictionaryEntry))),
> and class DictionaryEntry has key and value, the property of value is StringProp other
> than ObjectProp in which could not support to decode/extract SPDX alias with actual ID
> in image jsonld file
> -----------
>       "simplelicensing_customIdToUri": [
>         {
>           "type": "DictionaryEntry",
>           "key": "LicenseRef-PD",
>           "value": "http://spdxdocs.org/openembedded-alias/by-doc-hash/d53e90e23b12c4ad640809a74a810e86f31c76cdbdf36487712d22a33d53362a/sqlite3-native/UNIHASH/license-text/PD"
>         }
>       ],
> -----------
>
> This commit make StringProp to decode string as IRI first in which replace SPDX alias with
> actual ID. For other situation, still return string as usual
> -----------
>       "simplelicensing_customIdToUri": [
>         {
>           "type": "DictionaryEntry",
>           "key": "LicenseRef-PD",
>           "value": "http://spdx.org/spdxdocs/sqlite3-native-e5cc0672-d8dd-57e8-a2df-fe4615831fda/162c62b5b011cd3f82f413b3dae4d6d1542201552c964d5ce69fe170e0720b85/license-text/PD"
>         }
>       ]
> -----------
>
> Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
> ---
>  meta/lib/oe/spdx30.py | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/meta/lib/oe/spdx30.py b/meta/lib/oe/spdx30.py
> index 5cd2eb45c3..160b55f84b 100644
> --- a/meta/lib/oe/spdx30.py
> +++ b/meta/lib/oe/spdx30.py
> @@ -96,7 +96,12 @@ class StringProp(Property):
>          encoder.write_string(value)
>
>      def decode(self, decoder, *, objectset=None):
> -        return decoder.read_string()
> +        s = decoder.read_string()
> +        if is_IRI(s) and objectset:
> +            obj = objectset.find_by_id(s)
> +            if obj is not None:
> +                return obj._id
> +        return s

Sorry, this can't be done this way. These bindings are autogenerated
using a tool (shacl2code, see scripts/contrib/make-spdx-bindings.sh),
so it will be overwritten next time the bindings are generated

>
>
>  class AnyURIProp(StringProp):
> --
> 2.25.1
>
diff mbox series

Patch

diff --git a/meta/lib/oe/spdx30.py b/meta/lib/oe/spdx30.py
index 5cd2eb45c3..160b55f84b 100644
--- a/meta/lib/oe/spdx30.py
+++ b/meta/lib/oe/spdx30.py
@@ -96,7 +96,12 @@  class StringProp(Property):
         encoder.write_string(value)
 
     def decode(self, decoder, *, objectset=None):
-        return decoder.read_string()
+        s = decoder.read_string()
+        if is_IRI(s) and objectset:
+            obj = objectset.find_by_id(s)
+            if obj is not None:
+                return obj._id
+        return s
 
 
 class AnyURIProp(StringProp):