Skip to content

Failed to convert spdx to xml with Annotation #798

@lugmair

Description

@lugmair

I'm trying to convert a .spdx file to a .xml file.
This is my Code (it's basically the exact same code as in spdx2_convert_format example):

#  SPDX-FileCopyrightText: 2023 spdx contributors
#
#  SPDX-License-Identifier: Apache-2.0
from os import path

from spdx_tools.spdx.model import Document
from spdx_tools.spdx.writer.write_anything import write_file
from spdx_tools.spdx.parser.parse_anything import parse_file

# This example demonstrates how to load an existing SPDX2 file and convert it to a different SPDX2 format

# Provide a path to the input file in the originating format
input_path = path.join(path.dirname(__file__), "annotation_convert_fail.spdx")
# Parse the original input file (format is deduced automatically from the file extension)
document: Document = parse_file(input_path)
# Write to a different file format (e.g. XML, format is deduced automatically from the file extension)
write_file(document, "annotation_convert_fail.xml")

My .spdx file (example is in the .txt file) contains an Annotation and I wasn't able to make it work. I always got this error message:

Traceback (most recent call last):
  File "C:\Users\lugmair\PycharmProjects\spdx_to_xml\venv\SPDX_Parsing-Converting.py", line 16, in <module>
    document: Document = parse_file(input_path)
                         ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lugmair\PycharmProjects\spdx_to_xml\venv\Lib\site-packages\spdx_tools\spdx\parser\parse_anything.py", line 32, in parse_file
    return tagvalue_parser.parse_from_file(file_name, encoding)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lugmair\PycharmProjects\spdx_to_xml\venv\Lib\site-packages\spdx_tools\spdx\parser\tagvalue\tagvalue_parser.py", line 12, in parse_from_file
    document: Document = parser.parse(data)
                         ^^^^^^^^^^^^^^^^^^
  File "C:\Users\lugmair\PycharmProjects\spdx_to_xml\venv\Lib\site-packages\spdx_tools\spdx\parser\tagvalue\parser.py", line 537, in parse
    self.yacc.parse(text, lexer=self.lex)
  File "C:\Users\lugmair\PycharmProjects\spdx_to_xml\venv\Lib\site-packages\ply\yacc.py", line 333, in parse
    return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lugmair\PycharmProjects\spdx_to_xml\venv\Lib\site-packages\ply\yacc.py", line 1120, in parseopt_notrack
    p.callable(pslice)
  File "C:\Users\lugmair\PycharmProjects\spdx_to_xml\venv\Lib\site-packages\spdx_tools\spdx\parser\tagvalue\parser.py", line 494, in p_annotator
    set_value(p, self.current_element, method_to_apply=ActorParser.parse_actor)
  File "C:\Users\lugmair\PycharmProjects\spdx_to_xml\venv\Lib\site-packages\spdx_tools\spdx\parser\tagvalue\helper_methods.py", line 65, in set_value
    dict_to_fill[argument_name] = method_to_apply(parsed_value[2])
                                                  ~~~~~~~~~~~~^^^
  File "C:\Users\lugmair\PycharmProjects\spdx_to_xml\venv\Lib\site-packages\ply\yacc.py", line 243, in __getitem__
    return self.slice[n].value
           ~~~~~~~~~~^^^
IndexError: list index out of range

Process finished with exit code 1

But as soon as I comment out the Annotation the conversion works. I think the Parser is crashing somewhere when the Annotation is commented in.

annotation_convert_fail.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions