setup.py 中使用 SetupTools/Distribute 生成的非生成脚本

发布于 2024-10-08 05:58:54 字数 1480 浏览 0 评论 0原文

当我为正在构建的 Python 包运行 setup.py install 时,我试图获取非生成的脚本。

我已阅读 distutils 文档,但找不到有关如何完成此操作的明确示例。

Mercurial 在某种程度上通过导入 install_scripts 来实现这一点:

from distutils.command.install_scripts import install_scripts

然后继续替换其 hg 脚本中的一些内容。这个 hg 可执行文件最终会覆盖使用类似以下内容的默认行为:

#!/Users/alfredo/python/foo/bin/python  
# EASY-INSTALL-SCRIPT: 'foo==0.0.1','foo'
__requires__ = 'foo==0.0.1'
import pkg_resources
pkg_resources.run_script('foo==0.0.1', 'foo')

我试图最终使用 pkg_resources 导入我的 foo包,而是 最终得到我正在使用的脚本。我知道为什么这是自动生成的并且仍然想要 走另一条路。

这是我正在使用的基本 setup.py 的副本:

import distribute_setup
distribute_setup.use_setuptools()
from setuptools import setup

tests_require = ['pytest']

setup(
name = "foo",
version = "0.0.1",
packages = ['_foo'],

scripts = ['foo'],
zip_safe = False,
package_data = {'': ['distribute_setup.py']},
author = "Alfredo Deza",
author_email = "alfredodeza [at] gmail [dot] com",
description = "",
long_description = """\
Foo
""",
classifiers=[
    'Development Status :: 4 - Beta',
    'Intended Audience :: Developers',
    'License :: OSI Approved :: MIT License',
    'Topic :: Software Development :: Build Tools',
    'Programming Language :: Python :: 2.5',
    'Programming Language :: Python :: 2.6',
    'Programming Language :: Python :: 2.7',
  ],

license = "MIT",
keywords = "",
url = "",   

)

I'm trying to get a non-generated script when I run setup.py install for a Python Package that I am building.

I have read the distutils documentation but couldn't find clear examples on how to accomplish this.

Mercurial does this in some part by importing the install_scripts :

from distutils.command.install_scripts import install_scripts

And then goes on to replace some things within their hg script. This hg executable ends up being used overriding the default behavior of using something like this:

#!/Users/alfredo/python/foo/bin/python  
# EASY-INSTALL-SCRIPT: 'foo==0.0.1','foo'
__requires__ = 'foo==0.0.1'
import pkg_resources
pkg_resources.run_script('foo==0.0.1', 'foo')

I am trying not to end up using pkg_resources importing my foo package, but rather
end up with a script I am using. I'm aware why this is auto-generated and still want to
go the other route.

This is a copy of the base setup.py that I am using:

import distribute_setup
distribute_setup.use_setuptools()
from setuptools import setup

tests_require = ['pytest']

setup(
name = "foo",
version = "0.0.1",
packages = ['_foo'],

scripts = ['foo'],
zip_safe = False,
package_data = {'': ['distribute_setup.py']},
author = "Alfredo Deza",
author_email = "alfredodeza [at] gmail [dot] com",
description = "",
long_description = """\
Foo
""",
classifiers=[
    'Development Status :: 4 - Beta',
    'Intended Audience :: Developers',
    'License :: OSI Approved :: MIT License',
    'Topic :: Software Development :: Build Tools',
    'Programming Language :: Python :: 2.5',
    'Programming Language :: Python :: 2.6',
    'Programming Language :: Python :: 2.7',
  ],

license = "MIT",
keywords = "",
url = "",   

)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

童话里做英雄 2024-10-15 05:58:54

经过几天的挖掘...结果发现 Mercurial 并没有做任何特别的事情。

尽管他们的 setup.py 做了很多事情,但它实际上并没有做任何事情来干扰正确安装脚本而无需 pkg_resources 链接到它。

那有什么区别呢?

不同之处在于我使用的是 Distribute,它的工作方式是用自己的(而不是 setuptools)覆盖 setup 模块,因此它有自己不同的安装行为。

就我而言,安装脚本的不同方式意味着脚本foo将被复制到egg位置并通过foo链接导入 pkg_resources 并链接到该版本的脚本。

不是我想要的,我找不到任何关于它的分发文档。然而,很明显他们这样做是为了提供一种稍后卸载的方式。

所以要小心!如果你确实想走我的路,那么如果你想卸载东西,你就会遇到问题。

在 Distribute 无法为我提供自定义脚本中复制内容的方法之前,我将不得不切换回常规 setuptools

After days of digging around... it turns out that Mercurial is not doing anything special.

Even though their setup.py does a lot of things it actually does not do anything to interfere with installing a script correctly without pkg_resources linking to it.

What is the difference then?

The difference is that I am using Distribute, and the way it works it overrides the setup module with its own (instead of setuptools) and thus it has its own different behavior for installation.

In my case, that different way of installing scripts, means that a script foo will get copied over to the egg location and linked through a foo script that imports pkg_resources and links to that version.

This is not what I want and I couldn't find any Distribute documentation on it. However, it is clear they do so to provide a way of uninstallation later on.

So beware! If you do want to go my path, you will have issues if you want to uninstall stuff.

Until Distribute doesn't provide a way for me to customize what to copy in my scripts I will have to switch back to regular setuptools

扛刀软妹 2024-10-15 05:58:54

IIRC,使用 --single-version-externally-management 参数 安装时应该按照你喜欢的方式进行。

IIRC, using the --single-version-externally-managed argument when installing should do as you like.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文