;; Python wrapped with jemalloc enabled
;; (needed by pxr.Usdviewq Python module)
(define python-for-usd
(package
(inherit python-3.9)
(inputs (modify-inputs (package-inputs python-3.9)
(prepend jemalloc-5.3)))
(arguments
(substitute-keyword-arguments (package-arguments python-3.9)
((#:phases phases)
`(modify-phases ,phases
(add-after 'install 'use-jemalloc
(lambda* (#:key inputs outputs #:allow-other-keys)
(wrap-program (string-append (assoc-ref outputs "out")
"/bin/python3.9")
`("LD_PRELOAD" =
(,(search-input-file
inputs "/lib/libjemalloc.so.2"))))))))))))
(define* (wrap-python3 python
#:optional
(name (string-append (package-name python) "-wrapper")))
(package/inherit python
(name name)
(source #f)
(build-system trivial-build-system)
(outputs '("out"))
(inputs `(("bash" ,bash)))
(propagated-inputs `(("python" ,python)))
(arguments
`(#:modules ((guix build utils))
#:builder
(begin
(use-modules (guix build utils))
(let ((bin (string-append (assoc-ref %outputs "out") "/bin"))
(python (string-append (assoc-ref %build-inputs "python") "/bin/")))
(mkdir-p bin)
(for-each
(lambda (old new)
(symlink (string-append python old)
(string-append bin "/" new)))
`("python3" ,"pydoc3" ,"pip3")
`("python" ,"pydoc" ,"pip"))
;; python-config outputs search paths based upon its location,
;; use a bash wrapper to avoid changing its outputs.
(let ((bash (string-append (assoc-ref %build-inputs "bash")
"/bin/bash"))
(old (string-append python "python3-config"))
(new (string-append bin "/python-config")))
(with-output-to-file new
(lambda ()
(format #t "#!~a~%" bash)
(format #t "exec \"~a\" \"$@\"~%" old)
(chmod new #o755))))))))
(synopsis "Wrapper for the Python 3 commands")
(description
"This package provides wrappers for the commands of Python@tie{}3.x such
that they can also be invoked under their usual names---e.g., @command{python}
instead of @command{python3} or @command{pip} instead of @command{pip3}.
To function properly, this package should not be installed together with the
@code{python} package: this package uses the @code{python} package as a
propagated input, so installing this package already makes both the versioned
and the unversioned commands available.")))
;; "python" link pointing to "python3" command
(define-public python-wrapper-for-usd (wrap-python3 python-for-usd))