Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 project consists of two scripts, one module, two glade GUI descriptions, and two .desktop files. It's currently a pure python project, though that's likely to change soon-ish.

Looking at setuptools I can easily see how to deal with everything except the .desktop files; they have to end up in a specific directory so that Gnome can find them.

Is using distuils/setuptools a good idea to begin with?

like image 331
Magnus Avatar asked Feb 01 '09 21:02

Magnus


People also ask

How do you distribute a project in Python?

Use PyInstaller, py2exe, Nuitka, or another bundling solution. The most convenient way to deliver a Python application to a user is to provide them with an executable—either a single file or a directory with an easily identified executable somewhere in it.

How do I import setuptools in Python?

Follow the below steps to install the Setuptools package on Linux using the setup.py file: Step 1: Download the latest source package of Setuptools for Python3 from the website. Step 3: Go to the setuptools-60.5. 0 folder and enter the following command to install the package.

What is pip setuptools?

Docs | Issues | GitHub | PyPI. setuptools (which includes easy_install ) is a collection of enhancements to the Python distutils that allow you to more easily build and distribute Python distributions, especially ones that have dependencies on other packages.

Does Python come with setuptools?

Even in a vanilla version of Python 3.7. 6 (installed via pyenv ), the packages installed by default are both pip and setuptools .


3 Answers

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.

like image 71
Brutus Avatar answered Oct 15 '22 05:10

Brutus


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.

like image 1
Torsten Marek Avatar answered Oct 15 '22 04:10

Torsten Marek


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.

like image 1
Danilo Piazzalunga Avatar answered Oct 15 '22 04:10

Danilo Piazzalunga