Hi Felix,

Felix Lechner <felix.lech...@lease-up.com> writes:
> Hi Théo,
>
> On Fri, Jan 19 2024, Théo Tyburn wrote:
>
>> How do I go about packaging it to make the script available from the command 
>> line
>> without polluting the environment with the dependencies ?
>
> The best way is wrap-program, or my forthcoming wrap-executable.
>
> Kind regards
> Felix


This is what I was looking for, thanks !

If someone is interested, here is my function to wrap a python script in a 
package:

#+BEGIN_SRC scheme
(define*-public (python-script-package name source-dir source-file #:key 
(inputs '()))
  (package
   (name name)
   (version "")
   (source (local-file (string-append source-dir "/" source-file) #:recursive? 
#t))
   (build-system copy-build-system)
   (inputs (cons python inputs))
   (arguments (list #:install-plan #~'((#$source-file #$(string-append "bin/" 
name)))
                                        #:phases
                                        `(modify-phases %standard-phases
                                           (add-after 'strip 
'wrap-python-scripts
                                                 (lambda* (#:key outputs 
#:allow-other-keys)
                                                   ;; Make sure program runs 
with the correct PYTHONPATH.
                                                   (wrap-program 
(search-input-file outputs (string-append "bin/" ,name))
                                                         `("GUIX_PYTHONPATH" ":"
                                                           prefix (,(getenv 
"GUIX_PYTHONPATH")))))))))
   
   (home-page "")
   (synopsis "")
   (description "")
   (license license:lgpl3+)))
#+END_SRC

It works like a charm with my guix home declaration :)

Happy hacking !

Reply via email to