我正在尝试使用
setuptools
打包一个依赖于gsettings来存储和检索用户偏好的Python应用程序。然而,我以前没有使用过该工具,不确定如何处理setup.py
脚本,以指示它安装并编译模式。将您的模式添加到 setup.py
中:
setup(...,
data_files=[('/usr/share/glib-2.0/schemas', ['filename.schema.xml'])]
)
在 setup.py
中添加一个系统调用以运行:
glib-compile-schemas /usr/share/glib-2.0/schemas
--user
,这将失败。
share/glib-2.0/schemas
,这也意味着使用sys.prefix
变量重建glib-compile-schemas
命令的输入文件夹路径。setup.py
中的自定义install_data
子类中运行glib-compile-schemas
。例如,这是我们在{{link1:fluxgui的setup.py
}}中的做法:from distutils.core import setup
from distutils.log import info
import distutils.command.install_data, os.path
# On Ubuntu 18.04 both '/usr/local/share/glib-2.0/schemas' (global
# install) and '~/.local/share/glib-2.0/schemas' (local '--user'
# install) are on the default search path for glib schemas. The global
# search paths are in '$XDG_DATA_DIRS'.
gschema_dir_suffix = 'share/glib-2.0/schemas'
data_files = [<other data files>,
(gschema_dir_suffix, ['apps.fluxgui.gschema.xml'])]
class install_data(distutils.command.install_data.install_data):
def run(self):
# Python 3 'super' call.
super().run()
# Compile '*.gschema.xml' to update or create 'gschemas.compiled'.
info("compiling gsettings schemas")
# Use 'self.install_dir' to build the path, so that it works
# for both global and local '--user' installs.
gschema_dir = os.path.join(self.install_dir, gschema_dir_suffix)
self.spawn(["glib-compile-schemas", gschema_dir])
setup(<other setup args>,
cmdclass = {'install_data': install_data})
--user
安装。 - ntc2share/glib-2.0/schemas
,这也意味着使用sys.prefix
变量来重建glib-compile-schemas
命令的输入文件夹路径。 - user.dz