Subject: Re: bug#55139: package-location is wrong for transformed packages
From: Maxim Cournoyer <[email-masked]>
To: Ludovic Courtès <[email-masked]>
Cc: [email-masked]
Date: Wed, 08 Jun 2022 17:29:08 -0400
List-Id: <debbugs-submit.debbugs.gnu.org>

Hi Ludovic,

Ludovic Courtès <[email-masked]> writes:

> Hi!
>
> Maxim Cournoyer <[email-masked]> skribis:
>
>> Yeah, I ended up with this [0]:
>>
>> (define (locate-package-via-git name)
>>   "Return the location object corresponding to package NAME, searched via git."
>>   (let* ((input-pipe (open-pipe* OPEN_READ
>> 				 "git" "grep" "-n" "--column"
>>                                  (format #f "^(define-public ~a$" name)))
>> 	 (output (get-string-all input-pipe)) ;file:line:column:match
>> 	 (exit-val (status:exit-val (close-pipe input-pipe))))
>>     (case exit-val
>>       ((0)
>>        (let ((components (string-split output #\:)))
>>          (location
>>           (first components)                   ;file
>>           (string->number (second components)) ;1-indexed line
>>           ;; FIXME: Comment discrepancy in (guix diagnostics), which
>>           ;; says the column is 0-indexed.
>>           (and=> (string->number (third components)) 1-)))) ;0-indexed column
>>       ((1) #f)                                            ;no match
>>       (else (error "git grep failed with status" exit-val)))))
>>
>> and it does feel silly to have to shell out to git, but it did the job.
>>
>> Thanks,
>>
>> Maxim
>>
>> [0]  https://notabug.org/apteryx/guix-api-examples/src/master/purge-python2-packages.scm#L42
>
> Nice, it’s good to have these examples—and hopefully we’ll soon be able
> to remove a whole bunch of ‘python2-’ packages!
>
> As for ‘package-definition-location’, I don’t think we can reasonably do
> any better, so I’m tempted to close the bug.

OK; thanks for your input.

At least it'll be recorded somewhere for the next person stumbling on
this behavior to discover.

Maxim