[pacman-dev] [RFC] Package parser in python

Sebastian Nowicki sebnow at gmail.com
Fri Dec 11 22:46:20 EST 2009


On 01/10/2009, at 10:47 PM, Sebastian Nowicki wrote:

>
> On Oct 1, 2009, at 4:32 PM, Allan McRae wrote:
>
>> Sebastian Nowicki wrote:
>>>
>>> On Oct 1, 2009, at 2:52 PM, Allan McRae wrote:
>>>
>>>> Hi,
>>>>
>>>> This is one part of the makepkg test suite I am working on.   It  
>>>> is fairly a simple class that takes a pacman package filename and  
>>>> does some parsing.  Currently that involves getting the file list  
>>>> and the info from the .PKGINFO file.
>>>>
>>>> I am still fairly new to python so I am looking for comments on  
>>>> how this could be improved.
>>>> One idea I have had is to not initialize all the fields in the  
>>>> pkginfo dict and add a test if an array exists before appending.   
>>>> It would make the code tidier but that would mean the need to  
>>>> test if the field exists when comparing it later.
>>>
>>> I didn't really look at the script, but I made a similar parser  
>>> [1] earlier, initially for AUR2 purposes. Looking over it, it  
>>> seems I don't include the file list during parsing, but that can  
>>> probably be easily added in. Perhaps it can be expanded upon,  
>>> instead of creating a new one. If not it should at least help.
>>>
>>> [1] http://github.com/sebnow/parched/blob/master/parched.py
>>
>> Ah....   I had seen that before but I thought it only parsed  
>> PKGBUILDs for some reason.  I have been using that for some ideas  
>> for my PKGBUILD parser but it needed a big overhaul for package  
>> splitting.
>
> Indeed, I haven't kept it up to date. I've wanted to actually  
> implement a tiny and safe bash parser to make it work with all  
> PKGBUILDs, but it I could never settle on the feature list (bash is  
> bigger than I thought). Such changes to the PKGBUILD spec shouldn't  
> affect it then. That would be overkill for a test suite though :P.
>
> It seems our package parsers are pretty much the same, with the  
> exception of variable naming.

As you may have heard, I started a proper PKGBUILD parser[1], which  
parses according to shell semantics and does a little interpreting. I  
just released the first version, which doesn't handle errors, or multi- 
line values (like arrays or escaped newlines) very well. It does  
however support split packages. I'm in the process of modifying  
parched to essentially turn it into python bindings[2] for pkgparse.

You probably already have a parser at this point, so I'm not sure how  
useful this would be to you (it might be overkill anyway), I just  
though I'd let you know.

[1]: http://github.com/sebnow/pkgparse
[2]: http://github.com/sebnow/parched/tree/pkgparse_pyrex



More information about the pacman-dev mailing list