How to distribute `.desktop` files and icons for a Python package in Gnome (with distutils or setuptools)?

前端 未结 4 1472
灰色年华
灰色年华 2020-12-16 02:33

Currently I\'m using the auto-tools to build/install and package a project of mine, but I would really like to move to something that feels more \"pythonic\".

My pro

相关标签:
4条回答
  • 2020-12-16 03:18

    You can try to use python-distutils-extra. The DistUtilsExtra.auto module automatically supports .desktop files, as well as Glade/GtkBuilder .ui files, Python modules and scripts, misc data files, etc.

    It should work both with Distutils and Setuptools.

    0 讨论(0)
  • 2020-12-16 03:26

    I managed to get this to work, but it kinda feels to me more like a workaround.

    Don't know what's the preferred way to handle this...

    I used the following setup.py file (full version is here):

    from setuptools import setup
    
    setup(
      # ...
      data_files=[
        ('share/icons/hicolor/scalable/apps', ['data/mypackage.svg']),
        ('share/applications', ['data/mypackage.desktop'])
      ],
      entry_points={
        'console_scripts': ['startit=mypackage.cli:run']
      }
    )
    

    The starter script trough entry_points works. But the data_files where put in an egg file and not in the folders specified, so they can't be accessed by the desktop shell.

    To work around this, I used the following setup.cfg file:

    [install]
    single-version-externally-managed=1
    record=install.txt
    

    This works. Both data files are created in the right place and the .desktop file is recognized by Gnome.

    0 讨论(0)
  • 2020-12-16 03:33

    In general, yes - everything is better than autotools when building Python projects.

    I have good experiences with setuptools so far. However, installing files into fixed locations is not a strength of setuptools - after all, it's not something to build installaters for Python apps, but distribute Python libraries.

    For the installation of files which are not application data files (like images, UI files etc) but provide integration into the operating system, you are better off with using a real packaging format (like RPM or deb).

    That said, nothing stops you from having the build process based on setuptools and a small make file for installing everything into its rightful place.

    0 讨论(0)
  • 2020-12-16 03:37

    I've created https://pypi.python.org/pypi/install-freedesktop. It creates .desktop files automatically for the gui_scripts entry points, which can be customized through a setup argument, and supports --user as well as system-wide installation. Compared to DistUtilsExtra, it's more narrow in scope and IMHO more pythonic (explicit is better than implicit).

    0 讨论(0)
提交回复
热议问题