0

I have GNOME Builder installed on 3.24.1 installed on Ubuntu 17.04. I have a functional Django project and an associated virtualenv. (Django 1.11, Python 3)

How can I configure Builder, so that when I click Run it invokes manage.py runserver in the virtualenv? (Ideally I'd like to be able to run other manage.py functions too, like manage.py collectstatic.)

lofidevops
  • 15,528
  • 14
  • 79
  • 119

1 Answers1

2

This is not really possible as Gnome-Builder works tightly integrated with flatpak. As far as I know the "hostsystem buildsystem" only supports auto detected run targets and only one of those.

However if you create a flatpak json manifest you can set the command to be run in the command variable of the json manifest - though probably not everything you want. As this means the application runs in a flatpak sandbox.

Setup

To do that you can create a new python gnome application with gnome-builder called djangoproj. This will generate a Project that uses the meson buildsystem and a org.gnome.djangoproj.json. The next thing would be to remove the gnome application - or you just ignore it and add your Django dependencies.

Add the required modules before the native modules. For just Django this is:

[…]
"modules" : [
    {
        "name": "python3-Django",
        "buildsystem": "simple",
        "build-commands": [
            "pip3 install --no-index --find-links=\"file://${PWD}\" --prefix=${FLATPAK_DEST} Django"
        ],
        "sources": [
            {
                "type": "file",
                "url": "https://pypi.python.org/packages/1b/50/4cdc62fc0753595fc16c8f722a89740f487c6e5670c644eb8983946777be/pytz-2018.3.tar.gz",
                "sha256": "410bcd1d6409026fbaa65d9ed33bf6dd8b1e94a499e32168acfc7b332e4095c0"
            },
            {
                "type": "file",
                "url": "https://pypi.python.org/packages/54/59/4987ae4a4a8be8507af1b213e75a449c05939ab1e0f62b5e90ccea2b51c3/Django-2.0.3.tar.gz",
                "sha256": "769f212ffd5762f72c764fa648fca3b7f7dd4ec27407198b68e7c4abf4609fd0"
            }
        ]
    },
    {
        "name" : "djangoproj",
        "buildsystem" : "meson",
[…]

If you have additional dependencies there is a handy tool to generate the necessary json lines: https://github.com/flatpak/flatpak-builder-tools/tree/master/pip

Now you can add the Django project files using the host system.

django-admin startproject sample

Meson needs to know about the new files so just add subdir('sample') to the root meson directory and create new meson files in the subdirectories. The meson.build in the sample directory looks like this for me. for the sample/sample directory you'd need to adjust the moduledir and the djangoproj_sources

pkgdatadir = join_paths(get_option('prefix'), get_option('datadir'), meson.project_name())
moduledir = join_paths(pkgdatadir, 'djangoproj')
python3 = import('python3')

conf = configuration_data()
conf.set('PYTHON', python3.find_python().path())
conf.set('VERSION', meson.project_version())
conf.set('localedir', join_paths(get_option('prefix'), get_option('localedir')))
conf.set('pkgdatadir', pkgdatadir)

subdir('sample')

djangoproj_sources = [
  'manage.py',
]

install_data(djangoproj_sources, install_dir: moduledir)

Now you can set the command in the org.gnome.Djangoproj.json to bash and after pressing launch in the window where otherwise the logs of the program appear there is an interactive shell. There you can explore your newly created flatpak with Django included in the /app/ directory. If you want to run the Django app you'd do:

$ python3 /app/share/djangoproj2/djangoproj2/manage.py runserver

you can also write this command in the command variable of the json file to launch it directly when pressing the "play"-button.

All the other commands do work too- however keep in mind that the environment is in a flatpak and recreated on every rebuild... So nothing that needs to persist can be saved in the flatpak directory.

enaut
  • 431
  • 4
  • 15