specfile
specfile copied to clipboard
Сondition can be split between sections, which breaks the parsing
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!)
Thanks for the report. This is basically the same issue as https://github.com/packit/specfile/issues/231, but I didn't realize it affects also parsing. Let me think about how to fix this.
@mfocko maybe it's reasonable to move this issue to "priority backlog"?
There are a lot of packages with feature macros inside specfile
i.e
%if %{with dane}
%package dane
Summary: A DANE protocol implementation for GnuTLS
Requires: %{name}%{?_isa} = %{version}-%{release}
%endif
%if %{with guile}
%package guile
Summary: Guile bindings for the GNUTLS library
Requires: %{name}%{?_isa} = %{version}-%{release}
Requires: guile22
%endif
For example python3.9, gnutls and others...
Still relevant.