5

I'm trying to use setuptools to package a python application that relies on gsettings for storing and retrieving user's preferences. However I have not used said tool before and I am unsure about what to do with the setup.py script in order to instruct it to install and compile the schema.

2
  1. Add your schema to setup.py

    setup(...,
          data_files=[('/usr/share/glib-2.0/schemas', ['filename.schema.xml'])]
         )
    
  2. Add a system call in setup.py to run:

    glib-compile-schemas /usr/share/glib-2.0/schemas
    

As ntc2 commented bellow that this will fail when custom installation path is use, example with --user.

  • One possible solution is to use relative path share/glib-2.0/schemas, That also would imply reconstructing input folder path for glib-compile-schemas command using sys.prefix variable.
| improve this answer | |
  • 1
    This will fail for --user installs. – ntc2 Dec 27 '18 at 0:35
  • @ntc2 one possible solution is to use relative path share/glib-2.0/schemas, That also would imply reconstructing input folder path for glib-compile-schemas command using sys.prefix variable. – user.dz Jun 7 at 22:00
1

You can run glib-copmile-schemas in a custom install_data subclass in setup.py. For example, this is how we do it in fluxgui's setup.py:

from distutils.core import setup
from distutils.log import info
import distutils.command.install_data, os.path

# On Ubuntu 18.04 both '/usr/local/share/glib-2.0/schemas' (global
# install) and '~/.local/share/glib-2.0/schemas' (local '--user'
# install) are on the default search path for glib schemas. The global
# search paths are in '$XDG_DATA_DIRS'.
gschema_dir_suffix = 'share/glib-2.0/schemas'

data_files = [<other data files>,
    (gschema_dir_suffix, ['apps.fluxgui.gschema.xml'])]

class install_data(distutils.command.install_data.install_data):
    def run(self):
        # Python 3 'super' call.
        super().run()

        # Compile '*.gschema.xml' to update or create 'gschemas.compiled'.
        info("compiling gsettings schemas")
        # Use 'self.install_dir' to build the path, so that it works
        # for both global and local '--user' installs.
        gschema_dir = os.path.join(self.install_dir, gschema_dir_suffix)
        self.spawn(["glib-compile-schemas", gschema_dir])

setup(<other setup args>,
    cmdclass = {'install_data': install_data})
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.