使用 Distribution/setuptools 创建符号链接(或运行脚本)?
作为项目设置过程的一部分,我需要将其中一个包符号链接到指定目录,以便 init.d 脚本可以找到它。有什么方法可以将其作为后处理命令添加到 setup() 中吗?我什至愿意创建另一个文件来创建链接并将其传递给 setup() 作为“运行这些”的一些 kwarg 列表的一部分(如果存在这样的选项)。
setup(
...
packages = find_packages('src'),
package_dir = {'': 'src'},
install_requires = ...,
data_files = [('/etc/init.d', ['scripts/foo'])],
...
)
该 foo
脚本期望将 src/
中的包之一符号链接到其他地方的目录(例如,不仅仅是位于 PYTHONPATH
上)。有办法实现吗?
As part of my project's setup process, I need to symlink one of the packages to a specified directory so an init.d script can find it. Is there any way to add this as a post-processing command to setup()
? I would even settle for creating another file that creates the link and pass it to setup()
as part of some kwarg list of "run these" (if such an option exists).
setup(
...
packages = find_packages('src'),
package_dir = {'': 'src'},
install_requires = ...,
data_files = [('/etc/init.d', ['scripts/foo'])],
...
)
that foo
script expects one of the packages from src/
to be symlinked to directory elsewhere (e.g. not simply be on PYTHONPATH
). Is there a way to achieve that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我知道这篇文章已经有好几年了,但我想提供一个更新,说明可以在 setup.py 中进行后处理代码。长话短说,您必须覆盖 setuptools 的安装功能,但从那时起您可以添加任何您想要的代码,例如复制 MANIFEST.in 拒绝复制的符号链接。摘自 Peter Lamut 的解决方案。
I know this post is several years old but I wanted to provide an update that post-processing code is possible in setup.py. Long story short, you have to override the install function of setuptools but from then on you can add whatever code you want, such as copying symlinks that MANIFEST.in refuses to copy. Taken from Peter Lamut's solution.
目前,只有特定于平台的包管理工具(例如 RPM、deb、win32 安装程序)能够运行安装后步骤:distutils、setuptools 等不直接支持此操作。 (除非允许您构建 RPM、Windows 安装程序等)
因此,在没有特定于平台的安装程序的情况下执行此操作的最简单方法是创建您自己的安装后脚本,或者将安装后选项添加到您现有的脚本中,并告诉用户运行它。否则,您必须使用 bdist_rpm 或其他 bdist 命令之一来构建适用于适当平台的安装程序。
Currently, only platform-specific package management tools (e.g. RPM, deb, win32 installers) have the ability to run post-install steps: the distutils, setuptools, etc. do not support this directly. (Except to the extent of allowing you to build the RPM, windows installer, etc.)
So, the simplest way to do this without a platform-specific installer, is to create a postinstall script of your own, or add a postinstall option to an existing script of yours, and tell users to run it. Otherwise, you'll have to use bdist_rpm or one of the other bdist commands to build an installer for the appropriate platform(s).
扩展@pjeby的答案,您还可以扩展安装命令以添加您自己的自定义安装后步骤。然而,这仅在从源安装(即运行 setup.py)时有效,而其他安装程序(如 RPM 和 MSI)将默默地忽略您的更改。编辑:经过一番谷歌搜索后发现了这一点,似乎您不应该不尝试自己创建符号链接:http://docs.python.org/2/install/index.html#alternate-installation
Expanding on @pjeby's answer, you can also extend the install command to add your own custom postinstall steps. However that will only work when installing from source (i.e. running setup.py) and other installers like RPM and MSI will silently ignore your changes.EDIT: Found this after some googling, it seems you should not try to create the symlinks by yourself: http://docs.python.org/2/install/index.html#alternate-installation