Skip to content

Specfile() fails to open given a read-only filename #534

@praiskup

Description

@praiskup

What happened? What is the problem?

When I open a filename that is -r--r--r--, I get:

  File "/usr/lib/python3.14/site-packages/copr_rpmbuild/helpers.py", line 418, in __init__
    self.spec = Specfile(path, macros=macros)
                ~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.14/site-packages/specfile/specfile.py", line 105, in __init__
    self._file = Path(path).open("r+", **self.ENCODING_ARGS)
                 ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.14/pathlib/__init__.py", line 771, in open
    return io.open(self, mode, buffering, encoding, errors, newline)
           ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

What did you expect to happen?

We aren't looking to modify the specfile; we just want to read some fields using python-specfile. I expect the Specfile class to handle this for us using read-only operations.

Example URL(s)

discussed here: fedora-copr/copr#4266

Steps to reproduce

1.call Specfile("/some-read-only-file.spec")

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

    complexity/single-taskRegular task; should be done within daysgain/lowDoesn't bring much value to usersimpact/lowAffects only few of the userskind/bugAn unexpected problem or behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions