[Toaster] virtualenv for toaster and python 3

Michael Wood michael.g.wood at intel.com
Wed Jun 8 05:56:22 PDT 2016


On 01/06/16 21:12, Ed Bartosh wrote:
> On Wed, Jun 01, 2016 at 10:24:52AM -0700, Christopher Larson wrote:
>> On Wed, Jun 1, 2016 at 2:27 AM, Ed Bartosh <ed.bartosh at linux.intel.com>
>> wrote:
>>
>>> On Tue, May 31, 2016 at 11:48:01AM -0700, Christopher Larson wrote:
>>>> On Tue, May 31, 2016 at 11:47 AM, Brian Avery <avery.brian at gmail.com>
>>> wrote:
>>>>> One possible solution is to use RP's suggestion to leverage the --user
>>>>> argument (which stores packges in
>>>>> $HOME/.local/lib/python3.4/site-packages.
>>>>>
>>>>>> pip3 install --user -r poky/bitbake/toaster-requirements.txt
>>>>> * works except wsgiref is not python3 compatible yet
>>>>>> pip3 list installed --local
>>>>> argparse (1.2.1)
>>>>> beautifulsoup4 (4.4.1)
>>>>> Django (1.8.13)
>>>>>
>>>>> * works to show what is a --user install vs a global site install.
>>>>>> pip3 uninstall/install --user --upgrade/.... works as expected...
>>>> Cluttering up my ~/.local with app/project specific requirements is not
>>>> appropriate. As someone who uses --user quite a bit, I'd be quite annoyed
>>>> by this.
>>> So far pip3 --user looks like the only working approach to me. It's not
>>> ideal, but it's not that bad either. It should be used for its direct
>>> purpose
>>> - to install dependencies for 'one user' mode.
>>>
>>> For production Toaster instances I'd suggest to install runtime
>>> dependencies on the host system.
>>>
>>> BTW, Toaster has only one runtime requirement: Django. argparse and
>>> wsgiref is a legacy and beautifulsoup4 is not a runtime dependency. It's
>>> used only
>>> in tests.
>>
>> --user is intended for use by the user,  not your scripts.
> True. I'm not saying that toaster should do that. User will run pip3
> install --user 'Django>1.8<1.9' or install Django 1.8 any other suitable
> way.
>
>> I choose what I put there for good reason. Your use case is what virtual environments are
>> for. If toaster can't handle that, it should be fixed to do so.
> Toaster can't be fixed to setup an environment where python is python2
> and python3 is python3. Neither virtualenv or venv support this.
>
>>  From the python documentation:
>>
>> This scheme is designed to be the most convenient solution for users that
>> don’t have write permission to the global site-packages directory or don’t
>> want to install into it.
> Yes, and this is exactly what I'm proposing. Sorry for not being clear.
>
> --
> Regards,
> Ed

Did anyone test this, it works for me:

$ virtualenv -p python3 bothpython
$ virtualenv -p python2 bothpython
$ source ./bothpython/bin/activate
$ pip3 install -r ./bitbake/toaster-requirements.txt
$ source toaster start

The only change needed is to fix the toaster script to use python3 to 
detect if the dependencies are installed or not.

diff --git a/bitbake/bin/toaster b/bitbake/bin/toaster
index be1bb9c..e3a0dae 100755
--- a/bitbake/bin/toaster
+++ b/bitbake/bin/toaster
@@ -115,7 +115,7 @@ verify_prereq() {
exp='s/Django\([><=]\+\)\([^,]\+\),\([><=]\+\)\(.\+\)/'
      exp=$exp'import sys,django;version=django.get_version().split(".");'
      exp=$exp'sys.exit(not (version \1 "\2".split(".") and version \3 
"\4".split
-    if ! sed -n "$exp" $reqfile | python - ; then
+    if ! sed -n "$exp" $reqfile | python3 - ; then
          req=`grep ^Django $reqfile`
          echo "This program needs $req"
          echo "Please install with pip install -r $reqfile"


Michael


More information about the toaster mailing list