如何在Gnome中使用distutils或setuptools分发Python包的.desktop文件和图标? [英] How to distribute `.desktop` files and icons for a Python package in Gnome (with distutils or setuptools)?

查看:92
本文介绍了如何在Gnome中使用distutils或setuptools分发Python包的.desktop文件和图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我正在使用自动工具来构建/安装和打包我的项目,但是我真的很想迁移到感觉更"pythonic"的地方.

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".

我的项目包含两个脚本,一个模块,两个林间空地GUI描述和两个.desktop文件.尽管这很可能会很快改变,但目前它只是一个纯python项目.

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.

查看setuptools,我可以轻松地了解如何处理.desktop文件以外的所有内容;它们必须以特定目录结尾,以便Gnome可以找到它们.

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.

使用distuils/setuptools是一个好主意吗?

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

推荐答案

我设法使它起作用,但在我看来,这更像是解决方法.

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...

我使用了以下setup.py文件(完整版本为此处):

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']
  }
)

启动脚本槽entry_points起作用.但是data_files是放置在egg文件中的,而不是放置在指定的文件夹中的,因此台式机壳无法访问它们.

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.

要解决此问题,我使用了以下setup.cfg文件:

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

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

这有效.这两个数据文件都在正确的位置创建,并且.desktop文件被Gnome识别.

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

这篇关于如何在Gnome中使用distutils或setuptools分发Python包的.desktop文件和图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆