specfile icon indicating copy to clipboard operation
specfile copied to clipboard

Create Specfile from a virtual file

Open FrostyX opened this issue 2 years ago • 4 comments

Currently, it is possible to create an object of Specfile like this:

# using an absolute path
specfile = Specfile('/tmp/test.spec')

# using a relative path and a different sourcedir
specfile = Specfile('test.spec', sourcedir='/tmp/sources')

It would be nice to be able to create it also like this

with open('/tmp/test.spec', 'r') as fp:
    specfile = Specfile(fp)

This alone is not so interesting, but it allows for creating Specfile from a virtual file

from io import StringIO
fp = StringIO()
fp.write("Name: foo\nVersion: 1.0\nRelease: 1\n...")
specfile = Specfile(fp)

Of course, I am interested in the feature, not the exact syntax. My suggestion will probably have an issue with the .save() method so if it is done like

specfile = Specfile(fp=fp)

# or

specfile = Specfile.from_fp(fp)

It is all fine with me :-)

FrostyX avatar Feb 04 '23 06:02 FrostyX

This shouldn't be a problem, I'd probably go with adding a fp argument to the constructor. However, sourcedir would have to be specified when using fp.

nforro avatar Feb 06 '23 08:02 nforro

Still relevant but low priority.

majamassarini avatar May 09 '24 07:05 majamassarini

@FrostyX is this still useful for you?

majamassarini avatar May 09 '24 07:05 majamassarini

Still relevant but low priority. @FrostyX is this still useful for you?

No problem with me. Somewhere (if I could only remember where) I wanted to do this and couldn't, so I workarounded it by saving the specfile from a variable to a temporary file and using Specfile the standard way.

I still think it is useful but I agree with the low priority since it can be easily workarounded.

FrostyX avatar May 10 '24 10:05 FrostyX

Still relevant, but not a high priority since we can workaround this...

lachmanfrantisek avatar Feb 13 '25 08:02 lachmanfrantisek

Hi, I'm interested in working on this issue as part of my GSoC preparation. I'm learning Fedora packaging and Python, and this looks like a good way to understand how spec files are parsed. I'd like to implement this feature by adding new attributes (license_files, doc_files) to the Specfile class and update the parsing logic accordingly.

kaosiso avatar Apr 29 '25 22:04 kaosiso

@kaosiso This issue has been fixed and closed, there is nothing to do here.

nforro avatar May 04 '25 18:05 nforro