specfile icon indicating copy to clipboard operation
specfile copied to clipboard

Instantiate Specfile with a string

Open danishprakash opened this issue 2 years ago • 3 comments

Description

Currently, it's possible to do this via a file path. In my use case, all I'm doing is fetching the specfile for multiple packages via OSC API and then trying to parse them using Specfile. I'm currently creating a temp file and then passing it on to the package.

Is this something that can be supported or have there been any discussions in the past about this that ruled it out?

Benefit

No response

Importance

No response

Workaround

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

Participation

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

danishprakash avatar Jul 10 '23 12:07 danishprakash

This should definitely be possible, let me think about implementation.

nforro avatar Jul 10 '23 16:07 nforro

That's great, let me know If I can help with this.

danishprakash avatar Jul 11 '23 04:07 danishprakash

Still relevant. @danishprakash by any chance, would you be interested in contributing this? (We can definitely help.)

lachmanfrantisek avatar Jul 11 '24 07:07 lachmanfrantisek

is the usage something like mentioned in #206 ?

mynk8 avatar Mar 10 '25 18:03 mynk8

My idea is to be able to create an object by passing in a string, this is assuming I have a string buffer with the specfile contents. #206 seems to be suggesting to allow a file handle to be passed to to the constructor.

danishprakash avatar Mar 11 '25 05:03 danishprakash

What i think is the string can be passed from a method with the sourcedir argument from_str(spec_content) like:

spec_content = """\
Name: example
Version: 1.0
Release: 1%{?dist}
Summary: Example Package
"""
specfile = Specfile.from_str(spec_content, sourcedir="/abc")

the method will take string buffer and write to a tempfile to maintain the file behaviour that returns a path and avoid touching parts like save() and reload() since they operate on files and expect path to be present. sourcedir will be required. This is just the same as the workaround.

mynk8 avatar Mar 11 '25 15:03 mynk8

Wouldn't it make more sense to first implement #206 and then use a StringIO instance internally and initialize it with a given string?

nforro avatar Mar 11 '25 15:03 nforro

Yeah, that's why i had a thought if #206 is somehow related. If this approach is alright i can work on it.

mynk8 avatar Mar 11 '25 16:03 mynk8