Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'Sections' object has no attribute 'changelog' #404

Open
1 of 2 tasks
xsuchy opened this issue Jul 28, 2024 · 3 comments
Open
1 of 2 tasks

AttributeError: 'Sections' object has no attribute 'changelog' #404

xsuchy opened this issue Jul 28, 2024 · 3 comments
Labels
area/other Related to some other area/category than the specified ones. complexity/single-task Regular task, should be done within days. gain/low This doesn't bring that much value to users. impact/low This issue impacts only a few users. kind/feature New feature or a request for enhancement. workaround-exists There is an existing workaround that can be used in the meantime of implementing the issue.

Comments

@xsuchy
Copy link
Contributor

xsuchy commented Jul 28, 2024

Description

When Specfile does not have changelog section and you try to read it you get:

Traceback (most recent call last):
  File "/home/msuchy/projects/license-validate/./print-spec-changelog.py", line 10, in <module>
    print(sections.changelog)
          ^^^^^^^^^^^^^^^^^^
  File "/home/msuchy/.local/lib/python3.12/site-packages/specfile/sections.py", line 180, in __getattr__
    return super().__getattribute__(id)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Sections' object has no attribute 'changelog'

The script is

#!/usr/bin/python3
from specfile import Specfile
import sys

# this is dump, but do the work
filename = sys.argv[1]
specfile = Specfile(filename, force_parse=True)

with specfile.sections() as sections:
    print(sections.changelog)

While the TB is technically correct, I would argue that the getter should return empty section to make the user experience better.

Benefit

No response

Importance

No response

Workaround

  • There is an existing workaround that can be used until this feature is implemented.

Participation

  • I am willing to submit a pull request for this issue. (Packit team is happy to help!)
@xsuchy xsuchy added the kind/feature New feature or a request for enhancement. label Jul 28, 2024
@nforro
Copy link
Member

nforro commented Jul 29, 2024

I think the library should be able to express the difference between a spec file without a %changelog and a spec file with an empty %changelog. While it could be possible to "decouple" "changelog" in sections from sections.changelog, I'm not sure it's the best idea. Also, if sections.changelog returned an empty section, it would technically be creating a new section in the spec file, which should be a conscious action.

@nforro
Copy link
Member

nforro commented Jul 29, 2024

How about something like this, to make the creation explicit:

with spec.sections() as sections:
    changelog = sections.get_or_create("changelog")
    changelog[:] = ["%autochangelog"]

which would be equivalent to this:

with spec.sections() as sections:
    try:
        sections.changelog[:] = ["%autochangelog"]
    except AttributeError:
        sections.append(Section("changelog", data=["%autochangelog"]))

@xsuchy
Copy link
Contributor Author

xsuchy commented Jul 29, 2024

I like it.

@nforro nforro added area/other Related to some other area/category than the specified ones. complexity/single-task Regular task, should be done within days. gain/low This doesn't bring that much value to users. impact/low This issue impacts only a few users. workaround-exists There is an existing workaround that can be used in the meantime of implementing the issue. labels Jul 30, 2024
@nforro nforro moved this from new to backlog in Packit Kanban Board Jul 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/other Related to some other area/category than the specified ones. complexity/single-task Regular task, should be done within days. gain/low This doesn't bring that much value to users. impact/low This issue impacts only a few users. kind/feature New feature or a request for enhancement. workaround-exists There is an existing workaround that can be used in the meantime of implementing the issue.
Projects
Status: backlog
Development

No branches or pull requests

2 participants