简体   繁体   English

如何在 Gnome 中分发 Python 包的 `.desktop` 文件和图标(使用 distutils 或 setuptools)?

[英]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".目前我正在使用自动工具来构建/安装和打包我的项目,但我真的很想转向感觉更“pythonic”的东西。

My project consists of two scripts, one module, two glade GUI descriptions, and two .desktop files.我的项目由两个脚本、一个模块、两个 Glade GUI 描述和两个 .desktop 文件组成。 It's currently a pure python project, though that's likely to change soon-ish.它目前是一个纯 python 项目,尽管这可能很快就会改变。

Looking at setuptools I can easily see how to deal with everything except the .desktop files;查看 setuptools 我可以很容易地看到如何处理除 .desktop 文件之外的所有内容; they have to end up in a specific directory so that Gnome can find them.它们必须最终出现在特定目录中,以便 Gnome 可以找到它们。

Is using distuils/setuptools a good idea to begin with?开始使用 distuils/setuptools 是个好主意吗?

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 ):我使用了以下setup.py文件(完整版在这里):

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.入门脚本通过entry_points工作。 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.但是data_files放在egg 文件中而不是在指定的文件夹中,因此桌面外壳无法访问它们。

To work around this, I used the following setup.cfg file:为了解决这个问题,我使用了以下setup.cfg文件:

[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.两个数据文件都在正确的位置创建,并且 Gnome 可以识别.desktop文件。

You can try to use python-distutils-extra .您可以尝试使用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. DistUtilsExtra.auto模块自动支持.desktop 文件,以及 Glade/GtkBuilder .ui 文件、Python 模块和脚本、misc 数据文件等。

It should work both with Distutils and Setuptools.它应该适用于 Distutils 和 Setuptools。

I've created https://pypi.python.org/pypi/install-freedesktop .我已经创建了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.它为 gui_scripts 入口点自动创建 .desktop 文件,可以通过设置参数自定义,并支持--user以及系统范围的安装。 Compared to DistUtilsExtra , it's more narrow in scope and IMHO more pythonic (explicit is better than implicit).DistUtilsExtra相比,它的范围更窄,恕我直言更pythonic(显式优于隐式)。

In general, yes - everything is better than autotools when building Python projects.一般来说,是的 - 在构建 Python 项目时,一切都比 autotools 好。

I have good experiences with setuptools so far.到目前为止,我在 setuptools 方面有很好的经验。 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.但是,将文件安装到固定位置并不是 setuptools 的强项——毕竟,它不是为 Python 应用程序构建安装程序,而是分发 Python 库。

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).对于不是应用程序数据文件(如图像、UI 文件等)但提供与操作系统集成的文件的安装,最好使用真正的打包格式(如 RPM 或 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.也就是说,没有什么能阻止您拥有基于 setuptools 的构建过程和一个用于将所有内容安装到正确位置的小制作文件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何使用setuptools或distutils来分发脚本而不是Python包? - How do I use setuptools or distutils to distribute a script as opposed to a Python package? 分发、distutils、setuptools 和 distutils2 之间的区别? - Differences between distribute, distutils, setuptools and distutils2? 如何在 setuptools/distutils 中包含 package 数据? - How to include package data with setuptools/distutils? 通过setuptools或distutils安装Python软件包后,如何访问可编辑的配置文件? - How to access an editable configuration file once a Python package has been installed via setuptools or distutils? 如何将静态文件包含到 setuptools - python 包中 - How include static files to setuptools - python package Python setuptools / distutils使用Makefile定制构建`extra`包 - Python setuptools/distutils custom build for the `extra` package with Makefile 用于GO源中`extra`包的Python setuptools / distutils自定义构建 - Python setuptools/distutils custom build for the `extra` package from GO source 如何在不使用distutils的情况下创建一个debian软件包来分发python模块? - how can I create a debian package to distribute python modules without using distutils? 如何使用 setuptools 分发特定文件? - How to distribute specific files using setuptools? python distutils / setuptools:如何排除模块或保留svn:ignore标志 - python distutils / setuptools: how to exclude a module, or honor svn:ignore flag
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM