如何在 Gnome 中分发 Python 包的“.desktop”文件和图标(使用 distutils 或 setuptools)?
目前,我正在使用自动工具来构建/安装和打包我的一个项目,但我真的很想转向一些感觉更“Pythonic”的东西。
我的项目由两个脚本、一个模块、两个 Glade GUI 描述和两个 .desktop 文件组成。 它目前是一个纯 python 项目,尽管这可能很快就会改变。
查看 setuptools,我可以轻松了解如何处理除 .desktop 文件之外的所有内容; 它们必须位于特定目录中,以便 Gnome 可以找到它们。
一开始使用 distuils/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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我设法让它发挥作用,但对我来说,它更像是一种解决方法。
不知道处理这个问题的首选方法是什么...
我使用了 (完整版本位于此处):
以下
setup.py
文件 脚本槽entry_points
有效。 但是data_files
放在 Egg 文件中,而不是放在指定的文件夹中,因此桌面 shell 无法访问它们。为了解决这个问题,我使用了以下
setup.cfg
文件:这有效。 这两个数据文件都创建在正确的位置,并且 Gnome 可以识别
.desktop
文件。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):The starter script trough
entry_points
works. But thedata_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:This works. Both data files are created in the right place and the
.desktop
file is recognized by Gnome.总的来说,是的 - 在构建 Python 项目时,一切都比自动工具更好。
到目前为止,我在 setuptools 方面有很好的经验。 然而,将文件安装到固定位置并不是 setuptools 的强项 - 毕竟,它不是为 Python 应用程序构建安装程序,而是分发 Python 库。
对于不是应用程序数据文件(如图像、UI 文件等)但提供与操作系统集成的文件的安装,最好使用真正的打包格式(如 RPM 或 deb)。
也就是说,没有什么可以阻止您基于 setuptools 进行构建过程,并使用一个小 make 文件将所有内容安装到正确的位置。
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.
您可以尝试使用 python-distutils-extra。
DistUtilsExtra.auto
模块自动 支持 .desktop 文件,以及 Glade/GtkBuilder .ui 文件、Python 模块和脚本、杂项数据文件等。它应该与 Distutils 和 Setuptools 一起使用。
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.
我创建了 https://pypi.python.org/pypi/install-freedesktop 。 它自动为 gui_scripts 入口点创建 .desktop 文件,可以通过安装参数进行自定义,并支持
--user
以及系统范围的安装。 与 DistUtilsExtra 相比,它的范围更窄,恕我直言,更Pythonic(显式优于隐式)。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 toDistUtilsExtra
, it's more narrow in scope and IMHO more pythonic (explicit is better than implicit).