From: Hartmut Goebel <h.goebel@crazy-compilers.com>
To: Ricardo Wurmus <rekado@elephly.net>
Cc: guix-devel@gnu.org
Subject: Re: PYTHONPATH woes
Date: Fri, 23 Feb 2018 13:36:17 +0100 [thread overview]
Message-ID: <ac8e389e-0392-e4ac-962e-a8273ec5bb90@crazy-compilers.com> (raw)
In-Reply-To: <87371tqbyb.fsf@elephly.net>
[-- Attachment #1: Type: text/plain, Size: 583 bytes --]
Am 22.02.2018 um 16:30 schrieb Ricardo Wurmus:
> (This wouldn’t help us much for wrapper scripts, though.)
Attached please fins an approach for solving this issue.
The basic idea is make the application/script use a python within a
virtual environment. I nee to rethink some details and check whether
this will work out.
See the comments in the code for how it is intended to work.
--
Regards
Hartmut Goebel
| Hartmut Goebel | h.goebel@crazy-compilers.com |
| www.crazy-compilers.com | compilers which you thought are impossible |
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: test-new-build2.scm --]
[-- Type: text/x-scheme; name="test-new-build2.scm", Size: 3213 bytes --]
;;; Copyright © 2018 Hartmut Goebel <h.goebel@crazy-compilers.com>
(use-modules (guix)
(gnu packages python)
(guix licenses))
;; TODO decide which path to use
(define VENV-DIR "/share/guix-venv/") ; trailing slash!
;; python-uniseg is a reasonable small package without any dependencies and
;; including a script
(package
(inherit python-uniseg)
(name "my-python-uniseg")
(version (package-version python-uniseg))
(arguments
`(#:tests? #f ; copied from base package
#:phases
(modify-phases %standard-phases
(replace 'wrap
(lambda* (#:key inputs outputs #:allow-other-keys)
;; This sets up a small virtual environment for the package
;; and wraps the scripts to
;; ../share/guix-venv/my-site-display-0.1
;; +- pyvenv.cfg
;; +- bin/python
;; +- lib/pythonX.Y/site-packages/NAME.pth
(let* ((out (assoc-ref outputs "out"))
(venv (string-append out ,VENV-DIR ,name "-" ,version))
(python (assoc-ref inputs "python"))
(site-dir (string-append "/lib/python"
"3.5" ;; FIXME (get-python-version python)
"/site-packages"))
(PYTHONPATH ;; FIXME: Why is ther only one entry?
(cons (string-append out site-dir)
(search-path-as-string->list
(or (getenv "PYTHONPATH") "")))))
(mkdir-p (string-append venv "/bin"))
(mkdir-p (string-append venv site-dir))
;; The existance of a pyvenv.cfg file marks this as being a virtual
;; environment
(call-with-output-file (string-append venv "/pyvenv.cfg")
(lambda (p)
(format p "#include-system-site-packages = false")))
;; Link to all required packages using a .pth file
(call-with-output-file (string-append venv site-dir "/" ,name ".pth")
(lambda (p)
(for-each (lambda (pkg)
(format p "~a~%" pkg))
PYTHONPATH)))
;; Create the python "executable" within the virtual environment
(for-each
(lambda (name)
(symlink (string-append python "/bin/" name)
(string-append venv "/bin/" name)))
`("python" ,"python3"))
)))
;; Re-wrap the scripts to use the python within the virtual env
(add-after 'patch-shebangs 'patch-python-venv-shebang
(lambda* (#:key outputs inputs #:allow-other-keys)
(let* ((out (assoc-ref outputs "out"))
(venv (string-append out ,VENV-DIR ,name "-" ,version))
(python (assoc-ref inputs "python")))
(define (venv-program file)
(substitute* file
(((string-append "#!" python "/bin/python([0-9](\\.[0-9])?)?"))
(string-append "#!" venv "/bin/python"))))
;; FIXME: Use logic from python-build-system to find scripts
(venv-program (string-append out "/bin/uniseg-dbpath"))
))))))
;; Some requirement to check if all required pathes are included into the
;; .pth-file.
(inputs
`(("req" ,python-simplejson)))
)
next prev parent reply other threads:[~2018-02-23 12:36 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-20 10:53 PYTHONPATH woes Ricardo Wurmus
2018-02-20 15:01 ` Pjotr Prins
2018-02-20 15:18 ` Andy Wingo
2018-02-20 16:40 ` Pjotr Prins
2018-02-20 15:30 ` Ricardo Wurmus
2018-02-21 21:58 ` Hartmut Goebel
2018-02-22 15:30 ` Ricardo Wurmus
2018-02-22 18:35 ` Hartmut Goebel
2018-02-22 20:42 ` Hartmut Goebel
2018-02-23 8:45 ` Vincent Legoll
2018-02-23 12:36 ` Hartmut Goebel [this message]
2018-02-23 16:59 ` Pjotr Prins
2018-02-23 19:36 ` Ricardo Wurmus
2018-02-23 23:54 ` Pjotr Prins
2018-02-24 10:44 ` Hartmut Goebel
2018-02-24 10:49 ` Hartmut Goebel
2018-02-27 11:43 ` PYTHONPATH issue analysis - part 1 (was: PYTHONPATH woes) Hartmut Goebel
2018-03-13 21:54 ` PYTHONPATH issue analysis - part 1 Hartmut Goebel
2018-02-27 11:49 ` PYTHONPATH issue analysis - part 2 (was: PYTHONPATH woes) Hartmut Goebel
2018-03-11 21:47 ` PYTHONPATH issue analysis - part 3 " Hartmut Goebel
2018-03-13 21:23 ` PYTHONPATH issue analysis - part 3 Ludovic Courtès
2018-03-13 21:44 ` Pjotr Prins
2018-03-13 22:02 ` Hartmut Goebel
2018-03-14 7:49 ` Pjotr Prins
2018-03-14 9:04 ` Hartmut Goebel
2018-03-14 18:21 ` Pjotr Prins
2018-03-15 19:48 ` Hartmut Goebel
2018-03-13 21:47 ` Hartmut Goebel
2018-03-14 9:41 ` Ludovic Courtès
2018-03-13 21:51 ` Hartmut Goebel
2018-03-14 0:10 ` Ricardo Wurmus
2018-03-15 9:09 ` Ludovic Courtès
2018-03-15 19:30 ` PYTHONPATH issue explanation Hartmut Goebel
2018-03-17 1:41 ` 宋文武
2018-03-17 10:07 ` Ricardo Wurmus
2018-03-17 22:46 ` Hartmut Goebel
2018-03-17 22:53 ` Hartmut Goebel
2018-03-17 11:18 ` [PATCH] gnu: python: Honor 'GUIX_PYTHON_X_Y_SITE_PACKAGES' 宋文武
2018-03-17 21:53 ` Hartmut Goebel
2018-03-18 0:04 ` 宋文武
2018-03-18 0:07 ` 宋文武
2018-03-17 22:04 ` PYTHONPATH issue explanation Hartmut Goebel
2018-03-18 0:57 ` 宋文武
2018-03-18 10:05 ` 宋文武
2018-03-24 20:47 ` Chris Marusich
2018-04-16 14:21 ` PYTHONPATH - let's systematically tame the baest Hartmut Goebel
2018-04-17 1:47 ` 宋文武
2018-04-17 7:03 ` Hartmut Goebel
2018-04-18 8:34 ` Ricardo Wurmus
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ac8e389e-0392-e4ac-962e-a8273ec5bb90@crazy-compilers.com \
--to=h.goebel@crazy-compilers.com \
--cc=guix-devel@gnu.org \
--cc=rekado@elephly.net \
/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 external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.