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---