如何将安装后脚本添加到easy

编程入门 行业动态 更新时间:2024-10-25 13:30:28
本文介绍了如何将安装后脚本添加到easy_install / setuptools / distutils?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我希望能够在我的setup.py中添加一个钩子,该钩子将在安装后运行(在easy_install或python setup.py安装时运行)。

I would like to be able to add a hook to my setup.py that will be run post-install (either when easy_install'ing or when doing python setup.py install).

在我的项目 PySmell 中,我有一些针对Vim和Emacs的支持文件。当用户以通常的方式安装PySmell时,这些文件将复制到实际的鸡蛋中,并且用户必须将它们捞出并将它们放置在他的.vim或.emacs目录中。我想要的是询问用户,安装后,他想在哪里复制这些文件,甚至只是一条消息,显示文件的位置以及他应该如何处理这些文件。

In my project, PySmell, I have some support files for Vim and Emacs. When a user installs PySmell the usual way, these files get copied in the actual egg, and the user has to fish them out and place them in his .vim or .emacs directories. What I want is either asking the user, post-installation, where would he like these files copied, or even just a message printing the location of the files and what should he do with them.

执行此操作的最佳方法是什么?

What is the best way to do this?

谢谢

我的setup.py看起来像这样:

My setup.py looks like so:

#!/usr/bin/env python # -*- coding: UTF-8 -*- from setuptools import setup version = __import__('pysmell.pysmell').pysmell.__version__ setup( name='pysmell', version = version, description = 'An autocompletion library for Python', author = 'Orestis Markou', author_email = 'orestis@orestis.gr', packages = ['pysmell'], entry_points = { 'console_scripts': [ 'pysmell = pysmell.pysmell:main' ] }, data_files = [ ('vim', ['pysmell.vim']), ('emacs', ['pysmell.el']), ], include_package_data = True, keywords = 'vim autocomplete', url = 'code.google/p/pysmell', long_description = """\ PySmell is a python IDE completion helper. It tries to statically analyze Python source code, without executing it, and generates information about a project's structure that IDE tools can use. The first target is Vim, because that's what I'm using and because its completion mechanism is very straightforward, but it's not limited to it. """, classifiers = [ 'Development Status :: 5 - Production/Stable', 'Environment :: Console', 'Intended Audience :: Developers', 'License :: OSI Approved :: BSD License', 'Operating System :: OS Independent', 'Programming Language :: Python', 'Topic :: Software Development', 'Topic :: Utilities', 'Topic :: Text Editors', ] )

编辑:

下面是一个存根,显示了 python setup.py install :

Here's a stub which demonstrates the python setup.py install:

from setuptoolsmand.install import install as _install class install(_install): def run(self): _install.run(self) print post_install_message setup( cmdclass={'install': install}, ...

使用easy_install路由还没有运气。

No luck with the easy_install route yet.

推荐答案

这取决于用户如何安装软件包。如果用户实际运行 setup.py install,则非常简单:只需在安装命令中添加另一个子命令(例如install_vim),其run()方法将在所需位置复制所需文件。您可以将子命令添加到install.sub_commands,然后将该命令传递到setup()。

It depends on how the user installs your package. If the user actually runs "setup.py install", it's fairly easy: Just add another subcommand to the install command (say, install_vim), whose run() method will copy the files you want in the places where you want them. You can add your subcommand to install.sub_commands, and pass the command into setup().

如果您想要二进制形式的安装后脚本,则取决于您正在创建的二进制文件的类型。例如,bdist_rpm,bdist_wininst和bdist_msi支持安装后脚本,因为基础打包格式支持安装后脚本。

If you want a post-install script in a binary, it depends on the type of binary you are creating. For example, bdist_rpm, bdist_wininst, and bdist_msi have support for post-install scripts, because the underlying packing formats support post-install scripts.

bdist_egg不支持发布安装机制的设计方式:

bdist_egg doesn't support a post-install mechanism by design:

http:// bugs.python/setuptools/issue41

更多推荐

如何将安装后脚本添加到easy

本文发布于:2023-07-05 01:17:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1031274.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何将   脚本   easy

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!