Skip to content

Сondition can be split between sections, which breaks the parsing #365

@nikitych

Description

@nikitych

What happened? What is the problem?

In case of pg_auto_failover.spec or xorgxrdp.spec begin of condition remains in main package section while %endif goes to sub-package. So you get IndexError when trying to parse it.

from specfile import Specfile
with Specfile("xorgxrdp.spec") as specfile:
    with specfile.sections() as sections:
        for section in sections:
            if "package" in section.name:
                with specfile.tags(section) as tags:
                    for tag in tags:
                        print(tag.name)
  File "/usr/lib64/python3.9/site-packages/specfile/context_management.py", line 133, in __call__
    self.values[key] = next(self.generators[key])
  File "/usr/lib64/python3.9/site-packages/specfile/specfile.py", line 273, in tags
    tags = Tags.parse(section, context=self)
  File "/usr/lib64/python3.9/site-packages/specfile/tags.py", line 497, in parse
    lines = process_conditions(list(section), macro_definitions, context)
  File "/usr/lib64/python3.9/site-packages/specfile/conditions.py", line 119, in process_conditions
    result.append((line, branches[-2]))
IndexError: list index out of range

What did you expect to happen?

No errors.

May be process conditions before splitting to sections?

Example URL(s)

No response

Steps to reproduce

1. get xorgxrdp.spec
2. try to get package glamor tags
3. IndexError: list index out of range

Workaround

  • There is an existing workaround that can be used until this issue is fixed.

Participation

  • I am willing to submit a pull request for this issue. (Packit team is happy to help!)

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/generalNot tied to a specific areacomplexity/single-taskRegular task; should be done within daysgain/highBrings a lot of value to usersimpact/lowAffects only few of the userskind/bugAn unexpected problem or behavior

    Type

    No type

    Projects

    Status

    backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions