unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Antwane Mason <ad.mason1413@gmail.com>
To: guix-devel@gnu.org
Subject: Re: Python Site Package Syntax Runtime Error
Date: Mon, 20 Sep 2021 16:10:42 -0400	[thread overview]
Message-ID: <CAAztfgL8FRPzo-RsYd1b4kNQmYneTTHwPmHfSTBgvjEPxjUE0A@mail.gmail.com> (raw)
In-Reply-To: <CAAztfgL+ZmbupibJtAeEQLdLoPwR=BNmnU80YU10Ea35P3jdeA@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 5891 bytes --]

On Sun, Sep 19, 2021 at 1:59 PM Maxime Devos <maximedevos@telenet.be> wrote:

> Anyway, to prevent onlykey_agent.py from being wrapped, you can replace
> the 'wrap' phase with a custom 'wrap' phase adjusted for onlykey-agent
> pecularities:
>
> (package
>   (name "python-onlykey-agent")
>   ...
>   (arguments
>     `(#:phases
>       (modify-phases %standard-phases
>         (replace 'wrap
>           (lambda* (#:key outputs #:allow-other-keys)
>             (define bin (string-append (assoc-ref outputs "out") "/bin")
>             ;; Replace ??? with something appropriate for onlykey-agent
>             (wrap-program (string-append bin "/onlykey-agent)
>                `("PYTHONPATH" '??? '???))
>             'maybe-wrap-other-things
>             '???))))))
>
>
Maxime, thank you for the suggestion! I ended up with the following which
worked somewhat better but was running into runtime issues. Wanted to post
my code snippet here in case this is helpful to someone else.
This is a slight modification of code for wrap phase from
guix/build/python-build-system.scm.

--8<---------------cut here---------------start------------->8---
(arguments
     '(#:phases
       (modify-phases %standard-phases
         ;; prevents runtime error where shell wrapper for onlykey_agent.py
is loaded as module
         (replace 'wrap
           (lambda* (#:key inputs outputs #:allow-other-keys)
             (define (list-of-files dir)
               (find-files dir (lambda (file stat)
                                 (and (eq? 'regular (stat:type stat))
                                      (not (wrapper? file))
                                      (not ((file-name-predicate
"onlykey_agent.py")
                                            file
                                            stat))))))

             (define bindirs
               (let ((out (assoc-ref outputs "out")))
                 (list (string-append out "/bin")
                       (string-append out "/sbin"))))

             (let* ((out  (assoc-ref outputs "out"))
                    (python (assoc-ref inputs "python"))
                    (var `("PYTHONPATH" prefix
                           ,(cons (string-append out "/lib/python"
                                                 (python-version python)
                                                 "/site-packages")
                                  (search-path-as-string->list
                                   (or (getenv "PYTHONPATH") ""))))))
               (for-each (lambda (dir)
                           (let ((files (list-of-files dir)))
                             (for-each (lambda (file) (wrap-program file
var))
                                       files)))
                         bindirs)
               #t))))))
--8<---------------cut here---------------end--------------->8---

Regards,
Antwane


On Mon, Sep 20, 2021 at 4:09 PM Antwane Mason <ad.mason1413@gmail.com>
wrote:

>
> On Sun, Sep 19, 2021 at 1:59 PM Maxime Devos <maximedevos@telenet.be>
> wrote:
>
>> Anyway, to prevent onlykey_agent.py from being wrapped, you can replace
>> the 'wrap' phase with a custom 'wrap' phase adjusted for onlykey-agent
>> pecularities:
>>
>> (package
>>   (name "python-onlykey-agent")
>>   ...
>>   (arguments
>>     `(#:phases
>>       (modify-phases %standard-phases
>>         (replace 'wrap
>>           (lambda* (#:key outputs #:allow-other-keys)
>>             (define bin (string-append (assoc-ref outputs "out") "/bin")
>>             ;; Replace ??? with something appropriate for onlykey-agent
>>             (wrap-program (string-append bin "/onlykey-agent)
>>                `("PYTHONPATH" '??? '???))
>>             'maybe-wrap-other-things
>>             '???))))))
>>
>>
> Thank you for the suggestion! I ended up with the following which worked
> somewhat better but was running into runtime issues. Wanted to post my code
> snippet here in case this is helpful to someone else.
> This is a slight modification of code for wrap phase from
> guix/build/python-build-system.scm.
>
> --8<---------------cut here---------------start------------->8---
> (arguments
>      '(#:phases
>        (modify-phases %standard-phases
>          ;; prevents runtime error where shell wrapper for
> onlykey_agent.py is loaded as module
>          (replace 'wrap
>            (lambda* (#:key inputs outputs #:allow-other-keys)
>              (define (list-of-files dir)
>                (find-files dir (lambda (file stat)
>                                  (and (eq? 'regular (stat:type stat))
>                                       (not (wrapper? file))
>                                       (not ((file-name-predicate
> "onlykey_agent.py")
>                                             file
>                                             stat))))))
>
>              (define bindirs
>                (let ((out (assoc-ref outputs "out")))
>                  (list (string-append out "/bin")
>                        (string-append out "/sbin"))))
>
>              (let* ((out  (assoc-ref outputs "out"))
>                     (python (assoc-ref inputs "python"))
>                     (var `("PYTHONPATH" prefix
>                            ,(cons (string-append out "/lib/python"
>                                                  (python-version python)
>                                                  "/site-packages")
>                                   (search-path-as-string->list
>                                    (or (getenv "PYTHONPATH") ""))))))
>                (for-each (lambda (dir)
>                            (let ((files (list-of-files dir)))
>                              (for-each (lambda (file) (wrap-program file
> var))
>                                        files)))
>                          bindirs)
>                #t))))))
> --8<---------------cut here---------------end--------------->8---
>

[-- Attachment #2: Type: text/html, Size: 8774 bytes --]

      parent reply	other threads:[~2021-09-20 20:11 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-07 17:39 Python Site Package Syntax Runtime Error Antwane Mason
2021-09-16 12:06 ` Hartmut Goebel
2021-09-18 19:44   ` Antwane Mason
2021-09-19 16:31     ` Antwane Mason
2021-09-20 12:32     ` Hartmut Goebel
2021-09-20 20:28       ` Antwane Mason
2021-09-20 20:45         ` Hartmut Goebel
2021-09-19 17:59 ` Maxime Devos
     [not found]   ` <CAAztfgL+ZmbupibJtAeEQLdLoPwR=BNmnU80YU10Ea35P3jdeA@mail.gmail.com>
2021-09-20 20:10     ` Antwane Mason [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAAztfgL8FRPzo-RsYd1b4kNQmYneTTHwPmHfSTBgvjEPxjUE0A@mail.gmail.com \
    --to=ad.mason1413@gmail.com \
    --cc=guix-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).